public JsonResult UpdateQuantity(string cartModel, long orderId) { var jsonCart = new JavaScriptSerializer().Deserialize <List <CartItem> >(cartModel); var listCartItem = (List <CartItem>) this.ListCartItemByOrderId(orderId); foreach (var item in listCartItem) { var jsonItem = jsonCart.SingleOrDefault(x => x.Product.ID == item.Product.ID); if (jsonItem != null) { item.Quantity = jsonItem.Quantity; } } var detailDao = new OrderDetailDao(); OrderDetail orderDetail = new OrderDetail(); foreach (var item in listCartItem) { orderDetail.OrderID = orderId; orderDetail.ProductID = item.Product.ID; orderDetail.Quantity = item.Quantity; orderDetail.Price = item.Product.Price; detailDao.Update(orderDetail); } return(Json(new { status = true })); }
public void Put(int id, [FromBody] OrderDetail orderDetail) { if (orderDetailDao.FindById(id) != null && ModelState.IsValid) { orderDetailDao.Update(orderDetail); } }
public ActionResult Edit(OrderDetail orderDetail) { if (ModelState.IsValid) { var dao = new OrderDetailDao(); var result = dao.Update(orderDetail); if (result) { return(RedirectToAction("Index", "OrderDetail")); } else { ModelState.AddModelError("", "Modify successfully"); } } return(View("Index")); }