Exemple #1
0
        public string TaoDonHang(DONHANG donHang)
        {
            decimal TongTien  = 0;
            var     cartItems = GetCartItems();

            foreach (var item in cartItems)
            {
                var ctDonHang = new CHITIETDONHANG
                {
                    MaSP    = item.MaSP,
                    MaDH    = donHang.MaDH,
                    DonGia  = item.SanPham.GiaBan,
                    SoLuong = item.Count
                };

                TongTien += (item.Count * item.SanPham.GiaBan) ?? 0;

                db.CHITIETDONHANGs.Add(ctDonHang);
            }

            donHang.TongTien = TongTien;

            db.SaveChanges();
            EmptyCart();
            return(donHang.MaDH);
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var donHang = new DONHANG();
            var ctDonHang = new CHITIETDONHANG();

            TryUpdateModel(ctDonHang);
            TryUpdateModel(donHang);

            try
            {
                    donHang.MaTK = Request.Cookies["MaTK"]["MaTK"];
                    donHang.MaDH = (db.LaySoLuongDonHang() + 1).ToString();
                    donHang.UserName = values["UserName"];
                    donHang.NgayDatHang = DateTime.Now;
                    donHang.MaTT = "TT01";
                    string thanhPho = values["ThanhPho"];
                    string quan = values["Quan"];
                    string phuong = values["Phuong"];
                    string diaChi = values["DiaChi"];
                    donHang.DiaChi = diaChi + " " + phuong + " " + quan + " " + thanhPho;
                    donHang.Email = values["Email"];

                    donHang.MaHTTT = "TT";
                    donHang.MaTK = null;
                    donHang.SDT = values["SDT"];
                    donHang.TenNguoiNhan = values["Ten"];
                    donHang.TongTien = Decimal.Parse(values["TongTien"]);

                    ctDonHang.DonGia = Decimal.Parse(values["DonGia"]);
                    ctDonHang.MaDH = donHang.MaDH;
                    ctDonHang.MaSP = donHang.MaDH;

                    db.DONHANGs.Add(donHang);
                    db.SaveChanges();

                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.TaoDonHang(donHang);

                    return RedirectToAction("Complete", new { id = donHang.MaDH });
                //}
            }
            catch (System.Exception ex)
            {
                return View(donHang);
            }
        }
Exemple #3
0
        public string TaoDonHang(DONHANG donHang)
        {
            decimal TongTien = 0;
            var cartItems = GetCartItems();

            foreach (var item in cartItems)
            {
                var ctDonHang = new CHITIETDONHANG
                {
                    MaSP = item.MaSP,
                    MaDH = donHang.MaDH,
                    DonGia = item.SanPham.GiaBan,
                    SoLuong = item.Count
                };

                TongTien += (item.Count * item.SanPham.GiaBan) ?? 0;

                db.CHITIETDONHANGs.Add(ctDonHang);
            }

            donHang.TongTien = TongTien;

            db.SaveChanges();
            EmptyCart();
            return donHang.MaDH;
        }