Beispiel #1
0
        public int RemoveFromCart(Cloth cloth)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Cloth.ClothId == cloth.ClothId && s.ShoppingCartId == ShoppingCartId);

            var localAmount = 0;

            if (shoppingCartItem != null)
            {
                if (shoppingCartItem.Amount > 1)
                {
                    shoppingCartItem.Amount--;
                    localAmount = shoppingCartItem.Amount;
                }
                else
                {
                    _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
                }
            }

            _appDbContext.SaveChanges();

            return(localAmount);
        }
Beispiel #2
0
        public void AddToCart(Cloth cloth, int amount)
        {
            var _shoppingcartitem = _appDbContext.ShoppingCartItems.SingleOrDefault
                                        (s => s.Cloth.ClothId == cloth.ClothId && s.ShoppingCartId == ShoppingCartId);

            if (_shoppingcartitem == null)
            {
                _shoppingcartitem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Cloth          = cloth,
                    Amount         = amount
                };
                _appDbContext.ShoppingCartItems.Add(_shoppingcartitem);
            }
            else
            {
                _shoppingcartitem.Amount = _shoppingcartitem.Amount + amount;
            }
            _appDbContext.SaveChanges();
        }