First Commit 09/10
# Conflicts: # PyroFetes/PyroFetes.csproj
This commit is contained in:
42
PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs
Normal file
42
PyroFetes/Endpoints/Contact/CreateContactEndpoint.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user