コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 public void UpdatePie(Pie pie)
 {
     throw new NotImplementedException();
 }