public ActionResult XoaSP(int iMaSP) { List <SamPhamGH> lstSP = LayGioHang(); SamPhamGH SP = lstSP.Find(n => n.BookId == iMaSP); lstSP.Remove(SP); Session["GioHang"] = lstSP; return(Json(lstSP, JsonRequestBehavior.AllowGet)); }
public ActionResult ThemGioHang(int iMaSP, int?SL) { List <SamPhamGH> lstSP = LayGioHang(); SamPhamGH SP = lstSP.Find(n => n.BookId == iMaSP); if (SP == null) { SP = new SamPhamGH(); Book sp = db.Books.Single(n => n.BookId == iMaSP); SP.BookId = iMaSP; SP.Title = sp.Title; SP.ImgUrl = sp.ImgUrl; SP.Price = double.Parse(sp.Price.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 == null) { SP.SoLuongMua++; } else { SP.SoLuongMua = int.Parse(SL.ToString()); } Session["GioHang"] = lstSP; return(Json(lstSP, JsonRequestBehavior.AllowGet)); } }