contact updated

This commit is contained in:
2025-12-04 17:45:06 +01:00
parent 2b4b2b50df
commit 0beb5f3446
8 changed files with 53 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Customer.Request;
using PyroFetes.DTO.Customer.Response;
@@ -15,9 +16,20 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
public override async Task HandleAsync(CreateCustomerDto req, CancellationToken ct)
{
var customer = new Models.Customer
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.CustomerTypeId, cancellationToken: ct);
if (databaseCustomerType == null)
{
Note = req.Note
await Send.NotFoundAsync(ct);
Console.WriteLine("Customer Type not found");
return;
}
Models.Customer customer = new()
{
Note = req.Note,
CustomerTypeId = databaseCustomerType.Id,
};
pyroFetesDbContext.Add(customer);
await pyroFetesDbContext.SaveChangesAsync(ct);
@@ -25,7 +37,8 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
GetCustomerDto response = new GetCustomerDto()
{
Id = customer.Id,
Note = customer.Note
Note = customer.Note,
CustomerTypeId = customer.CustomerTypeId
};
await Send.OkAsync(response, ct);