コード例 #1
0
        public void ChiTietPhieuNhap(PhieuNhap phieunhap)
        {
            if (CartSession.CartTonTai(this.HttpContext))
            {
                var cart = CartSession.GetCart(this.HttpContext);
                foreach (var item in cart.ListItem)
                {
                    var sp = db.SanPhams.SingleOrDefault(s => s.IdSanPham == item.SanPham.IdSanPham);
                    if (String.IsNullOrEmpty(item.Gia.ToString()) || item.Gia ==0)
                    {
                        ChiTietPhieuNhap ctpn = new ChiTietPhieuNhap
                        {
                            SoLuong = item.SoLuong,
                            ThanhTien = item.ThanhTien,
                            SanPham = sp,
                            GiaNhap = sp.Gia,
                            PhieuNhap = phieunhap
                        };
                        db.ChiTietPhieuNhaps.Add(ctpn);

                    }
                    else
                    {
                        ChiTietPhieuNhap ctpn = new ChiTietPhieuNhap
                        {
                            SoLuong = item.SoLuong,
                            ThanhTien = item.ThanhTien,
                            SanPham = sp,
                            GiaNhap = item.Gia,
                            PhieuNhap = phieunhap
                        };
                        sp.Gia = item.Gia;
                        db.Entry(sp).State = EntityState.Modified;
                        db.SaveChanges();
                        db.ChiTietPhieuNhaps.Add(ctpn);
                    }

                    XuLiTonKho(sp, item.SoLuong);
                }
            }
        }
コード例 #2
0
 public ActionResult LuuPhieuNhap()
 {
     var cart = CartSession.GetCart(this.HttpContext);
     DateTime now = System.DateTime.Now;
     if (cart != null)
     {
         //User u = Session["admin"] as User;
         //var user = db.Users.SingleOrDefault(us => us.Id == u.Id);
         PhieuNhap phieunhap = new PhieuNhap { NgayLap=now};
         db.PhieuNhaps.Add(phieunhap);
         db.SaveChanges();
         ChiTietPhieuNhap(phieunhap);
         CartSession.XoaCartSession(this.HttpContext);
         return RedirectToAction("Index");
     }
     TempData["error"] = "Chưa chọn sản phẩm";
     return RedirectToAction("Index");
 }