public IActionResult Checkout() { //if u try to checkout with 0 items var cart = GetShoppingCart(); if (GetNumOfItems() == 0) { return(RedirectToAction(nameof(Index))); } //if entering the checkout and one items became out of stock var itemsList = _context.ShoppingCartItem.Where(i => i.AssociatedShoppingCart.Id == cart.Id).Include(c => c.Product); foreach (var item in itemsList) { if (item.Product.InStock == false) { _context.Remove(item); } } _context.SaveChanges(); return(View()); }
public int Delete(int id) { var review = _context.Review.FirstOrDefault(r => r.Id == id); if (review == null) { return(0); } _context.Review.Remove(review); _context.SaveChanges(); return(1); }