public int RemoveFromCart(PieDto pie) { var shoppingCartItem = _Context.ShoppingCartItems.SingleOrDefault(c => c.pie.Id == pie.Id && c.ShoppingCartId == ShoppingCartId); var localAmount = 0; if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } else { _Context.ShoppingCartItems.Remove(shoppingCartItem); } _Context.SaveChanges(); return(localAmount); }
public void AddCart(PieDto pie, int amount) { var shoppingCartItem = _Context.ShoppingCartItems.SingleOrDefault(c => c.pie.Id == pie.Id && c.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItemDto { ShoppingCartId = ShoppingCartId, pie = pie, Amount = 1 }; _Context.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _Context.SaveChanges(); }