public IActionResult PutShipper(int key, [FromBody] Models.Northwind.Shipper newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.ShipperID != key)) { return(BadRequest()); } this.OnShipperUpdated(newItem); this.context.Shippers.Update(newItem); this.context.SaveChanges(); return(new NoContentResult()); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Northwind.Shipper item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnShipperCreated(item); this.context.Shippers.Add(item); this.context.SaveChanges(); return(Created($"odata/Northwind/Shippers/{item.ShipperID}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult PutShipper(int key, [FromBody] Models.Northwind.Shipper newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.ShipperID != key)) { return(BadRequest()); } this.OnShipperUpdated(newItem); this.context.Shippers.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.Shippers.Where(i => i.ShipperID == key); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnShipperUpdated(Models.Northwind.Shipper item);
partial void OnShipperDeleted(Models.Northwind.Shipper item);