public int RemoveFromCart(Pie pie) { var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault( s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId); int localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } { _appDbContext.ShoppingCartItems.Remove(shoppingCartItem); } } _appDbContext.SaveChanges(); return(localAmount); }
public void AddToCart(Pie pie, int amount = 1) { var shoppingCartItem = _appDbContext.ShoppingCartItems .FirstOrDefault(c => c.Pie.PieId == pie.PieId && c.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { Pie = pie, ShoppingCartId = ShoppingCartId, Amount = amount }; _appDbContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _appDbContext.SaveChanges(); }
public void UpdatePie(Pie pie) { throw new NotImplementedException(); }
public void CreatePie(Pie pie) { _dbContext.Pies.Add(pie); _dbContext.SaveChanges(); }
public void UpdatePie(Pie pie) { _dbContext.Pies.Update(pie); _dbContext.SaveChanges(); }