public IActionResult PutOrderDetail(int key, [FromBody] Models.Sample.OrderDetail newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.Id != key)) { return(BadRequest()); } this.OnOrderDetailUpdated(newItem); this.context.OrderDetails.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.OrderDetails.Where(i => i.Id == key); Request.QueryString = Request.QueryString.Add("$expand", "Order,Product"); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Sample.OrderDetail item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnOrderDetailCreated(item); this.context.OrderDetails.Add(item); this.context.SaveChanges(); var key = item.Id; var itemToReturn = this.context.OrderDetails .Where(i => i.Id == key) .Include(i => i.Order) .Include(i => i.Product) .FirstOrDefault(); return(new JsonResult(itemToReturn, new Newtonsoft.Json.JsonSerializerSettings { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc }) { StatusCode = 201 }); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnOrderDetailUpdated(Models.Sample.OrderDetail item);
partial void OnOrderDetailDeleted(Models.Sample.OrderDetail item);