forked from sanchezvem/PyroFetes
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using FastEndpoints;
 | |
| using Microsoft.EntityFrameworkCore;
 | |
| 
 | |
| namespace PyroFetes.Endpoints.Warehouse;
 | |
| 
 | |
| public class DeleteWarehouseRequest
 | |
| {
 | |
|     public int Id { get; set; }
 | |
| }
 | |
| 
 | |
| public class DeleteWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteWarehouseRequest>
 | |
| {
 | |
|     public override void Configure()
 | |
|     {
 | |
|         Delete("/api/warehouse/{@id}", x => new { x.Id });
 | |
|         AllowAnonymous();
 | |
|     }
 | |
|     
 | |
|     public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)
 | |
|     {
 | |
|         Models.Warehouse? warehouseToDelete = await pyrofetesdbcontext
 | |
|             .Warehouses
 | |
|             .SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
 | |
| 
 | |
|         if (warehouseToDelete == null)
 | |
|         {
 | |
|             Console.WriteLine($"Aucun entrepôt avec l'ID {req.Id} trouvé.");
 | |
|             await Send.NotFoundAsync(ct);
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         pyrofetesdbcontext.Warehouses.Remove(warehouseToDelete);
 | |
|         await pyrofetesdbcontext.SaveChangesAsync(ct);
 | |
| 
 | |
|         await Send.NoContentAsync(ct);
 | |
|     }
 | |
| } |