Exemplo n.º 1
0
 public bool Add_HoaDon(HoaDon hd)
 {
     try
     {
         db.HoaDon.Add(hd);
         db.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemplo n.º 2
0
        public ActionResult Payment()
        {
            var cart = (List<HangHoaList>)Session[Common.Common.CartSession];
            //tinh tong gia tri cua hoa don
            decimal s = 0;
            foreach (var item in cart)
            {
                s = s + Convert.ToDecimal(item.Product.GiaBan * item.SoLuong);
            }
            // Them HoaDon
            // string NV_ID = Main.Controllers.AccountController.ID_NV;

            HoaDon hd = new HoaDon
            {
                MaHD = new GetMa().MaHoaDon(),
                LoaiHD = false,
                NgayTao = DateTime.Now,
                TenTK_NV = Admin.Controllers.AccountController.id_NV,
                TongTien = Convert.ToDouble(s),
                MaDT=null,
            };
            db.HoaDon.Add(hd);
            db.SaveChanges();
            var detail = new KhoDb();
            foreach (var item in cart)
            {
                var hoadon = new CT_HoaDon();
                hoadon.MaHD = hd.MaHD;
                hoadon.SoLuong = item.SoLuong;
                hoadon.MaHH = item.Product.MaHH;
                hoadon.DonGia = item.Product.GiaBan;
                hoadon.LoiNhuan = Convert.ToDecimal(item.Product.GiaBan - item.Product.GiaNhap);
                detail.Add_CT_HoaDon(hoadon);
            }
            return RedirectToAction("Index", "Cart", new { area = "Sale" });
        }
Exemplo n.º 3
0
        public ActionResult Create(string maDT, string tongtien)
        {
            var list = (List<CartItem>)Session["Cart"];
            if (list != null)
            {

                HoaDon hd = new HoaDon()
                {
                    MaHD = ma.MaHoaDon(),
                    MaDT = maDT,
                    NgayTao = DateTime.Now,
                    LoaiHD = true,
                    TenTK_NV = "NV001",
                    TongTien = Convert.ToDouble(tongtien)
                };
                db.HoaDon.Add(hd);
                db.SaveChanges();
                Create_CongNo(hd.MaHD);
                foreach (var item in list)
                {
                    CT_HoaDon ct = new CT_HoaDon()
                    {
                        MaHD = hd.MaHD,
                        MaHH = item.Product.MaHH,
                        SoLuong = item.SoLuong,
                        DonGia = item.DonGia
                    };
                    db.CT_HoaDon.Add(ct);
                    HangHoa hh = db.HangHoa.Single(x => x.MaHH == item.Product.MaHH);
                    hh.SoLuong += item.SoLuong;
                    hh.GiaNhap = item.DonGia;
                    db.SaveChanges();
                }

                return Json(Url.Action("Index", "GiaoDich"));
            }
            else
                return Json(Url.Action("Create", "GiaoDich"));
        }