Example #1
0
        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();
            }
        }
Example #2
0
        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);
        }
Example #3
0
 public void Delete(Bread bread)
 {
     _bakeryDbContext.Remove(bread);
 }
Example #4
0
 public void Add(Bread bread)
 {
     _bakeryDbContext.Add(bread);
 }