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.Contact.Request;
using PyroFetes.DTO.Contact.Response;
@@ -15,6 +16,15 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
{
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.CustomerId, cancellationToken: ct);
if (databaseCustomer == null)
{
await Send.NotFoundAsync(ct);
Console.WriteLine("Customer not found");
return;
}
Models.Contact contact = new()
{
LastName = req.LastName,
@@ -22,7 +32,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
PhoneNumber = req.PhoneNumber,
Email = req.Email,
Address = req.Address,
City = req.City,
Role = req.Role,
CustomerId = databaseCustomer.Id,
};
pyroFetesDbContext.Add(contact);
await pyroFetesDbContext.SaveChangesAsync(ct);
@@ -34,7 +46,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
PhoneNumber = contact.PhoneNumber,
Email = contact.Email,
Address = contact.Address,
City = contact.City,
Role = contact.Role,
CustomerId = contact.CustomerId,
};
await Send.OkAsync(response, ct);

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);