41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes.DTO.HistoryOfApproval.Request;
|
|
using PyroFetes.DTO.HistoryOfApproval.Response;
|
|
|
|
namespace PyroFetes.Endpoints.HistoryOfApproval;
|
|
|
|
public class UpdateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateHistoryOfApprovalDto, GetHistoryOfApprovalDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Put ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(UpdateHistoryOfApprovalDto req, CancellationToken ct)
|
|
{
|
|
Models.HistoryOfApproval? databaseHistoryOfApproval = await pyroFetesDbContext.HistoryOfApprovals.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
|
|
if (databaseHistoryOfApproval == null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
databaseHistoryOfApproval.DeliveryDate = req.DeliveryDate;
|
|
databaseHistoryOfApproval.ExpirationDate = req.ExpirationDate;
|
|
}
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
GetHistoryOfApprovalDto dto = new()
|
|
{
|
|
Id = databaseHistoryOfApproval.Id,
|
|
DeliveryDate = req.DeliveryDate,
|
|
ExpirationDate = req.ExpirationDate
|
|
};
|
|
|
|
await Send.OkAsync(dto, ct);
|
|
}
|
|
} |