public IActionResult Index() { var cartListViewModel = new CartViewModel(); var listOfProdIds = _cartService.Get(HttpContext.Session); if (listOfProdIds != null) { var listOfProducts = new List <Product>(); foreach (var prodId in listOfProdIds) { var product = _dbContext.Products.Include(prod => prod.Category).Include(prod => prod.Reviews).FirstOrDefault(prod => prod.Id == prodId); if (product != null) { cartListViewModel.AddProductviewModel(new ProductCardViewModel(product) { IsInCart = true }); } } } return(View("Index", cartListViewModel)); }