コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 public void UpdatePie(Pie pie)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
 public void CreatePie(Pie pie)
 {
     _dbContext.Pies.Add(pie);
     _dbContext.SaveChanges();
 }
コード例 #5
0
 public void UpdatePie(Pie pie)
 {
     _dbContext.Pies.Update(pie);
     _dbContext.SaveChanges();
 }