42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.Contact.Request;
|
|
using PyroFetes.DTO.Contact.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Contact;
|
|
|
|
public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateContactDto, GetContactDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/contacts");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
|
|
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
|
|
{
|
|
Models.Contact contact = new()
|
|
{
|
|
LastName = req.LastName,
|
|
FirstName = req.FirstName,
|
|
PhoneNumber = req.PhoneNumber,
|
|
Email = req.Email,
|
|
Address = req.Address,
|
|
Role = req.Role,
|
|
};
|
|
pyroFetesDbContext.Add(contact);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
GetContactDto response = new()
|
|
{
|
|
LastName = contact.LastName,
|
|
FirstName = contact.FirstName,
|
|
PhoneNumber = contact.PhoneNumber,
|
|
Email = contact.Email,
|
|
Address = contact.Address,
|
|
Role = contact.Role,
|
|
};
|
|
|
|
await Send.OkAsync(response, ct);
|
|
}
|
|
} |