Implementing CRUD Operations
The next step is to implement CRUD operations. For queries, methods in the OData service must match HTTP verbs. Adding a new object through an OData service is done via the POST
verb. So you need to replace the PostCustomer
method with the following:
<ResponseType(GetType(Customer))>Async Function Post(ByVal customer As Customer) _ As Task(Of IHttpActionResult) If Not ModelState.IsValid Then Return BadRequest(ModelState) End If db.Customers.Add(customer) Try Await db.SaveChangesAsync() Catch ex As DbUpdateException If (CustomerExists(customer.CustomerID)) Then Return Conflict() Else Throw End If End Try Return ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.