Refactored Program.cs
This commit is contained in:
@@ -29,9 +29,10 @@ public class CreatePurchaseProductEndpoint(
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
|
||||
|
||||
|
||||
PurchaseOrder? purchaseOrder =
|
||||
await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
purchaseOrder = new PurchaseOrder()
|
||||
@@ -40,16 +41,16 @@ public class CreatePurchaseProductEndpoint(
|
||||
};
|
||||
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
|
||||
}
|
||||
|
||||
|
||||
PurchaseProduct purchaseProduct = new PurchaseProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
PurchaseOrderId = purchaseOrder.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
|
||||
|
||||
await purchaseProductsRepository.AddAsync(purchaseProduct, ct);
|
||||
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using FastEndpoints;
|
||||
using FastEndpoints.Swagger;
|
||||
using FastEndpoints.Security;
|
||||
using PyroFetes.MappingProfiles;
|
||||
using IMapper = FastEndpoints.IMapper;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -19,6 +19,17 @@ builder.Services
|
||||
// On ajoute ici la configuration de la base de données
|
||||
builder.Services.AddDbContext<PyroFetesDbContext>();
|
||||
|
||||
builder.Services.AddScoped<DeliverersRepository>();
|
||||
builder.Services.AddScoped<DeliveryNotesRepository>();
|
||||
builder.Services.AddScoped<PricesRepository>();
|
||||
builder.Services.AddScoped<ProductDeliveriesRepository>();
|
||||
builder.Services.AddScoped<ProductsRepository>();
|
||||
builder.Services.AddScoped<PurchaseOrdersRepository>();
|
||||
builder.Services.AddScoped<PurchaseProductsRepository>();
|
||||
builder.Services.AddScoped<QuotationProductsRepository>();
|
||||
builder.Services.AddScoped<QuotationsRepository>();
|
||||
builder.Services.AddScoped<SuppliersRepository>();
|
||||
builder.Services.AddScoped<SettingsRepository>();
|
||||
|
||||
MapperConfiguration mappingConfig = new(mc =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user