forked from sanchezvem/PyroFetes
MaJ des .txt en .cs
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using API.DTO.Material.Request;
|
||||
using API.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
namespace API.Endpoints.Material;
|
||||
|
||||
public class CreateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -15,20 +16,20 @@ public class CreateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Create
|
||||
{
|
||||
Models.Material quantity = new()
|
||||
{
|
||||
Name = req.Name,
|
||||
Name = req.Label,
|
||||
Quantity = req.Quantity,
|
||||
WarehouseId = req.WarehouseId,
|
||||
};
|
||||
|
||||
appDbContext.Materials.Add(quantity);
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
pyrofetesdbcontext.Materials.Add(quantity);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
Console.WriteLine("Material added");
|
||||
|
||||
GetMaterialDto responseDto = new()
|
||||
{
|
||||
Id = quantity.Id,
|
||||
WarehouseId = quantity.WarehouseId,
|
||||
Name = req.Name,
|
||||
Label = req.Label,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
@@ -1,12 +1,12 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Endpoints.Material;
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
public class DeleteMaterialRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
public class DeleteMaterialEndpoint(AppDbContext appDbContext) : Endpoint<DeleteMaterialRequest>
|
||||
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -16,7 +16,7 @@ public class DeleteMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Delete
|
||||
|
||||
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
|
||||
{
|
||||
Models.Material? materialToDelete = await appDbContext
|
||||
Models.Material? materialToDelete = await pyrofetesdbcontext
|
||||
.Materials
|
||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
@@ -27,8 +27,8 @@ public class DeleteMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Delete
|
||||
return;
|
||||
}
|
||||
|
||||
appDbContext.Materials.Remove(materialToDelete);
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
pyrofetesdbcontext.Materials.Remove(materialToDelete);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
@@ -2,9 +2,9 @@ using API.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Endpoints.Material;
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class GetAllMaterialsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetMaterialDto>>
|
||||
public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMaterialDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -14,11 +14,11 @@ public class GetAllMaterialsEndpoint(AppDbContext appDbContext) : EndpointWithou
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetMaterialDto> responseDto = await appDbContext.Materials
|
||||
List<GetMaterialDto> responseDto = await pyrofetesdbcontext.Materials
|
||||
.Select(a => new GetMaterialDto
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
Label = a.Name,
|
||||
Quantity = a.Quantity,
|
||||
WarehouseId = a.WarehouseId,
|
||||
}
|
@@ -1,16 +1,15 @@
|
||||
using API.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Endpoints.Material;
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class GetMaterialRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint<GetMaterialRequest, GetMaterialDto>
|
||||
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -20,7 +19,7 @@ public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint<GetMateri
|
||||
|
||||
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
|
||||
{
|
||||
Models.Material? material = await appDbContext
|
||||
Models.Material? material = await pyrofetesdbcontext
|
||||
.Materials
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
@@ -34,7 +33,7 @@ public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint<GetMateri
|
||||
GetMaterialDto responseDto = new()
|
||||
{
|
||||
Id = material.Id,
|
||||
Name = material.Name,
|
||||
Label = material.Name,
|
||||
WarehouseId = material.WarehouseId,
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
@@ -1,12 +1,11 @@
|
||||
using API.DTO.Material.Request;
|
||||
using API.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.AspNetCore.Server.Kestrel;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Endpoints.Material;
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class UpdateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
|
||||
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -16,7 +15,7 @@ public class UpdateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Update
|
||||
|
||||
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Material? materialToEdit = await appDbContext
|
||||
Models.Material? materialToEdit = await pyrofetesdbcontext
|
||||
.Materials
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
@@ -27,14 +26,14 @@ public class UpdateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Update
|
||||
return;
|
||||
|
||||
}
|
||||
materialToEdit.Name = req.Name;
|
||||
materialToEdit.Name = req.Label;
|
||||
materialToEdit.WarehouseId = req.WarehouseId;
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
|
||||
GetMaterialDto responseDto = new()
|
||||
{
|
||||
Id = req.Id,
|
||||
Name = req.Name,
|
||||
Label = req.Label,
|
||||
WarehouseId = req.WarehouseId,
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
Reference in New Issue
Block a user