contact updated
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user