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)); } }
public async Task <List <User> > GetAllUsersAsync() { using (var dbContext = new TheStoreContext()) { return(await dbContext.Users.ToListAsync()); } }
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(); } }
public async Task DeleteUserAsync(User user) { using (var dbContext = new TheStoreContext()) { dbContext.Remove(user); await dbContext.SaveChangesAsync(); } }
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); } }
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(); } }
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 <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(); } }
public ProductController(TheStoreContext context) { _context = context; }