forked from sanchezvem/PyroFetes
MaJ des .txt en .cs
This commit is contained in:
37
PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using API.DTO.Material.Request;
|
||||
using API.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/material/create");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Material quantity = new()
|
||||
{
|
||||
Name = req.Label,
|
||||
Quantity = req.Quantity,
|
||||
WarehouseId = req.WarehouseId,
|
||||
};
|
||||
|
||||
pyrofetesdbcontext.Materials.Add(quantity);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
Console.WriteLine("Material added");
|
||||
|
||||
GetMaterialDto responseDto = new()
|
||||
{
|
||||
Id = quantity.Id,
|
||||
WarehouseId = quantity.WarehouseId,
|
||||
Label = req.Label,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user