public IActionResult Index() { if (HttpContext.Session.GetString("Cart") == null) { ViewBag.ERRORMESSAGE = "List is empty"; return(View()); } var cart = JsonConvert.DeserializeObject <CartViewModel>(HttpContext.Session.GetString("Cart")); if (cart.ListCart == null) { ViewBag.ERRORMESSAGE = "List is empty"; return(View()); } if (_cart.GetRooms() == null) { List <RoomViewModel> listroom = _context.Rooms.Select(x => new RoomViewModel() { Id = x.RoomId, RoomName = x.RoomName, Status = x.Status, }).ToList(); _cart.AddRooms(listroom); cart = _cart.GetCart(); HttpContext.Session.SetString("Cart", JsonConvert.SerializeObject(cart)); } return(View(cart)); }