public void AddToCart(Clothes clothes, int amount) { var shoppingCartItem = _atDbContext.ShopppingCartItems.SingleOrDefault( s => s.Clothes.ClothesId == clothes.ClothesId && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Clothes = clothes, Amount = amount }; _atDbContext.ShopppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _atDbContext.SaveChanges(); }
public int RemoveFromCart(Clothes clothes) { var shoppingCartItem = _atDbContext.ShopppingCartItems.SingleOrDefault( s => s.Clothes.ClothesId == clothes.ClothesId && s.ShoppingCartId == ShoppingCartId); var localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } else { _atDbContext.ShopppingCartItems.Remove(shoppingCartItem); } } _atDbContext.SaveChanges(); return(localAmount); }