forked from sanchezvem/PyroFetes
36 lines
1005 B
C#
36 lines
1005 B
C#
using PyroFetes.DTO.Material.Request;
|
|
using PyroFetes.DTO.Material.Response;
|
|
using FastEndpoints;
|
|
namespace PyroFetes.Endpoints.Material;
|
|
|
|
public class CreateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/material/create");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
|
{
|
|
Models.Material material = new()
|
|
{
|
|
Label = req.Label,
|
|
Quantity = req.Quantity,
|
|
WarehouseId = req.WarehouseId,
|
|
};
|
|
|
|
appDbContext.Materials.Add(material);
|
|
await appDbContext.SaveChangesAsync(ct);
|
|
Console.WriteLine("Material added");
|
|
|
|
GetMaterialDto responseDto = new()
|
|
{
|
|
Id = material.Id,
|
|
WarehouseId = material.WarehouseId,
|
|
Label = req.Label,
|
|
};
|
|
|
|
await Send.OkAsync(responseDto, ct);
|
|
}
|
|
} |