Exemple #1
0
        public async Task SaveCartItemAsync(CartItem cartItem)
        {
            using (var dbContext = new TheStoreContext())
            {
                if (cartItem.Id == 0)
                {
                    await dbContext.CartItems.AddAsync(cartItem);
                }
                else
                {
                    dbContext.Update(cartItem);
                }

                await dbContext.SaveChangesAsync();
            }
        }
Exemple #2
0
        public async Task SaveUserAsync(User user)
        {
            using (var dbContext = new TheStoreContext())
            {
                if (user.Id == 0)
                {
                    await dbContext.AddAsync(user);
                }
                else
                {
                    dbContext.Update(user);
                }

                await dbContext.SaveChangesAsync();
            }
        }
        public async Task SaveProductAsync(T product)
        {
            using (var dbContext = new TheStoreContext())
            {
                if (product.Id == 0)
                {
                    product.DateCreated = DateTime.Now;
                    await dbContext.AddAsync(product);
                }
                else
                {
                    product.DateModified = DateTime.Now;
                    dbContext.Update(product);
                }

                await dbContext.SaveChangesAsync();
            }
        }