public string UpdateGioHang(int idSanPham, int soLuong) { GioHang gioHang = (GioHang)Session["GioHang"]; FSanPhamGioHang fSanPhamGioHang = new FSanPhamGioHang(); string json = fSanPhamGioHang.ChangeItem(idSanPham, gioHang.ID, soLuong); FGioHang fGioHang = new FGioHang(); Session["GioHang"] = fGioHang.GetGH_MaGH(gioHang.ID); return(json); }
public ActionResult Product(int masp, int soLuong) { FSanPham fSanPham = new FSanPham(); FSanPhamGioHang fSanPhamGioHang = new FSanPhamGioHang(); FGioHang fGioHang = new FGioHang(); var sp = fSanPham.FindSanPham(masp); if (sp.TenSP.Length > 40) { sp.TenSP = sp.TenSP.Substring(0, 35) + "..."; } var gioHang = (GioHang)Session["GioHang"]; SanPhamGioHang sanPhamGioHang = new SanPhamGioHang(); if (Session["KhachHang"] != null) { KhachHang x = (KhachHang)Session["KhachHang"]; if (gioHang == null) { gioHang = fGioHang.NewGH(x); } gioHang = fSanPhamGioHang.AddItem(masp, gioHang.ID, soLuong); Session["GioHang"] = gioHang; return(RedirectToAction("Shopcart")); } else { if (Request.Cookies["IDCart"] != null) { string x = Request.Cookies["IDCart"].Value; var giohangtam = fGioHang.GetGH_MaGH(Convert.ToInt32(x)); giohangtam = fSanPhamGioHang.AddItem(masp, Convert.ToInt32(x), soLuong); Session["GioHang"] = giohangtam; return(RedirectToAction("Shopcart")); } else { gioHang = fGioHang.NewGH(); Response.Cookies["IDCart"].Value = gioHang.ID.ToString(); Response.Cookies["IDCart"].Expires = DateTime.Now.AddDays(1); gioHang = fSanPhamGioHang.AddItem(masp, gioHang.ID, soLuong); Session["GioHang"] = gioHang; return(RedirectToAction("Shopcart")); } } }
// GET: Shopcart public ActionResult Shopcart() { var temp = Session["KhachHang"]; var gioHang = (GioHang)Session["GioHang"]; if (temp != null) { if (gioHang == null) { gioHang = new GioHang(); Session["GioHang"] = gioHang; return(View(gioHang)); } else { return(View(gioHang)); } } else { if (gioHang != null) { return(View(gioHang)); } else if (Request.Cookies["IDCart"] != null) { string x = Request.Cookies["IDCart"].Value; FGioHang fGioHang = new FGioHang(); gioHang = fGioHang.GetGH_MaGH(Convert.ToInt32(x)); Session["GioHang"] = gioHang; return(View(gioHang)); } else { gioHang = new GioHang(); Session["GioHang"] = gioHang; return(View(gioHang)); } } }