Exemple #1
0
 public async Task <List <CartItem> > GetCartItemsOfActiveUserAsync(User user)
 {
     using (var dbContext = new TheStoreContext())
     {
         return(await dbContext.CartItems.Include(y => y.Product).Where(x => x.User == user).ToListAsync());
     }
 }
 public async Task <List <T> > GetAllProductsAsync()
 {
     using (var dbContext = new TheStoreContext())
     {
         return(await dbContext.Set <T>().ToListAsync());
     }
 }
 public async Task <T> FindProductByIdAsync(int id)
 {
     using (var dbContext = new TheStoreContext())
     {
         return(await dbContext.FindAsync <T>(id));
     }
 }
Exemple #4
0
 public async Task <List <User> > GetAllUsersAsync()
 {
     using (var dbContext = new TheStoreContext())
     {
         return(await dbContext.Users.ToListAsync());
     }
 }
Exemple #5
0
 public async Task <User> FindUserByIdAsync(int id)
 {
     using (var dbContext = new TheStoreContext())
     {
         return(await dbContext.FindAsync <User>(id));
     }
 }
 public async Task DeleteProductAsync(T product)
 {
     using (var dbContext = new TheStoreContext())
     {
         dbContext.Remove(product);
         await dbContext.SaveChangesAsync();
     }
 }
Exemple #7
0
 public async Task DeleteUserAsync(User user)
 {
     using (var dbContext = new TheStoreContext())
     {
         dbContext.Remove(user);
         await dbContext.SaveChangesAsync();
     }
 }
Exemple #8
0
 public User GetUserByIdAsync(int id)
 {
     using (var dbContext = new TheStoreContext())
     {
         var test = dbContext.Users.Include(x => x.CartItems)
                    .ThenInclude(x => x.Product)
                    .FirstOrDefault(y => y.Id == id);
         return(test);
     }
 }
Exemple #9
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 #10
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();
            }
        }
Exemple #11
0
 public async Task <List <CartItem> > GetAllCartItemsAsync(bool includeProductData = false)
 {
     if (includeProductData)
     {
         using (var dbContext = new TheStoreContext())
         {
             return(await dbContext.CartItems.Include(x => x.Product).ToListAsync());
         }
     }
     else
     {
         using (var dbContext = new TheStoreContext())
         {
             return(await dbContext.CartItems.ToListAsync());
         }
     }
 }
        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();
            }
        }
Exemple #13
0
 public ProductController(TheStoreContext context)
 {
     _context = context;
 }