I am developing an application with Angular interface and ASP.NET back side using oData and Oracle. I am at the point where I am trying to correct the entries on the rear panel. I use the generic template code on the back of my controller, and the patch method is as follows:
<AcceptVerbs("PATCH", "MERGE")> Async Function Patch(<FromODataUri> ByVal key As Decimal, ByVal patchValue As Delta(Of FTP_ORDERS)) As Task(Of IHttpActionResult) Validate(patchValue.GetEntity()) If Not ModelState.IsValid Then Return BadRequest(ModelState) End If Dim fTP_ORDERS As FTP_ORDERS = Await db.FTP_ORDERS.FindAsync(key) If IsNothing(fTP_ORDERS) Then Return NotFound() End If patchValue.Patch(fTP_ORDERS) Try Await db.SaveChangesAsync() Catch ex As DbUpdateConcurrencyException If Not (FTP_ORDERSExists(key)) Then Return NotFound() Else Throw End If End Try Return Updated(fTP_ORDERS) End Function
On the Angular side, I use a service based on $ resource to send the update. The code calling the resource is as follows:
(new FTPOrderService({ "key": vm.ID, "data": vm }, vm)) .$patch() .then(function (data) { alert("Order Saved!"); }, function (error) { debugger; } );
The service is defined using:
.factory('FTPOrderService', function ($resource) { var odataUrl = '../odata/FTP_ORDERS'; var results = $resource('', {}, { 'patch': { method: 'PATCH', params: { key: '@key', }, url: odataUrl + '(:key)' } }); return results; })
I also tried:
(new FTPOrderService({ "key": vm.ID, }, vm)) .$patch(vm) .then(function (data) { alert("Order Saved!"); }, function (error) { debugger; } );
and get the same results.
I believe that I configured Angular to send data correctly:
.config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.headers.patch = { 'Content-Type': 'application/json;charset=utf-8' }; }])
The debugger shows that I am calling the URL with the corresponding key added to it in parens, and the request payload is as follows:
{key: "1239990990", data: {loading: false, selectedRow: {}, lineItems: [,…], orderId: "1239990990",…}} data: {loading: false, selectedRow: {}, lineItems: [,…], orderId: "1239990990",…} key: "1239990990"
Any idea what I'm missing? There are many examples that use direct calls to $ http.post and a few for .patch, but nothing is used using $ resource.