//xoa 1 san pham trong gio hang public void ActionDelete(int ProductID) { Global.Cart _Cart = new Global.Cart(); _Cart.Remove(new Global.CartItem() { ProductID = ProductID }); _Cart.Save(); ViewPage.Response.Redirect("~/vn/gio-hang.aspx"); }
//cap nhap gio hang public void ActionUpdate(MViewCartModel model) { Global.Cart _Cart = new Global.Cart(); for (int i = 0; i < _Cart.Items.Count; i++) { _Cart.Items[i].Quantity = (model.ArrCount[i] <= 0) ? 1 : model.ArrCount[i]; } _Cart.Save(); ViewPage.Response.Redirect("~/vn/gio-hang.aspx"); }
//them vao gio hang public void ActionAdd(int ProductID, int Quantity) { if (Quantity < 1 || Quantity > 9999) { Quantity = 1; } Global.Cart _Cart = new Global.Cart(); Global.CartItem item = _Cart.Find(new Global.CartItem() { ProductID = ProductID }); var objProduct = ModProduct_InfoService.Instance.GetByID(ProductID); if (item == null && objProduct != null) { _Cart.Add(new Global.CartItem() { ProductID = ProductID, Quantity = Quantity, MenuID = objProduct.MenuID, LangID = objProduct.LangID, Code = objProduct.Code, Name = objProduct.Name, File = objProduct.File, ShowPrice = objProduct.ShowPrice, Price = objProduct.Price, PriceSale = objProduct.PriceSale, VAT = objProduct.VAT, ShowVAT = objProduct.ShowVAT, ProductsConnection = objProduct.ProductsConnection, ProductsAttach = objProduct.ProductsAttach }); } else { item.Quantity += Quantity; } _Cart.Save(); ViewPage.Response.Redirect("~/gio-hang.aspx"); }
public void ActionIndex() { Global.Cart _Cart = new Global.Cart(); string sListID = string.Empty; for (int i = 0; _Cart != null && i < _Cart.Count; i++) { sListID += (sListID == "" ? "" : ",") + _Cart.Items[i].ProductID; } if (sListID != string.Empty) { ViewBag.Data = ModProduct_InfoService.Instance.CreateQuery() .Where(o => o.Activity == true) .WhereIn(o => o.ID, sListID) .ToList(); } ViewBag.Cart = _Cart; ViewBag.Title = ViewPage.CurrentPage.Name; }
public void ActionCheckOut(ModProduct_CheckoutModel model) { List <ModProduct_Order_DetailsEntity> lstOrder_Details = new List <ModProduct_Order_DetailsEntity>(); ModProduct_Order_DetailsEntity objOrder_Detail = null; int iQuantityProduct = 0; int iQuantityTotal = 0; double dTotalFriceFirst = 0; #region Thêm thông tin đơn hàng ModProduct_OrderEntity objModProduct_Order = new ModProduct_OrderEntity(); objModProduct_Order.TransportId = model.TransportId; objModProduct_Order.PaymentId = model.PaymentId; objModProduct_Order.CustomersCode = null; objModProduct_Order.IP = VSW.Core.Web.HttpRequest.IP; objModProduct_Order.Code = "[Order]" + VSW.Lib.Global.Utils.GetRandString(); objModProduct_Order.NguoiDat_FullName = model.NguoiDat_FullName; objModProduct_Order.NguoiDat_Sex = model.NguoiDat_Sex; objModProduct_Order.NguoiDat_Address = model.NguoiDat_Address; objModProduct_Order.NguoiDat_Email = model.NguoiDat_Email; objModProduct_Order.NguoiDat_PhoneNumber = model.NguoiDat_PhoneNumber; objModProduct_Order.NguoiNhan_FullName = model.NguoiNhan_FullName; objModProduct_Order.NguoiNhan_Sex = model.NguoiNhan_Sex; objModProduct_Order.NguoiNhan_Address = model.NguoiNhan_Address; objModProduct_Order.NguoiNhan_Email = model.NguoiNhan_Email; objModProduct_Order.NguoiNhan_PhoneNumber = model.NguoiNhan_PhoneNumber; objModProduct_Order.Note = model.Note; objModProduct_Order.Status = (int)Global.EnumValue.OrderStatus.MOI; objModProduct_Order.CreateDate = DateTime.Now; ModProduct_OrderService.Instance.Save(objModProduct_Order); #endregion #region Lấy thông tin giỏ hàng - Chi tiết đơn hàng Global.Cart _Cart = new Global.Cart(); foreach (var itemCart in _Cart.Items) { // Số lượng tất cả iQuantityTotal += itemCart.Quantity; // số lượng từng loại iQuantityProduct++; objOrder_Detail = new ModProduct_Order_DetailsEntity(); objOrder_Detail.OrderId = objModProduct_Order.ID; objOrder_Detail.ProductInfoId = itemCart.ProductID; objOrder_Detail.MenuID = itemCart.MenuID; objOrder_Detail.LangID = itemCart.LangID; objOrder_Detail.Code = itemCart.Code; objOrder_Detail.Name = itemCart.Name; objOrder_Detail.File = itemCart.File; objOrder_Detail.Quantity = itemCart.Quantity; objOrder_Detail.FriceInput = itemCart.Price; objOrder_Detail.Frice = itemCart.Price; objOrder_Detail.PriceSale = itemCart.PriceSale; objOrder_Detail.VAT = itemCart.VAT; objOrder_Detail.SaleOffType = itemCart.SaleOffType; objOrder_Detail.PriceTextSaleView = itemCart.PriceTextSaleView; objOrder_Detail.TotalFrice = itemCart.TotalFrice; objOrder_Detail.Gifts = itemCart.Gifts; objOrder_Detail.Attach = itemCart.Attach; objOrder_Detail.Note = itemCart.Note; dTotalFriceFirst += itemCart.TotalFrice; // Thêm vào danh sách lstOrder_Details.Add(objOrder_Detail); } // thêm thông tin chi tiết ModProduct_Order_DetailsService.Instance.Save(lstOrder_Details); #endregion // Cập nhật lại thông tin đơn hàng objModProduct_Order.QuantityProduct = iQuantityProduct; objModProduct_Order.QuantityTotal = iQuantityTotal; objModProduct_Order.Discount = 0; // Số tiền tính được (Bao gồm cả VAT nếu có) objModProduct_Order.TotalFriceFirst = dTotalFriceFirst; // Sau khi đã giảm trừ (Giả sử từ cho 200 khi đặt hàng online) objModProduct_Order.TotalFrice = objModProduct_Order.TotalFriceFirst - objModProduct_Order.Discount; // Lưu lại ModProduct_OrderService.Instance.Save(objModProduct_Order); // Xóa dữ liệu của giỏ hàng _Cart.RemoveAll(); _Cart.Save(); ViewPage.Alert("Đơn hàng đã gửi thành công. Xin cảm ơn quý khách hàng!"); ViewPage.Navigate("/default.aspx"); }