public IActionResult UpdateProductOrder(int id, ProductOrder lineItem) { var updatedLineItem = _productOrderRepo.Update(id, lineItem); if (_productOrderRepo.GetSingleItemInOrderById(id) == null) { return(NotFound("We could not find a line item with this ID. Please try again.")); } return(Ok(updatedLineItem)); }
public ActionResult COnfirmOrder() { var UserName = User.Identity.GetUserName(); ViewBag.Total = cart_Service.GetCartTotal(cart_Service.GetCartID()); ViewBag.TotalQTY = cart_Service.GetCartItems().FindAll(x => x.cartId == cart_Service.GetCartID()).Sum(q => q.quantity); var confirm = _productOrdersRepository.GetAll(); //db.productrders.ToList(); var cart = _productOrdersRepository.GetAll(); //db.Cart_Items.ToList(); CustomerOrder mealOrder = new CustomerOrder(); mealOrder.OrderNumber = mealOrder.GenVoucher(); mealOrder.Total = ViewBag.Total; mealOrder.UserOrder = UserName; mealOrder.Status = "Paid"; mealOrder.OrderDate = DateTime.Now.Date.ToLongDateString(); _CustomerOrderRepository.Insert(mealOrder); //db.MealOrders.Add(mealOrder); //db.SaveChanges(); ProductOrder foodOrder = new ProductOrder(); foreach (var item in confirm) { foreach (var i in cart) { if (UserName == item.UserEmail && item.cart_id == i.cart_id) { var statusUpdate = _productOrdersRepository.GetById(item.cart_item_id); //db.productrders.Find(item.cart_item_id); statusUpdate.OrderStatus = "Checked Out"; statusUpdate.OrderId = mealOrder.OrderId; _productOrdersRepository.Update(statusUpdate); //db.Entry(statusUpdate).State = EntityState.Modified; //db.SaveChanges(); cart_Service.EmptyCart(); } } } return(RedirectToAction("OnceOff", new { tot = mealOrder.Total })); }