public IActionResult PutCustomer(string key, [FromBody] Models.Northwind.Customer newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.CustomerID != key)) { return(BadRequest()); } this.OnCustomerUpdated(newItem); this.context.Customers.Update(newItem); this.context.SaveChanges(); return(new NoContentResult()); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Northwind.Customer item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnCustomerCreated(item); this.context.Customers.Add(item); this.context.SaveChanges(); return(Created($"odata/Northwind/Customers/{item.CustomerID}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnCustomerUpdated(Models.Northwind.Customer item);
partial void OnCustomerDeleted(Models.Northwind.Customer item);