public ActionResult UpdateCart(ListProductCartModel updateList) { if (updateList != null) { Session["Cart"] = updateList; } return(PartialView("_Cart")); }
// // GET: /Cart/ public ActionResult Index() { ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; return(View()); }
public ActionResult ConfirmCheckOut() { ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; Session["Cart"] = null; return(View(listCart)); }
public ActionResult DeleteCartProduct(int Prod) { ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; var st = listCart.listProduct.Find(c => c.ProductId == Prod); listCart.listProduct.Remove(st); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; return(RedirectToAction("Index", "Cart")); }
public ActionResult CheckGiftCode(string GiftCode) { if (GiftCode != "") { var code = _StaffService.GetStaffs().Where(p => p.Yahoo.ToLower().Equals(GiftCode.ToLower())).FirstOrDefault(); ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; if (code != null) { listCart.GiftCode = GiftCode; listCart.GiftCodePercent = int.Parse(code.Phone); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; } } return(RedirectToAction("Index", "Cart")); }
public static ListProductCartModel CalculatorCart(ListProductCartModel model) { if (model != null) { double totalPayment = 0; foreach (var item in model.listProduct) { totalPayment += item.Price * item.Quantity; } if (model.GiftCodePercent > 0) { var remainPercent = (100 - model.GiftCodePercent); model.TotalAfterDiscount = (totalPayment * remainPercent) / 100; } model.TotalPayment = totalPayment; } return(model); }
public ActionResult Addtocart(int ProdId, int Quantity) { ListProductCartModel listCart = new ListProductCartModel(); if (Session["Cart"] != null) { listCart = (ListProductCartModel)Session["Cart"]; //kiểm tra product đã có trong cart chưa, nếu có thì cập nhật số lượng if (listCart.listProduct.Where(p => p.ProductId == ProdId).FirstOrDefault() != null) { foreach (var item in listCart.listProduct) { if (item.ProductId == ProdId) { item.Quantity = Quantity; } } var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; } else { //nếu không có trong cart, thì thêm product vào cart CartModel cart = new CartModel(); var product = _productService.GetProductById(ProdId); cart.ProdName = product.Name; cart.ProdNameEngh = product.NameEng; cart.DescriptionEng = product.DescEng; cart.Description = product.Description; cart.slug = product.Slug; cart.ProductImage = product.ProductPictureMappings.FirstOrDefault().Picture.Url; cart.ProductId = product.Id; if (product.IsHomePage) { cart.Price = product.Price; } else { cart.Price = product.OldPrice; } cart.Quantity = Quantity; listCart.listProduct.Add(cart); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; } } else { //tạo mới cart đưa vào session CartModel cart = new CartModel(); var product = _productService.GetProductById(ProdId); cart.ProdName = product.Name; cart.ProdNameEngh = product.NameEng; cart.DescriptionEng = product.DescEng; cart.Description = product.Description; cart.slug = product.Slug; cart.ProductImage = product.ProductPictureMappings.FirstOrDefault().Picture.Url; cart.ProductId = product.Id; if (product.IsHomePage) { cart.Price = product.Price; } else { cart.Price = product.OldPrice; } cart.Quantity = Quantity; listCart.listProduct.Add(cart); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; } return(null); }
public ActionResult Checkout(string CustomerName, string CustomePhone, string CustomerAddress, string CustomerNote) { Order order = new Order(); order.CustomerName = CustomerName; order.CustomerPhone = CustomePhone; order.CustomerAddress = CustomerAddress; order.Note = CustomerNote; ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; #region input data vào session listCart.CustomePhone = CustomePhone; listCart.CustomerAddress = CustomerAddress; listCart.CustomerName = CustomerName; listCart.CustomerNote = CustomerNote; #endregion if (listCart != null) { order.OrderTotal = listCart.TotalPayment; if (listCart.GiftCode != "") { order.TotalPayment = listCart.TotalAfterDiscount; } else { order.TotalPayment = listCart.TotalPayment; } order.Status = 1; //order.Discount = listCart.GiftCodePercent; order.Temp_1 = listCart.GiftCode; order.Deleted = false; order.DateCreated = DateTime.Now; //add Order to DB _OrderService.CreateOrder(order); #region set orderItem foreach (var item in listCart.listProduct) { OrderItem Oitem = new OrderItem(); Oitem.Discount = 0; Oitem.OrderId = order.Id; Oitem.Price = item.Price; Oitem.ProductId = item.ProductId; Oitem.Quantity = item.Quantity; //Oitem.Temp_1 = ""; //Oitem.Temp_2 = ""; //Oitem.Temp_3 = ""; //add to order Item _OrderItemService.CreateOrderItem(Oitem); } #endregion Session["Cart"] = listCart; return(RedirectToAction("ConfirmCheckOut", "Cart")); } return(RedirectToAction("Index", "Home")); }