public ActionResult XoaSP(int iMaSP) { List <SanPhamGH> lstSP = LayGioHang(); SanPhamGH SP = lstSP.Find(n => n.MaSP == iMaSP); lstSP.Remove(SP); Session["GioHang"] = lstSP; return(Json(lstSP, JsonRequestBehavior.AllowGet)); }
public ActionResult ThemGioHang(int iMaSP, int?SL) { List <SanPhamGH> lstSP = LayGioHang(); SanPhamGH SP = lstSP.Find(n => n.MaSP == iMaSP); if (SP == null) { SP = new SanPhamGH(); SANPHAM sp = db.SANPHAMs.Single(n => n.MaSP == iMaSP); SP.MaSP = iMaSP; SP.TenSP = sp.TenSP; SP.HinhMinhHoa = sp.HinhMinhHoa; SP.SoLuong = int.Parse(sp.SoLuong.ToString()); SP.DonGia = double.Parse(sp.DonGia.ToString()); if (SL == null) { SP.SoLuongMua = 1; } else { SP.SoLuongMua = int.Parse(SL.ToString()); } lstSP.Add(SP); Session["GioHang"] = lstSP; return(Json(lstSP, JsonRequestBehavior.AllowGet)); } else { if (SL > SP.SoLuong) { return(Json(1)); } else { if (SL == null) { SP.SoLuongMua++; } else { SP.SoLuongMua = int.Parse(SL.ToString()); } Session["GioHang"] = lstSP; return(Json(lstSP, JsonRequestBehavior.AllowGet)); } } }
public ActionResult ThemGioHang(int iMaSP, int? SL) { List<SanPhamGH> lstSP = LayGioHang(); SanPhamGH SP = lstSP.Find(n => n.MaSP == iMaSP); if (SP == null) { SP = new SanPhamGH(); NuocHoa nuocHoa = db.NuocHoas.Single(n => n.MaNuocHoa == iMaSP); SP.MaSP = iMaSP; SP.TenSP = nuocHoa.TenNuocHoa; SP.AnhSP = nuocHoa.AnhBia; SP.GiaSP = double.Parse(nuocHoa.GiaBan.ToString()); if (SL>0) { SP.SoLuong = 1; } else { SP.SoLuong = int.Parse(SL.ToString()); } lstSP.Add(SP); Session["GioHang"] = lstSP; return Json(lstSP, JsonRequestBehavior.AllowGet); } else { if (SL == null) { SP.SoLuong++; } else { SP.SoLuong = int.Parse(SL.ToString()); } Session["GioHang"] = lstSP; return Json(lstSP, JsonRequestBehavior.AllowGet); } }