Sky.Net/Infrastructure/Data/ProductRepository.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2022-05-09 17:07:59 -07:00
using Core.Entities;
using Core.Interfaces;
using Microsoft.EntityFrameworkCore;
2022-05-09 18:31:09 -07:00
namespace Infrastructure.Data
2022-05-09 17:07:59 -07:00
{
public class ProductRepository : iProductRepository
{
private readonly StoreContext _context;
public ProductRepository(StoreContext context)
{
_context = context;
}
2022-05-10 10:26:43 -07:00
public async Task<IReadOnlyList<ProductBrand>> GetProductBrandsAsync()
{
return await _context.ProductBrands.ToListAsync();
}
2022-05-09 17:07:59 -07:00
public async Task<Product> GetProductByIdAsync(int id)
{
2022-05-10 10:26:43 -07:00
return await _context.Products
.Include(p => p.ProductType)
.Include(p => p.ProductBrand)
.FirstOrDefaultAsync(p => p.Id == id);
2022-05-09 17:07:59 -07:00
}
public async Task<IReadOnlyList<Product>> GetProductsAync()
{
2022-05-10 10:26:43 -07:00
return await _context.Products
.Include(p => p.ProductType)
.Include(p => p.ProductBrand)
.ToListAsync();
}
public async Task<IReadOnlyList<ProductType>> GetProductTypesAsync()
{
return await _context.ProductTypes.ToListAsync();
2022-05-09 17:07:59 -07:00
}
}
}