public int RemoveFromCart(Honden hond) { var shoppingCartItem = _appDbContext.WinkelWagenItems.SingleOrDefault( s => s.Honden.HondId == hond.HondId && s.WinkelWagenId == WinkelWagenId); var localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Hoeveelheid > 1) { shoppingCartItem.Hoeveelheid--; localAmount = shoppingCartItem.Hoeveelheid; } else { _appDbContext.WinkelWagenItems.Remove(shoppingCartItem); } } _appDbContext.SaveChanges(); return(localAmount); }
public void AddToCart(Honden hond, int amount) { var shoppingCartItem = _appDbContext.WinkelWagenItems.SingleOrDefault( s => s.Honden.HondId == hond.HondId && s.WinkelWagenId == WinkelWagenId); if (shoppingCartItem == null) { shoppingCartItem = new WinkelWagenItem { WinkelWagenId = WinkelWagenId, Honden = hond, Hoeveelheid = 1 }; _appDbContext.WinkelWagenItems.Add(shoppingCartItem); } else { shoppingCartItem.Hoeveelheid++; } _appDbContext.SaveChanges(); }