// POST api/CheckoutList public HttpResponseMessage PostCheckoutList(CheckoutListDto checkoutlist) { if (ModelState.IsValid) { foreach (CheckoutItemDto item in checkoutlist.CheckoutItems) { var product = tdDb.ShoppingItems.Find(item.ProductId); item.SubTotal = product.Price * item.Quantity; checkoutlist.TotalPrice += item.SubTotal; item.Price = product.Price; item.ProductName = product.Title; } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, checkoutlist); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = checkoutlist.CheckoutListId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/CheckoutList/5 public HttpResponseMessage PutCheckoutList(int id, CheckoutListDto checkoutlistDto) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != checkoutlistDto.CheckoutListId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } coDb.Entry(checkoutlistDto).State = EntityState.Modified; try { coDb.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }