public ActionResult CapNhatGioHang(VatPhamTrongGioHang item) { SanPham spCheck = _spService.LayTheoMa(item.MaSP); if (spCheck.SoLuongTon < item.SoLuong) { return(View("ThongBao")); } List <VatPhamTrongGioHang> lstGH = LayGioHang(); VatPhamTrongGioHang itemGHUpdate = lstGH.Find(n => n.MaSP == item.MaSP); itemGHUpdate.SoLuong = item.SoLuong; itemGHUpdate.ThanhTien = itemGHUpdate.SoLuong * itemGHUpdate.DonGia; return(RedirectToAction("XemGioHang")); }
public ActionResult ThemVaoGioHang(int MaSP, string strURL) { SanPham sp = _spService.LayTheoMa(MaSP); if (sp == null) { Response.StatusCode = 404; return(null); } List <VatPhamTrongGioHang> GioHang = LayGioHang(); VatPhamTrongGioHang spCheck = GioHang.SingleOrDefault(x => x.MaSP == MaSP); if (spCheck != null) { if (sp.SoLuongTon - spCheck.SoLuong < spCheck.SoLuong) { return(View("ThongBao")); } spCheck.SoLuong++; spCheck.ThanhTien = spCheck.SoLuong * spCheck.DonGia; return(Redirect(strURL)); } VatPhamTrongGioHang item = new VatPhamTrongGioHang(); item.MaSP = MaSP; item.TenSP = sp.Ten; item.HinhAnh = sp.HinhAnh; item.DonGia = sp.DonGia; item.SoLuong = 1; item.ThanhTien = item.DonGia * item.SoLuong; if (sp.SoLuongTon < item.SoLuong) { return(View("ThongBao")); } GioHang.Add(item); return(Redirect(strURL)); }
public ActionResult CapNhatGioHang(int MaSP) { if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } SanPham sp = _spService.LayTheoMa(MaSP); if (sp == null) { Response.StatusCode = 404; return(null); } List <VatPhamTrongGioHang> lstGioHang = LayGioHang(); VatPhamTrongGioHang spCheck = lstGioHang.SingleOrDefault(n => n.MaSP == MaSP); if (spCheck == null) { return(RedirectToAction("Index", "Home")); } ViewBag.GioHang = lstGioHang; return(View(spCheck)); }