Beispiel #1
0
        public async Task<IActionResult> DetailsPost(int ma, int soLuong)
        {
            List<SLSP> lstGioHang = HttpContext.Session.Get<List<SLSP>>("ssGioHang");

            if (lstGioHang == null)
            {
                lstGioHang = new List<SLSP>();
            }
            SLSP sp = new SLSP { MaSP = ma, SoLuong = soLuong}; // Sử dụng struct SLSP để lưu mã sp và số lượng
            lstGioHang.Add(sp);
            HttpContext.Session.Set("ssGioHang", lstGioHang);

            return RedirectToAction("Index", "Home", new { area = "Customer" });
        }
Beispiel #2
0
 public IActionResult Remove(int ma)
 {
     List<SLSP> lstGioHang = HttpContext.Session.Get<List<SLSP>>("ssGioHang");
     var result = lstGioHang.ToList();
     if (lstGioHang.Count > 0)
     {
         SLSP sp = lstGioHang.Find(a => a.MaSP == ma);
         if (lstGioHang.Contains(sp))
         {
             lstGioHang.Remove(sp);
         }
     }
     HttpContext.Session.Set("ssGioHang", lstGioHang);
     return RedirectToAction("Index");
 }