public void AddToCart(Bread bread, int amount) { var shoppingCartItem = _bakeryDbContext.ShoppingCartItems.SingleOrDefault( s => s.Bread.BreadId == bread.BreadId && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Bread = bread, Amount = amount }; _bakeryDbContext.ShoppingCartItems.Add(shoppingCartItem); _bakeryDbContext.SaveChanges(); } }
public int RemoveFromCart(Bread bread) { var shoppingCartItem = _bakeryDbContext.ShoppingCartItems.SingleOrDefault( s => s.Bread.BreadId == bread.BreadId && s.ShoppingCartId == ShoppingCartId); var localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } else { _bakeryDbContext.ShoppingCartItems.Remove(shoppingCartItem); } } _bakeryDbContext.SaveChanges(); return(localAmount); }
public void Delete(Bread bread) { _bakeryDbContext.Remove(bread); }
public void Add(Bread bread) { _bakeryDbContext.Add(bread); }