Ejemplo n.º 1
0
 public void SaveJewelry(Jewelry jewelry)
 {
     if (jewelry.JewelryId == 0)
     {
         _appDbContext.Add(jewelry);
     }
     else
     {
         _appDbContext.Update(jewelry);
     }
     _appDbContext.SaveChanges();
 }
Ejemplo n.º 2
0
        public void AddToCart(Jewelry jewelry, int amount)
        {
            var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault(
                s => s.Jewelry.JewelryId == jewelry.JewelryId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Jewelry        = jewelry,
                    Amount         = amount
                };
                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _appDbContext.SaveChanges();
        }
Ejemplo n.º 3
0
        public int RemoveFromCart(Jewelry jewelry)
        {
            var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault(
                s => s.Jewelry.JewelryId == jewelry.JewelryId && 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);
        }