Added Brand and Types to Controller

This commit is contained in:
Charles Showalter 2022-05-10 10:26:43 -07:00
parent f185ef9163
commit 7601a394b4
4 changed files with 34 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
obj
bin
appsettings.json
*.db
*.db*

View File

@ -27,5 +27,18 @@ namespace API.Controllers
{
return await _repo.GetProductByIdAsync(id);
}
[HttpGet("brands")]
public async Task<ActionResult<IReadOnlyList<ProductBrand>>> GetProductBrands()
{
return Ok(await _repo.GetProductBrandsAsync());
}
[HttpGet("types")]
public async Task<ActionResult<IReadOnlyList<ProductType>>> GetProductTypes()
{
return Ok(await _repo.GetProductTypesAsync());
}
}
}

View File

@ -6,5 +6,7 @@ namespace Core.Interfaces
{
Task<Product> GetProductByIdAsync(int id);
Task<IReadOnlyList<Product>> GetProductsAync();
Task<IReadOnlyList<ProductBrand>> GetProductBrandsAsync();
Task<IReadOnlyList<ProductType>> GetProductTypesAsync();
}
}

View File

@ -12,14 +12,30 @@ namespace Infrastructure.Data
_context = context;
}
public async Task<IReadOnlyList<ProductBrand>> GetProductBrandsAsync()
{
return await _context.ProductBrands.ToListAsync();
}
public async Task<Product> GetProductByIdAsync(int id)
{
return await _context.Products.FindAsync(id);
return await _context.Products
.Include(p => p.ProductType)
.Include(p => p.ProductBrand)
.FirstOrDefaultAsync(p => p.Id == id);
}
public async Task<IReadOnlyList<Product>> GetProductsAync()
{
return await _context.Products.ToListAsync();
return await _context.Products
.Include(p => p.ProductType)
.Include(p => p.ProductBrand)
.ToListAsync();
}
public async Task<IReadOnlyList<ProductType>> GetProductTypesAsync()
{
return await _context.ProductTypes.ToListAsync();
}
}
}