29 lines
740 B
C#
29 lines
740 B
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PF3.DTO.Staff.Request;
|
|
|
|
namespace PF3.Endpoints.Staff;
|
|
|
|
public class DeleteStaffEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdStaffDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Delete("/api/staff/{Id}");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(IdStaffDto req, CancellationToken ct)
|
|
{
|
|
var staff = await pf3DbContext.Staffs.FirstOrDefaultAsync(s => s.Id == req.Id, ct);
|
|
if (staff is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
pf3DbContext.Staffs.Remove(staff);
|
|
await pf3DbContext.SaveChangesAsync(ct);
|
|
|
|
await Send.OkAsync(ct);
|
|
}
|
|
} |