forked from sanchezvem/PyroFetes
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			845 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			845 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using API.DTO.Brand.Request;
 | |
| using API.DTO.Brand.Response;
 | |
| using FastEndpoints;
 | |
| 
 | |
| namespace PyroFetes.Endpoints.Brand;
 | |
| 
 | |
| public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateBrandDto, GetBrandDto>
 | |
| {
 | |
|     public override void Configure()
 | |
|     {
 | |
|         Post("/api/brands");
 | |
|         AllowAnonymous();
 | |
|     }
 | |
| 
 | |
|     public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct)
 | |
|     {
 | |
|         
 | |
|         Models.Brand brand = new ()
 | |
|         {
 | |
|             Name = req.Name
 | |
|         };
 | |
|         
 | |
|         pyrofetesdbcontext.Brands.Add(brand);
 | |
|         await pyrofetesdbcontext.SaveChangesAsync(ct);
 | |
|         
 | |
|         Console.WriteLine("Marque créé avec succès !");
 | |
| 
 | |
|         GetBrandDto responseDto = new ()
 | |
|         {
 | |
|             Name = req.Name
 | |
|         };
 | |
| 
 | |
|         await Send.OkAsync(responseDto, ct);
 | |
|     }
 | |
| } |