using Microsoft.EntityFrameworkCore; using ShopOnline.Api.Data; using ShopOnline.Api.Entities; using ShopOnline.Api.Repositories.Contracts; namespace ShopOnline.Api.Repositories { public class ProductRepository : IProductRepository { private readonly ShopOnlineDbContext shopOnlineDbContext; public ProductRepository(ShopOnlineDbContext shopOnlineDbContext) { this.shopOnlineDbContext = shopOnlineDbContext; } public async Task> GetCategories() { var categories = await this.shopOnlineDbContext.ProductCategories.ToListAsync(); return categories; } public async Task GetCategory(int id) { var category = await shopOnlineDbContext.ProductCategories.SingleOrDefaultAsync(c => c.Id == id); return category; } public async Task GetItem(int id) { var product = await shopOnlineDbContext.Products.FindAsync(id); return product; } public async Task> GetItems() { var products = await this.shopOnlineDbContext.Products.ToListAsync(); return products; } } }