using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Provider.Request; using PyroFetes.DTO.Provider.Response; namespace PyroFetes.Endpoints.Provider; public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { Post("/serviceproviders"); AllowAnonymous(); } public override async Task HandleAsync(CreateProviderDto req, CancellationToken ct) { Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.ProviderTypeId, cancellationToken: ct); if (databaseProviderType == null) { await Send.NotFoundAsync(ct); Console.WriteLine("Customer Type not found"); return; } Models.ServiceProvider provider = new() { Price = req.Price, ProviderTypeId = req.ProviderTypeId }; pyroFetesDbContext.Add(provider); await pyroFetesDbContext.SaveChangesAsync(ct); GetProviderDto response = new GetProviderDto() { Id = provider.Id, Price = provider.Price, ProviderTypeId = provider.ProviderTypeId }; await Send.OkAsync(response, ct); } }