コード例 #1
0
        public ActionResult Index(CusInfoViewModel model)
        {
            // kiểm tra danh sách sản phẩm về số lượng
            bool isCheck = true;

            if (Session["Cart"] == null)
            {
                Session["Cart"] = new Cart();
            }
            model.cart = Session["Cart"] as Cart;
            foreach (var item in model.cart.GetList())
            {
                if (!CusInfoService.CheckNumberProduct(item.Product.MASP, item.Quantity))
                {
                    isCheck = false;
                    break;
                }
            }
            if (!isCheck)
            {
                return(RedirectToAction("Index", "Cart"));
            }
            //lấy Id Khách hàng
            int Id = 1;// mã khách vãn lai

            if (Session[CommonConstands.USER_SESSION] != null)
            {
                long MaTK = (Session[CommonConstands.USER_SESSION] as UserLogin).UserID;
                Id = CusInfoService.GetIdCustomer(MaTK);
            }
            // Thêm đơn hàng
            CusInfoService.AddBill(model, Id);
            return(RedirectToAction("Success"));
        }
コード例 #2
0
        // Phương thức thêm một đơn hàng
        public static void AddBill(CusInfoViewModel model, int idKhachHang)
        {
            // lấy ra id lớn nhất
            BANDONGHOEntities db  = new BANDONGHOEntities();
            DONHANG           don = (from dh in db.DONHANGs
                                     orderby dh.MADH descending
                                     select dh).Take(1).SingleOrDefault();
            int id = don == null ? 0:don.MADH;

            id += 1;
            // tạo mới đơn hàng
            DONHANG donhang = new DONHANG
            {
                MADH       = id,
                MAKH       = idKhachHang,
                DIACHIGIAO = model.DiaChiGiao,
                SDT        = model.Sdt,
                MOTA       = model.MoTa,
                TONGTIEN   = model.cart.TotalMoney(),
                TRANGTHAI  = "0",
                NGAYDAT    = DateTime.Now,
                NGAYGIAO   = DateTime.Now.AddDays(7)
            };

            db.DONHANGs.Attach(donhang);
            db.DONHANGs.Add(donhang);
            db.SaveChanges();


            // thêm danh sách chi tiết đơn hàng
            AddListDetailBill(model.cart, id);
        }
コード例 #3
0
        public ActionResult Index()
        {
            CusInfoViewModel cus = new CusInfoViewModel();

            if (Session["Cart"] == null)
            {
                Session["Cart"] = new Cart();
            }
            cus.cart = Session["Cart"] as Cart;
            return(View(cus));
        }