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