forked from sanchezvem/PyroFetes
35 lines
851 B
C#
35 lines
851 B
C#
using API.DTO.Brand.Response;
|
|
using FastEndpoints;
|
|
using PyroFetes.DTO.Brand.Request;
|
|
|
|
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);
|
|
}
|
|
} |