public int RemoveFromCart(Pie pie) { var shopingCartItem = _appDbContext.ShopingCartItems.SingleOrDefault(s => s.Pie.PieId == pie.PieId && s.ShopingCartId == ShopingCartId); var localAmount = 0; if (shopingCartItem == null) { if (shopingCartItem.Amount > 1) { shopingCartItem.Amount--; localAmount = shopingCartItem.Amount; } else { _appDbContext.ShopingCartItems.Remove(shopingCartItem); } } _appDbContext.SaveChanges(); return(localAmount); }
public void AddToCart(Pie pie, int amount) { var shopingCartItem = _appDbContext.ShopingCartItems.SingleOrDefault(s => s.Pie.PieId == pie.PieId && s.ShopingCartId == ShopingCartId); if (shopingCartItem == null) { shopingCartItem = new ShoppingCartItem { ShopingCartId = ShopingCartId, Pie = pie, Amount = 1, }; _appDbContext.ShopingCartItems.Add(shopingCartItem); } else { shopingCartItem.Amount++; } _appDbContext.SaveChanges(); }
public void UpdatePie(Pie pie) { throw new NotImplementedException(); }