27 lines
No EOL
902 B
C#
27 lines
No EOL
902 B
C#
using DrinkRateAPI.ApiModels.ProductTable;
|
|
using DrinkRateAPI.Contexts;
|
|
using DrinkRateAPI.DbEntities;
|
|
using DrinkRateAPI.Exceptions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DrinkRateAPI.Services;
|
|
|
|
public class ProductTableService(ApplicationDbContext context)
|
|
{
|
|
private ApplicationDbContext _context = context;
|
|
|
|
|
|
public async Task<ProductTableGet> GetProductTable(string productTableName)
|
|
{
|
|
var productTable =
|
|
await _context.ProductTable.FirstOrDefaultAsync(x => x.ProductTableName == productTableName) ??
|
|
throw new NotFoundException($"Product table with the name {productTableName} not found.");
|
|
|
|
return new ProductTableGet
|
|
{
|
|
ProductTableName = productTable.ProductTableName,
|
|
ProductTableId = productTable.Id.ToString(),
|
|
CompanyTableId = productTable.CompanyTableId.ToString(),
|
|
};
|
|
}
|
|
} |