Ejemplo n.º 1
0
        public int RemoveFromCart(Vinyl vinyl)
        {
            var shoppingCartItem =
                appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Vinyl.VinylId == vinyl.VinylId && 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);
        }
Ejemplo n.º 2
0
        public Vinyl DeleteVinyl(int vinylId)
        {
            Vinyl dbEntry = appDbContext.Vinyls.FirstOrDefault(v => v.VinylId == vinylId);

            if (dbEntry != null)
            {
                appDbContext.Vinyls.Remove(dbEntry);
                appDbContext.SaveChanges();
            }
            return(dbEntry);
        }
Ejemplo n.º 3
0
        public void AddToCart(Vinyl vinyl, int amount)
        {
            var shoppingCartItem =
                appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Vinyl.VinylId == vinyl.VinylId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Vinyl          = vinyl,
                    Amount         = 1
                };

                appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            appDbContext.SaveChanges();
        }
Ejemplo n.º 4
0
 public void SaveVinyl(Vinyl vinyl)
 {
     if (vinyl.VinylId == 0)
     {
         appDbContext.Vinyls.Add(vinyl);
     }
     else
     {
         Vinyl dbEntry = appDbContext.Vinyls.FirstOrDefault(v => v.VinylId == vinyl.VinylId);
         if (dbEntry != null)
         {
             dbEntry.ShortDescription  = vinyl.ShortDescription;
             dbEntry.LongDescription   = vinyl.LongDescription;
             dbEntry.Label             = vinyl.Label;
             dbEntry.Price             = vinyl.Price;
             dbEntry.ImageUrl          = vinyl.ImageUrl;
             dbEntry.ImageThumbnailUrl = vinyl.ImageThumbnailUrl;
             dbEntry.IsVinylOfTheWeek  = vinyl.IsVinylOfTheWeek;
             dbEntry.InStock           = vinyl.InStock;
             dbEntry.CategoryId        = vinyl.CategoryId;
         }
     }
     appDbContext.SaveChanges();
 }