using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Brand; public class DeleteBrandRequest { public int Id { get; set; } } public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { public override void Configure() { Delete("/api/brands/{@id}", x => new { x.Id }); AllowAnonymous(); } public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct) { Models.Brand? brandToDelete = await pyrofetesdbcontext .Brands .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); if (brandToDelete == null) { Console.WriteLine($"Aucune marque avec l'ID {req.Id} trouvé."); await Send.NotFoundAsync(ct); return; } pyrofetesdbcontext.Brands.Remove(brandToDelete); await pyrofetesdbcontext.SaveChangesAsync(ct); await Send.NoContentAsync(ct); } }