drinkrate/DrinkRateAPI/Services/ProductTableService.cs

27 lines
No EOL
850 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();
return new ProductTableGet
{
ProductTableName = productTable.ProductTableName,
ProductTableId = productTable.Id.ToString(),
CompanyTableId = productTable.CompanyTableId.ToString(),
};
}
}