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 PostProductTableAsync(ProductTablePost productTablePost) { DbProductTable productTable = new() { ProductTableName = productTablePost.ProductTableName }; _context.ProductTable.Add(productTable); await _context.SaveChangesAsync(); var productTableGet = await GetProductTable(productTable.ProductTableName); return productTableGet; } public async Task 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() }; } }