public ActionResult ThemVaoGioHang(int?masanpham) { if (Session["GioHangTamThoi"] == null) { Session["GioHangTamThoi"] = new List <ClassGioHangTamThoi>(); Session["Dem"] = "Trống"; } List <ClassGioHangTamThoi> GioHangTamThoi = Session["GioHangTamThoi"] as List <ClassGioHangTamThoi>; if (GioHangTamThoi.FirstOrDefault(n => n.MaSanPham == masanpham) == null) { tbSanPham sanpham = dt.tbSanPhams.Find(masanpham); if (Session["Dem"].ToString() == "Trống") { Session["Dem"] = "0"; } Session["Dem"] = Int32.Parse(Session["Dem"].ToString()) + 1; ClassGioHangTamThoi item = new ClassGioHangTamThoi() { MaSanPham = sanpham.MaSanPham, TenSanPham = sanpham.TenSanPham, SoLuong = 1, GiaSanPham = decimal.ToInt32(sanpham.GiaSanPham.Value) }; GioHangTamThoi.Add(item); } else { ClassGioHangTamThoi gio = GioHangTamThoi.FirstOrDefault(n => n.MaSanPham == masanpham); gio.SoLuong++; } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult CapNhat(int masanpham, int soluongmoi) { List <ClassGioHangTamThoi> giohangtamthoi = Session["GioHangTamThoi"] as List <ClassGioHangTamThoi>; ClassGioHangTamThoi capnhat = giohangtamthoi.FirstOrDefault(n => n.MaSanPham == masanpham); if (capnhat != null) { capnhat.SoLuong = soluongmoi; } return(Redirect(Request.UrlReferrer.ToString())); }