public void ActionAdd(ModProduct_Order_DetailsModel model) { if (model.RecordID > 0) { item = ModProduct_Order_DetailsService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { item = new ModProduct_Order_DetailsEntity(); // khoi tao gia tri mac dinh khi insert } ViewBag.Data = item; ViewBag.Model = model; }
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"); }