public IActionResult Order(Customer model) { List <BillDetail> cart = SessionHelper.GetObjectFromJson <List <BillDetail> >(HttpContext.Session, "cart"); ViewBag.SuccessOrder = false; ViewBag.CartCheckOut = cart; if (cart != null) { ViewBag.total = cart.Sum(item => item.Product.UnitPrice * item.Quantity); _Customer.Add(model); //new bill Bill modelBill = new Bill(); modelBill.CustomerId = model.Id; modelBill.DateOrder = DateTime.Now; modelBill.Total = ViewBag.total; _Bill.Add(modelBill); //new Bill details for (int i = 0; i < cart.Count(); i++) { BillDetail newBillDetails = new BillDetail(); newBillDetails.Quantity = cart[i].Quantity; newBillDetails.UnitPrice = cart[i].Product.UnitPrice; newBillDetails.ProductId = cart[i].Product.Id; newBillDetails.BillId = modelBill.Id; _BillDetail.Add(newBillDetails); } ViewBag.SuccessOrder = true; } else { return(NotFound()); } return(RedirectToAction("Index")); }
public IActionResult CreateProduct(BillDetail model) { if (ModelState.IsValid) { _billDetail.Add(model); return(RedirectToAction("Index")); } return(View(model)); }