Files
AP-WEB-PF3/PF3/Endpoint/Show/CreateShowEndpoint.cs

42 lines
1.1 KiB
C#

using FastEndpoints;
using PF3.DTO.Show.Request;
using PF3.DTO.Show.Response;
using PF3.Migrations;
using PyroFetes;
namespace PF3.Endpoint.Show;
public class CreateShowEndpoint(PyroFetesDbContext pyroFetesDbContext):Endpoint<CreateShowDto, ReadShowDto>
{
public override void Configure()
{
Post("/api/show");
AllowAnonymous();
}
public override async Task HandleAsync(CreateShowDto req, CancellationToken ct)
{
var show = new Models.Show
{
Name = req.Name,
Place = req.Place,
Description = req.Description,
Date = req.Date,
PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan
};
pyroFetesDbContext.Shows.Add(show);
await pyroFetesDbContext.SaveChangesAsync(ct);
ReadShowDto readShowDto = new ReadShowDto()
{
Id = show.Id,
Name = show.Name,
Place = show.Place,
Description = show.Description,
PyrotechnicImplementationPlan = show.PyrotechnicImplementationPlan
};
await Send.OkAsync(readShowDto, ct);
}
}