Compare commits
36 Commits
c0090da9bd
...
60a7c059b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60a7c059b4 | ||
|
|
9684dbcbc7 | ||
| bbd8d3d36a | |||
| 7d92f80de3 | |||
| 304c06ed19 | |||
| 97a7c6811c | |||
| f8b3c51435 | |||
| a535f8cfeb | |||
| 65b5e6afe3 | |||
| 33719b708e | |||
| b00ed36557 | |||
| be0a6a4004 | |||
|
|
6bc8281a37 | ||
|
|
9ff5c038b1 | ||
|
|
4bdd8104d8 | ||
|
|
abc843778f | ||
| 1c898f9144 | |||
| 7bb21be0e6 | |||
| 6a4760fb72 | |||
| 06c64a9f3f | |||
| aa1c98d649 | |||
| fa72c6d777 | |||
| 59628717d4 | |||
| ff590302e2 | |||
| 45f6baaac3 | |||
| ef9740d8ff | |||
| 3ada21adae | |||
| 4f12911263 | |||
| 8bd7fadabc | |||
| e4e6c1c3f7 | |||
| 791eff9256 | |||
| b4502ae562 | |||
| 347003c24a | |||
| 31e69aae1a | |||
| 74b5fa6666 | |||
| b79e07dd8b |
@@ -8,5 +8,4 @@ public class CreateDeliveryNoteDto
|
||||
public DateOnly RealDeliveryDate { get; set; }
|
||||
|
||||
public int DelivererId { get; set; }
|
||||
|
||||
}
|
||||
@@ -4,5 +4,4 @@ public class PatchDeliveryNoteRealDeliveryDateDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateOnly RealDeliveryDate { get; set; }
|
||||
|
||||
}
|
||||
@@ -9,5 +9,4 @@ public class UpdateDeliveryNoteDto
|
||||
public DateOnly? RealDeliveryDate { get; set; }
|
||||
|
||||
public int DelivererId { get; set; }
|
||||
|
||||
}
|
||||
@@ -13,5 +13,5 @@ public class GetDeliveryNoteDto
|
||||
public int DelivererId { get; set; }
|
||||
public string? DelivererTransporter { get; set; }
|
||||
|
||||
public List<GetProductDeliveryDto> Products { get; set; }
|
||||
public List<GetProductDeliveryDto>? Products { get; set; }
|
||||
}
|
||||
@@ -4,7 +4,7 @@ public class CreatePriceDto
|
||||
{
|
||||
public decimal SellingPrice { get; set; }
|
||||
|
||||
public int SupplierId { get; set; }
|
||||
public int? SupplierId { get; set; }
|
||||
public string? SupplierName { get; set; }
|
||||
public string? SupplierEmail { get; set; }
|
||||
public string? SupplierPhone { get; set; }
|
||||
@@ -13,8 +13,8 @@ public class CreatePriceDto
|
||||
public string? SupplierCity { get; set; }
|
||||
public int SupplierDeliveryDelay { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public int? ProductId { get; set; }
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
public class PatchPriceSellingPriceDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
public decimal SellingPrice { get; set; }
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class UpdatePriceDto
|
||||
public int SupplierDeliveryDelay { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GetPriceDto
|
||||
public int SupplierDeliveryDelay { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace PyroFetes.DTO.Product.Request;
|
||||
|
||||
public class CreateProductDto
|
||||
{
|
||||
public int References { get; set; }
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Request;
|
||||
public class UpdateProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int References { get; set; }
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Response;
|
||||
public class GetProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int References { get; set; }
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.PurchaseOrder.Request;
|
||||
|
||||
public class PatchPurchaseOrderPurchaseConditionsDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? PurchaseConditions { get; set; }
|
||||
}
|
||||
10
PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs
Normal file
10
PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.DTO.PurchaseOrder.Response;
|
||||
|
||||
public class GetPurchaseOrderDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? PurchaseConditions { get; set; }
|
||||
public List<GetPurchaseProductDto>? GetPurchaseProductDto { get; set; }
|
||||
}
|
||||
@@ -3,20 +3,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request;
|
||||
public class CreatePurchaseProductDto
|
||||
{
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
|
||||
|
||||
public int PurchaseOrderId { get; set; }
|
||||
public string? PurchaseOrderPurchaseConditions { get; set; }
|
||||
}
|
||||
@@ -2,6 +2,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request;
|
||||
|
||||
public class PatchPurchaseProductQuantityDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
@@ -2,10 +2,11 @@ namespace PyroFetes.DTO.PurchaseProduct.Request;
|
||||
|
||||
public class UpdatePurchaseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
@@ -17,7 +18,5 @@ public class UpdatePurchaseProductDto
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
|
||||
|
||||
public int PurchaseOrderId { get; set; }
|
||||
public string? PurchaseOrderPurchaseConditions { get; set; }
|
||||
}
|
||||
@@ -2,23 +2,20 @@ namespace PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
public class GetPurchaseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public decimal ProductSellingPrice { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
|
||||
|
||||
public int PurchaseOrderId { get; set; }
|
||||
public string? PurchaseOrderPurchaseConditions { get; set; }
|
||||
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.Quotation.Request;
|
||||
|
||||
public class PatchQuotationConditionsSaleDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? ConditionsSale { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.Quotation.Request;
|
||||
|
||||
public class PatchQuotationMessageDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
11
PyroFetes/DTO/Quotation/Response/GetQuotationDto.cs
Normal file
11
PyroFetes/DTO/Quotation/Response/GetQuotationDto.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.DTO.Quotation.Response;
|
||||
|
||||
public class GetQuotationDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public string? ConditionsSale { get; set; }
|
||||
public List<GetQuotationProductDto>? GetQuotationProductDto { get; set; }
|
||||
}
|
||||
@@ -2,6 +2,7 @@ namespace PyroFetes.DTO.QuotationProduct.Request;
|
||||
|
||||
public class PatchQuotationProductQuantityDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int QuotationId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
@@ -2,7 +2,6 @@ namespace PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
public class GetQuotationProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int QuotationId { get; set; }
|
||||
@@ -10,7 +9,7 @@ public class GetQuotationProductDto
|
||||
public string? QuotationConditionsSale { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
|
||||
7
PyroFetes/DTO/User/Request/ConnectUserDto.cs
Normal file
7
PyroFetes/DTO/User/Request/ConnectUserDto.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.User.Request;
|
||||
|
||||
public class ConnectUserDto
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
@@ -4,7 +4,6 @@ public class CreateUserDto
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string? Salt { get; set; }
|
||||
public string? Fonction { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
7
PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs
Normal file
7
PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.User.Request;
|
||||
|
||||
public class PatchUserPasswordDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
6
PyroFetes/DTO/User/Response/GetTokenDto.cs
Normal file
6
PyroFetes/DTO/User/Response/GetTokenDto.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace PyroFetes.DTO.User.Response;
|
||||
|
||||
public class GetTokenDto
|
||||
{
|
||||
public string? Token { get; set; }
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class CreateWareHouseProductDto
|
||||
{
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
||||
@@ -2,6 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class PatchWareHouseProductQuantityDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WareHouseId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class UpdateWareHouseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
public class GetTotalQuantityDto
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int TotalQuantity { get; set; }
|
||||
}
|
||||
@@ -2,27 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
public class GetWareHouseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,9 @@ using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
public class CreateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||
public class CreateDelivererEndpoint(
|
||||
PyroFetesDbContext database,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -20,15 +22,11 @@ public class CreateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<Cre
|
||||
{
|
||||
Transporter = req.Transporter,
|
||||
};
|
||||
|
||||
|
||||
database.Deliverers.Add(newDeliverer);
|
||||
|
||||
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(new GetDelivererDto()
|
||||
{
|
||||
Id = newDeliverer.Id,
|
||||
Transporter = req.Transporter,
|
||||
},ct);
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DeleteDelivererEndpoint(PyroFetesDbContext database) : Endpoint<Del
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("api/deliverers/{id}", x=>new {x.DelivererId});
|
||||
Delete("api/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@ public class GetDelivererRequest
|
||||
public int DelivererId { get; set; }
|
||||
}
|
||||
|
||||
public class GetDelivererEndpoint(PyroFetesDbContext database) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||
public class GetDelivererEndpoint(
|
||||
PyroFetesDbContext database,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/deliverers/{id}", x=>new {x.DelivererId});
|
||||
Get("api/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
@@ -29,11 +31,7 @@ public class GetDelivererEndpoint(PyroFetesDbContext database) : Endpoint<GetDel
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(new GetDelivererDto()
|
||||
{
|
||||
Id = deliverer.Id,
|
||||
Transporter = deliverer.Transporter,
|
||||
}, ct);
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,11 +6,13 @@ using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
public class UpdateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||
public class UpdateDelivererEndpoint(
|
||||
PyroFetesDbContext database,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("api/deliverers/{id}", x=>new {x.Id});
|
||||
Put("api/deliverers/{@id}", x=>new {x.Id});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
@@ -29,11 +31,7 @@ public class UpdateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<Upd
|
||||
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(new GetDelivererDto()
|
||||
{
|
||||
Id = deliverer.Id,
|
||||
Transporter = deliverer.Transporter,
|
||||
}, ct);
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||
}
|
||||
|
||||
}
|
||||
104
PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs
Normal file
104
PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Price;
|
||||
|
||||
public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint<CreatePriceDto, GetPriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/prices");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
|
||||
{
|
||||
// Gestion du fournisseur
|
||||
var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct);
|
||||
if (supplier == null)
|
||||
{
|
||||
supplier = new Models.Supplier()
|
||||
{
|
||||
Name = req.SupplierName,
|
||||
Email = req.SupplierEmail,
|
||||
Phone = req.SupplierPhone,
|
||||
Address = req.SupplierAddress,
|
||||
City = req.SupplierCity,
|
||||
ZipCode = req.SupplierZipCode,
|
||||
DeliveryDelay = req.SupplierDeliveryDelay
|
||||
};
|
||||
database.Suppliers.Add(supplier);
|
||||
await database.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
// Gestion du produit
|
||||
var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
||||
if (product == null)
|
||||
{
|
||||
product = new Models.Product()
|
||||
{
|
||||
Reference = req.ProductReferences,
|
||||
Name = req.ProductName,
|
||||
Duration = req.ProductDuration,
|
||||
Caliber = req.ProductCaliber,
|
||||
ApprovalNumber = req.ProductApprovalNumber,
|
||||
Weight = req.ProductWeight,
|
||||
Nec = req.ProductNec,
|
||||
Image = req.ProductImage,
|
||||
Link = req.ProductLink,
|
||||
MinimalQuantity = req.ProductMinimalQuantity
|
||||
};
|
||||
database.Products.Add(product);
|
||||
await database.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
// Vérifie si le prix existe déjà pour ce fournisseur et produit
|
||||
var existingPrice = await database.Prices
|
||||
.SingleOrDefaultAsync(p => p.ProductId == product.Id && p.SupplierId == supplier.Id, ct);
|
||||
|
||||
if (existingPrice != null)
|
||||
{
|
||||
await Send.ConflictAsync("Le fournisseur a déjà un prix pour ce produit.", ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// Création du prix
|
||||
var priceAdded = new Models.Price()
|
||||
{
|
||||
SellingPrice = req.SellingPrice,
|
||||
SupplierId = supplier.Id,
|
||||
ProductId = product.Id
|
||||
};
|
||||
database.Prices.Add(priceAdded);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
// Création du DTO de réponse
|
||||
var responseDto = new GetPriceDto()
|
||||
{
|
||||
SellingPrice = priceAdded.SellingPrice,
|
||||
SupplierId = supplier.Id,
|
||||
ProductId = product.Id,
|
||||
SupplierName = supplier.Name,
|
||||
SupplierEmail = supplier.Email,
|
||||
SupplierPhone = supplier.Phone,
|
||||
SupplierAddress = supplier.Address,
|
||||
SupplierCity = supplier.City,
|
||||
SupplierZipCode = supplier.ZipCode,
|
||||
SupplierDeliveryDelay = supplier.DeliveryDelay,
|
||||
ProductReferences = product.Reference,
|
||||
ProductName = product.Name,
|
||||
ProductDuration = product.Duration,
|
||||
ProductCaliber = product.Caliber,
|
||||
ProductApprovalNumber = product.ApprovalNumber,
|
||||
ProductWeight = product.Weight,
|
||||
ProductNec = product.Nec,
|
||||
ProductImage = product.Image,
|
||||
ProductLink = product.Link,
|
||||
ProductMinimalQuantity = product.MinimalQuantity
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
36
PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class DeletePriceRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint<DeletePriceRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
|
||||
{
|
||||
var price = await database.Prices
|
||||
.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct);
|
||||
|
||||
if (price == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Prices.Remove(price);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
36
PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Price;
|
||||
|
||||
public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct)
|
||||
{
|
||||
var price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct);
|
||||
if (price == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
price.SellingPrice = req.SellingPrice;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetPriceDto responseDto = new()
|
||||
{
|
||||
ProductId = price.ProductId,
|
||||
SupplierId = price.SupplierId,
|
||||
SellingPrice = price.SellingPrice
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
36
PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Product;
|
||||
|
||||
public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetProductDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/products");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products
|
||||
.Select(product => new GetProductDto()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(product, ct);
|
||||
}
|
||||
}
|
||||
48
PyroFetes/Endpoints/Product/GetProductEndpoint.cs
Normal file
48
PyroFetes/Endpoints/Product/GetProductEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Product;
|
||||
|
||||
public class GetProductRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint<GetProductRequest, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/products/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Request;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Product;
|
||||
|
||||
public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database)
|
||||
: Endpoint<PatchProductMinimalStockDto, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
product.MinimalQuantity = req.MinimalQuantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
54
PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs
Normal file
54
PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Request;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Product;
|
||||
|
||||
public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint<UpdateProductDto, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/products/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
product.Reference = req.References;
|
||||
product.Name = req.Name;
|
||||
product.Duration = req.Duration;
|
||||
product.Caliber = req.Caliber;
|
||||
product.ApprovalNumber = req.ApprovalNumber;
|
||||
product.Weight = req.Weight;
|
||||
product.Nec = req.Nec;
|
||||
product.Image = req.Image;
|
||||
product.Link = req.Link;
|
||||
product.MinimalQuantity = req.MinimalQuantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class DeletePurchaseOrderRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.Include(po => po.PurchaseProducts)
|
||||
.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||
{
|
||||
database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts);
|
||||
}
|
||||
|
||||
database.PurchaseOrders.Remove(purchaseOrder);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.Include(p => p.PurchaseProducts)
|
||||
.Select(purchaseOrder => new GetPurchaseOrderDto()
|
||||
{
|
||||
Id = purchaseOrder.Id,
|
||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
||||
.Select(p => new GetPurchaseProductDto
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductReferences = p.Product.Reference,
|
||||
ProductName = p.Product.Name,
|
||||
ProductDuration = p.Product.Duration,
|
||||
ProductCaliber = p.Product.Caliber,
|
||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
||||
ProductWeight = p.Product.Weight,
|
||||
ProductNec = p.Product.Nec,
|
||||
ProductImage = p.Product.Image,
|
||||
ProductLink = p.Product.Link,
|
||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
||||
PurchaseOrderId = p.PurchaseOrderId,
|
||||
Quantity = p.Quantity,
|
||||
}).ToList()
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(purchaseOrder, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class GetPurchaseOrderRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetPurchaseOrderDto responseDto = new()
|
||||
{
|
||||
Id = purchaseOrder.Id,
|
||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
||||
.Select(p => new GetPurchaseProductDto
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductReferences = p.Product.Reference,
|
||||
ProductName = p.Product.Name,
|
||||
ProductDuration = p.Product.Duration,
|
||||
ProductCaliber = p.Product.Caliber,
|
||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
||||
ProductWeight = p.Product.Weight,
|
||||
ProductNec = p.Product.Nec,
|
||||
ProductImage = p.Product.Image,
|
||||
ProductLink = p.Product.Link,
|
||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
||||
PurchaseOrderId = p.PurchaseOrderId,
|
||||
Quantity = p.Quantity,
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetPurchaseOrderDto responseDto = new()
|
||||
{
|
||||
Id = purchaseOrder.Id,
|
||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
||||
.Select(p => new GetPurchaseProductDto
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductReferences = p.Product.Reference,
|
||||
ProductName = p.Product.Name,
|
||||
ProductDuration = p.Product.Duration,
|
||||
ProductCaliber = p.Product.Caliber,
|
||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
||||
ProductWeight = p.Product.Weight,
|
||||
ProductNec = p.Product.Nec,
|
||||
ProductImage = p.Product.Image,
|
||||
ProductLink = p.Product.Link,
|
||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
||||
PurchaseOrderId = p.PurchaseOrderId,
|
||||
Quantity = p.Quantity,
|
||||
}).ToList()
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/purchaseProducts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
purchaseOrder = new Models.PurchaseOrder()
|
||||
{
|
||||
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
|
||||
};
|
||||
database.PurchaseOrders.Add(purchaseOrder);
|
||||
await database.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
var purchaseProduct = new Models.PurchaseProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
PurchaseOrderId = purchaseOrder.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
database.PurchaseProducts.Add(purchaseProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
var responseDto = new GetPurchaseProductDto()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
ProductReferences = product.Reference,
|
||||
ProductName = product.Name,
|
||||
ProductDuration = product.Duration,
|
||||
ProductCaliber = product.Caliber,
|
||||
ProductApprovalNumber = product.ApprovalNumber,
|
||||
ProductWeight = product.Weight,
|
||||
ProductNec = product.Nec,
|
||||
ProductImage = product.Image,
|
||||
ProductLink = product.Link,
|
||||
ProductMinimalQuantity = product.MinimalQuantity,
|
||||
|
||||
PurchaseOrderId = purchaseOrder.Id,
|
||||
PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
Quantity = purchaseProduct.Quantity
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class DeletePurchaseProductRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseProduct = await database.PurchaseProducts
|
||||
.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
||||
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.PurchaseProducts.Remove(purchaseProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
var purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetPurchaseProductDto responseDto = new()
|
||||
{
|
||||
ProductId = purchaseProduct.ProductId,
|
||||
PurchaseOrderId = purchaseProduct.PurchaseOrderId,
|
||||
Quantity = purchaseProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
41
PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs
Normal file
41
PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotation;
|
||||
|
||||
public class DeleteQuotationRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/quotations/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
var quotation = await database.Quotations
|
||||
.Include(q => q.QuotationProducts)
|
||||
.SingleOrDefaultAsync(q => q.Id == req.Id, ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
|
||||
{
|
||||
database.QuotationProducts.RemoveRange(quotation.QuotationProducts);
|
||||
}
|
||||
|
||||
database.Quotations.Remove(quotation);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
48
PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs
Normal file
48
PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotation;
|
||||
|
||||
public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetQuotationDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/quotations");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var quotations = await database.Quotations
|
||||
.Include(q => q.QuotationProducts!)
|
||||
.ThenInclude(qp => qp.Product)
|
||||
.Select(q => new GetQuotationDto
|
||||
{
|
||||
Id = q.Id,
|
||||
Message = q.Message,
|
||||
ConditionsSale = q.ConditionsSale,
|
||||
GetQuotationProductDto = q.QuotationProducts.Select(qp => new GetQuotationProductDto
|
||||
{
|
||||
Quantity = qp.Quantity,
|
||||
QuotationId = q.Id,
|
||||
QuotationMessage = q.Message,
|
||||
QuotationConditionsSale = q.ConditionsSale,
|
||||
ProductId = qp.ProductId,
|
||||
ProductReferences = qp.Product.Reference,
|
||||
ProductName = qp.Product.Name,
|
||||
ProductDuration = qp.Product.Duration,
|
||||
ProductCaliber = qp.Product.Caliber,
|
||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
||||
ProductWeight = qp.Product.Weight,
|
||||
ProductNec = qp.Product.Nec,
|
||||
ProductImage = qp.Product.Image,
|
||||
ProductLink = qp.Product.Link,
|
||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
||||
}).ToList()
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(quotations, ct);
|
||||
}
|
||||
}
|
||||
59
PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
Normal file
59
PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotation;
|
||||
|
||||
public class GetQuotationRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/quotations/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
var quotation = await database.Quotations
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetQuotationDto responseDto = new()
|
||||
{
|
||||
Id = quotation.Id,
|
||||
Message = quotation.Message,
|
||||
ConditionsSale = quotation.ConditionsSale,
|
||||
GetQuotationProductDto = quotation.QuotationProducts
|
||||
.Select(qp => new GetQuotationProductDto
|
||||
{
|
||||
Quantity = qp.Quantity,
|
||||
QuotationId = quotation.Id,
|
||||
QuotationMessage = quotation.Message,
|
||||
QuotationConditionsSale = quotation.ConditionsSale,
|
||||
ProductId = qp.ProductId,
|
||||
ProductReferences = qp.Product.Reference,
|
||||
ProductName = qp.Product.Name,
|
||||
ProductDuration = qp.Product.Duration,
|
||||
ProductCaliber = qp.Product.Caliber,
|
||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
||||
ProductWeight = qp.Product.Weight,
|
||||
ProductNec = qp.Product.Nec,
|
||||
ProductImage = qp.Product.Image,
|
||||
ProductLink = qp.Product.Link,
|
||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotation;
|
||||
|
||||
public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
|
||||
{
|
||||
var quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
if (quotation == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
quotation.ConditionsSale = req.ConditionsSale;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetQuotationDto responseDto = new()
|
||||
{
|
||||
Id = quotation.Id,
|
||||
Message = quotation.Message,
|
||||
ConditionsSale = quotation.ConditionsSale,
|
||||
GetQuotationProductDto = quotation.QuotationProducts.Select(qp => new GetQuotationProductDto
|
||||
{
|
||||
Quantity = qp.Quantity,
|
||||
QuotationId = quotation.Id,
|
||||
QuotationMessage = quotation.Message,
|
||||
QuotationConditionsSale = quotation.ConditionsSale,
|
||||
ProductId = qp.ProductId,
|
||||
ProductReferences = qp.Product.Reference,
|
||||
ProductName = qp.Product.Name,
|
||||
ProductDuration = qp.Product.Duration,
|
||||
ProductCaliber = qp.Product.Caliber,
|
||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
||||
ProductWeight = qp.Product.Weight,
|
||||
ProductNec = qp.Product.Nec,
|
||||
ProductImage = qp.Product.Image,
|
||||
ProductLink = qp.Product.Link,
|
||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
||||
}).ToList()
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/quotationProduct");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
|
||||
{
|
||||
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
var quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
quotation = new Models.Quotation()
|
||||
{
|
||||
Message = req.QuotationMessage ?? "",
|
||||
ConditionsSale = req.QuotationConditionsSale,
|
||||
};
|
||||
database.Quotations.Add(quotation);
|
||||
await database.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
var quotationProduct = new Models.QuotationProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
QuotationId = quotation.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
database.QuotationProducts.Add(quotationProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
var responseDto = new GetQuotationProductDto()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
ProductReferences = product.Reference,
|
||||
ProductName = product.Name,
|
||||
ProductDuration = product.Duration,
|
||||
ProductCaliber = product.Caliber,
|
||||
ProductApprovalNumber = product.ApprovalNumber,
|
||||
ProductWeight = product.Weight,
|
||||
ProductNec = product.Nec,
|
||||
ProductImage = product.Image,
|
||||
ProductLink = product.Link,
|
||||
ProductMinimalQuantity = product.MinimalQuantity,
|
||||
Quantity = quotationProduct.Quantity,
|
||||
QuotationMessage = quotation.Message,
|
||||
QuotationConditionsSale = quotation.ConditionsSale,
|
||||
QuotationId = quotation.Id,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class DeleteQuotationProductRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int QuotationId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
|
||||
{
|
||||
var quotationProduct = await database.QuotationProducts
|
||||
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
||||
|
||||
if (quotationProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.QuotationProducts.Remove(quotationProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
var quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
||||
if (quotationProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
quotationProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetQuotationProductDto responseDto = new()
|
||||
{
|
||||
ProductId = quotationProduct.ProductId,
|
||||
QuotationId = quotationProduct.QuotationId,
|
||||
Quantity = quotationProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SettingEndpoints;
|
||||
|
||||
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/setting");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = new Models.Setting()
|
||||
{
|
||||
ElectronicSignature = req.ElectronicSignature,
|
||||
Logo = req.Logo
|
||||
};
|
||||
|
||||
database.Settings.Add(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.SettingEndpoints;
|
||||
|
||||
public class DeleteSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/setting/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Settings.Remove(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
38
PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs
Normal file
38
PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SettingEndpoints;
|
||||
|
||||
public class GetSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SettingEndpoints;
|
||||
|
||||
public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.ElectronicSignature = req.ElectronicSignature;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SettingEndpoints;
|
||||
|
||||
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}/Logo", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.Logo = req.Logo;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
43
PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs
Normal file
43
PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/suppliers");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
||||
{
|
||||
var supplier = new Models.Supplier()
|
||||
{
|
||||
Name = req.Name,
|
||||
Email = req.Email,
|
||||
Phone = req.Phone,
|
||||
Address = req.Address,
|
||||
City = req.City,
|
||||
ZipCode = req.ZipCode,
|
||||
DeliveryDelay = req.DeliveryDelay
|
||||
};
|
||||
|
||||
database.Suppliers.Add(supplier);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
33
PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs
Normal file
33
PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class DeleteSupplierRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSupplierRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Suppliers.Remove(supplier);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
32
PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs
Normal file
32
PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetSupplierDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/suppliers");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var supplier = await database.Suppliers
|
||||
.Select(supplier => new GetSupplierDto()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(supplier, ct);
|
||||
}
|
||||
}
|
||||
43
PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs
Normal file
43
PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class GetSupplierRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
var supplier = await database.Suppliers
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct)
|
||||
{
|
||||
var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
DeliveryDelay = supplier.DeliveryDelay,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
48
PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs
Normal file
48
PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Supplier;
|
||||
|
||||
public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
||||
{
|
||||
var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
supplier.Name = req.Name;
|
||||
supplier.Email = req.Email;
|
||||
supplier.Phone = req.Phone;
|
||||
supplier.Address = req.Address;
|
||||
supplier.City = req.City;
|
||||
supplier.ZipCode = req.ZipCode;
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
48
PyroFetes/Endpoints/User/ConnectUserEndpoint.cs
Normal file
48
PyroFetes/Endpoints/User/ConnectUserEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Security;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint<ConnectUserDto, GetTokenDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/users/connect");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await Send.UnauthorizedAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password))
|
||||
{
|
||||
var jwtToken = JwtBearer.CreateToken(
|
||||
o =>
|
||||
{
|
||||
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||
if (user.Fonction != null) o.User.Roles.Add(user.Fonction);
|
||||
o.User.Claims.Add(("Name", user.Name)!);
|
||||
o.User.Claims.Add(("Id", user.Id.ToString())!);
|
||||
});
|
||||
|
||||
GetTokenDto responseDto = new()
|
||||
{
|
||||
Token = jwtToken
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
else await Send.UnauthorizedAsync(ct);
|
||||
}
|
||||
}
|
||||
45
PyroFetes/Endpoints/User/CreateUserEndpoint.cs
Normal file
45
PyroFetes/Endpoints/User/CreateUserEndpoint.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using FastEndpoints;
|
||||
using PasswordGenerator;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUserDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/users");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
||||
{
|
||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||
|
||||
var user = new Models.User()
|
||||
{
|
||||
Name = req.Name,
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
||||
Salt = salt,
|
||||
Email = req.Email,
|
||||
Fonction = req.Fonction
|
||||
};
|
||||
|
||||
database.Users.Add(user);
|
||||
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetUserDto responseDto = new()
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Password = user.Password,
|
||||
Salt = user.Salt,
|
||||
Email = user.Email,
|
||||
Fonction = user.Fonction
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
33
PyroFetes/Endpoints/User/DeleteUserEndpoint.cs
Normal file
33
PyroFetes/Endpoints/User/DeleteUserEndpoint.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class DeleteUserRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUserRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/users/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Users.Remove(user);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
30
PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs
Normal file
30
PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetUserDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/users");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var users = await database.Users
|
||||
.Select(users => new GetUserDto()
|
||||
{
|
||||
Id = users.Id,
|
||||
Name = users.Name,
|
||||
Password = users.Password,
|
||||
Salt = users.Salt,
|
||||
Email = users.Email,
|
||||
Fonction = users.Fonction
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(users, ct);
|
||||
}
|
||||
}
|
||||
42
PyroFetes/Endpoints/User/GetUserEndpoint.cs
Normal file
42
PyroFetes/Endpoints/User/GetUserEndpoint.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class GetUserRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequest, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/users/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetUserDto responseDto = new()
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Password = user.Password,
|
||||
Salt = user.Salt,
|
||||
Email = user.Email,
|
||||
Fonction = user.Fonction
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
39
PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs
Normal file
39
PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/users/{@Id}/Password", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
if (user == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetUserDto responseDto = new()
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Password = user.Password,
|
||||
Salt = user.Salt,
|
||||
Email = user.Email,
|
||||
Fonction = user.Fonction
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
54
PyroFetes/Endpoints/User/UpdateUserEndpoint.cs
Normal file
54
PyroFetes/Endpoints/User/UpdateUserEndpoint.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PasswordGenerator;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.User;
|
||||
|
||||
public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUserDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/users/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
var ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ckeckName != null)
|
||||
{
|
||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||
|
||||
user.Name = req.Name;
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt);
|
||||
user.Salt = salt;
|
||||
user.Email = req.Email;
|
||||
user.Fonction = req.Fonction;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetUserDto responseDto = new()
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Password = user.Password,
|
||||
Salt = user.Salt,
|
||||
Email = user.Email,
|
||||
Fonction = user.Fonction
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
||||
|
||||
public class GetTotalQuantityRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
}
|
||||
|
||||
public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/wareHouseProduct/{@ProductId}", x => new { x.ProductId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
||||
{
|
||||
var exists = await database.WarehouseProducts
|
||||
.AnyAsync(wp => wp.ProductId == req.ProductId, ct);
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
var totalQuantity = await database.WarehouseProducts
|
||||
.Where(wp => wp.ProductId == req.ProductId)
|
||||
.SumAsync(wp => wp.Quantity, ct);
|
||||
|
||||
GetTotalQuantityDto responseDto = new()
|
||||
{
|
||||
ProductId = req.ProductId,
|
||||
TotalQuantity = totalQuantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
||||
|
||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/wareHouseProduct/{@ProductId}/{@WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
var wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
|
||||
if (wareHouseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetWareHouseProductDto responseDto = new()
|
||||
{
|
||||
ProductId = wareHouseProduct.ProductId,
|
||||
WareHouseId = wareHouseProduct.WarehouseId,
|
||||
Quantity = wareHouseProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using AutoMapper;
|
||||
using PyroFetes.DTO.Deliverer.Request;
|
||||
using PyroFetes.DTO.DeliveryNote.Request;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.DTO.Product.Request;
|
||||
using PyroFetes.DTO.ProductDelivery.Request;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.MappingProfiles;
|
||||
|
||||
public class DtoToEntityMappings : Profile
|
||||
{
|
||||
public DtoToEntityMappings()
|
||||
{
|
||||
CreateMap<CreateDelivererDto, Deliverer>();
|
||||
CreateMap<UpdateDelivererDto, Deliverer>();
|
||||
|
||||
CreateMap<CreateDeliveryNoteDto, DeliveryNote>();
|
||||
CreateMap<UpdateDeliveryNoteDto, DeliveryNote>();
|
||||
CreateMap<PatchDeliveryNoteRealDeliveryDateDto, DeliveryNote>();
|
||||
|
||||
CreateMap<CreatePriceDto, Price>();
|
||||
CreateMap<UpdatePriceDto, Price>();
|
||||
CreateMap<PatchPriceSellingPriceDto, Price>();
|
||||
|
||||
CreateMap<CreateProductDto, Product>();
|
||||
CreateMap<UpdateProductDto, Product>();
|
||||
CreateMap<PatchProductMinimalStockDto, Product>();
|
||||
|
||||
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
|
||||
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
|
||||
|
||||
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>();
|
||||
|
||||
CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
|
||||
CreateMap<UpdatePurchaseProductDto, PurchaseProduct>();
|
||||
CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>();
|
||||
|
||||
CreateMap<PatchQuotationConditionsSaleDto, Quotation>();
|
||||
CreateMap<PatchQuotationMessageDto, Quotation>();
|
||||
|
||||
CreateMap<CreateQuotationProductDto, QuotationProduct>();
|
||||
CreateMap<UpdateQuotationProductDto, QuotationProduct>();
|
||||
CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>();
|
||||
|
||||
CreateMap<CreateSettingDto, Setting>();
|
||||
CreateMap<PatchSettingElectronicSignatureDto, Setting>();
|
||||
CreateMap<PatchSettingLogoDto, Setting>();
|
||||
|
||||
CreateMap<CreateSupplierDto, Supplier>();
|
||||
CreateMap<UpdateSupplierDto, Supplier>();
|
||||
CreateMap<PatchSupplierDeliveryDelayDto, Supplier>();
|
||||
|
||||
CreateMap<CreateUserDto, User>();
|
||||
CreateMap<UpdateUserDto, User>();
|
||||
CreateMap<PatchUserPasswordDto, User>();
|
||||
|
||||
CreateMap<PatchWareHouseProductQuantityDto, WarehouseProduct>();
|
||||
}
|
||||
}
|
||||
46
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
46
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using AutoMapper;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.DTO.ProductDelivery.Response;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.MappingProfiles;
|
||||
|
||||
public class EntityToDtoMappings : Profile
|
||||
{
|
||||
public EntityToDtoMappings()
|
||||
{
|
||||
CreateMap<Deliverer, GetDelivererDto>();
|
||||
|
||||
CreateMap<DeliveryNote, GetDeliveryNoteDto>();
|
||||
|
||||
CreateMap<Price, GetPriceDto>();
|
||||
|
||||
CreateMap<Product, GetProductDto>();
|
||||
|
||||
CreateMap<ProductDelivery, GetProductDeliveryDto>();
|
||||
|
||||
CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
|
||||
|
||||
CreateMap<PurchaseProduct, GetPurchaseProductDto>();
|
||||
|
||||
CreateMap<Quotation, GetQuotationDto>();
|
||||
|
||||
CreateMap<QuotationProduct, GetQuotationProductDto>();
|
||||
|
||||
CreateMap<Setting, GetSettingDto>();
|
||||
|
||||
CreateMap<User, GetUserDto>();
|
||||
|
||||
CreateMap<WarehouseProduct, GetWareHouseProductDto>();
|
||||
}
|
||||
}
|
||||
1963
PyroFetes/Migrations/20251013175653_AddingEntitiesInDatabase.Designer.cs
generated
Normal file
1963
PyroFetes/Migrations/20251013175653_AddingEntitiesInDatabase.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
755
PyroFetes/Migrations/20251013175653_AddingEntitiesInDatabase.cs
Normal file
755
PyroFetes/Migrations/20251013175653_AddingEntitiesInDatabase.cs
Normal file
@@ -0,0 +1,755 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PyroFetes.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddingEntitiesInDatabase : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ContactServiceProvider_Contacts_ContactId",
|
||||
table: "ContactServiceProvider");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ContactServiceProvider_Providers_ServiceProviderId",
|
||||
table: "ContactServiceProvider");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Contract_Providers_ServiceProviderId",
|
||||
table: "Contract");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Contract_Shows_ShowId",
|
||||
table: "Contract");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_MaterialWarehouse_Materials_MaterialId",
|
||||
table: "MaterialWarehouse");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_MaterialWarehouse_Warehouses_WarehouseId",
|
||||
table: "MaterialWarehouse");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProductTimecode_Products_ProductId",
|
||||
table: "ProductTimecode");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProductTimecode_Shows_ShowId",
|
||||
table: "ProductTimecode");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProviderContacts_Providers_ProviderId",
|
||||
table: "ProviderContacts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Providers_ProviderTypes_ProviderTypeId",
|
||||
table: "Providers");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowMaterial_Materials_MaterialId",
|
||||
table: "ShowMaterial");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowMaterial_Shows_ShowId",
|
||||
table: "ShowMaterial");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Shows_City_CityId",
|
||||
table: "Shows");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowStaff_Shows_ShowId",
|
||||
table: "ShowStaff");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowStaff_Staffs_StaffId",
|
||||
table: "ShowStaff");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowTruck_Shows_ShowId",
|
||||
table: "ShowTruck");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowTruck_Trucks_TruckId",
|
||||
table: "ShowTruck");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowTruck",
|
||||
table: "ShowTruck");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowStaff",
|
||||
table: "ShowStaff");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowMaterial",
|
||||
table: "ShowMaterial");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_Providers",
|
||||
table: "Providers");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ProductTimecode",
|
||||
table: "ProductTimecode");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_MaterialWarehouse",
|
||||
table: "MaterialWarehouse");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_Contract",
|
||||
table: "Contract");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ContactServiceProvider",
|
||||
table: "ContactServiceProvider");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_City",
|
||||
table: "City");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowTruck",
|
||||
newName: "ShowTrucks");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowStaff",
|
||||
newName: "ShowStaffs");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowMaterial",
|
||||
newName: "ShowMaterials");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Providers",
|
||||
newName: "ServiceProviders");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ProductTimecode",
|
||||
newName: "ProductTimecodes");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "MaterialWarehouse",
|
||||
newName: "MaterialWarehouses");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Contract",
|
||||
newName: "Contracts");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ContactServiceProvider",
|
||||
newName: "ContactServiceProviders");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "City",
|
||||
newName: "Cities");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowTruck_TruckId",
|
||||
table: "ShowTrucks",
|
||||
newName: "IX_ShowTrucks_TruckId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowStaff_ShowId",
|
||||
table: "ShowStaffs",
|
||||
newName: "IX_ShowStaffs_ShowId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowMaterial_MaterialId",
|
||||
table: "ShowMaterials",
|
||||
newName: "IX_ShowMaterials_MaterialId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_Providers_ProviderTypeId",
|
||||
table: "ServiceProviders",
|
||||
newName: "IX_ServiceProviders_ProviderTypeId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ProductTimecode_ShowId",
|
||||
table: "ProductTimecodes",
|
||||
newName: "IX_ProductTimecodes_ShowId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_MaterialWarehouse_WarehouseId",
|
||||
table: "MaterialWarehouses",
|
||||
newName: "IX_MaterialWarehouses_WarehouseId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_Contract_ServiceProviderId",
|
||||
table: "Contracts",
|
||||
newName: "IX_Contracts_ServiceProviderId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ContactServiceProvider_ServiceProviderId",
|
||||
table: "ContactServiceProviders",
|
||||
newName: "IX_ContactServiceProviders_ServiceProviderId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowTrucks",
|
||||
table: "ShowTrucks",
|
||||
columns: new[] { "ShowId", "TruckId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowStaffs",
|
||||
table: "ShowStaffs",
|
||||
columns: new[] { "StaffId", "ShowId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowMaterials",
|
||||
table: "ShowMaterials",
|
||||
columns: new[] { "ShowId", "MaterialId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ServiceProviders",
|
||||
table: "ServiceProviders",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ProductTimecodes",
|
||||
table: "ProductTimecodes",
|
||||
columns: new[] { "ProductId", "ShowId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_MaterialWarehouses",
|
||||
table: "MaterialWarehouses",
|
||||
columns: new[] { "MaterialId", "WarehouseId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Contracts",
|
||||
table: "Contracts",
|
||||
columns: new[] { "ShowId", "ServiceProviderId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ContactServiceProviders",
|
||||
table: "ContactServiceProviders",
|
||||
columns: new[] { "ContactId", "ServiceProviderId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Cities",
|
||||
table: "Cities",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShowServiceProviders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShowServiceProviders", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ContactServiceProviders_Contacts_ContactId",
|
||||
table: "ContactServiceProviders",
|
||||
column: "ContactId",
|
||||
principalTable: "Contacts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ContactServiceProviders_ServiceProviders_ServiceProviderId",
|
||||
table: "ContactServiceProviders",
|
||||
column: "ServiceProviderId",
|
||||
principalTable: "ServiceProviders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Contracts_ServiceProviders_ServiceProviderId",
|
||||
table: "Contracts",
|
||||
column: "ServiceProviderId",
|
||||
principalTable: "ServiceProviders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Contracts_Shows_ShowId",
|
||||
table: "Contracts",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_MaterialWarehouses_Materials_MaterialId",
|
||||
table: "MaterialWarehouses",
|
||||
column: "MaterialId",
|
||||
principalTable: "Materials",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_MaterialWarehouses_Warehouses_WarehouseId",
|
||||
table: "MaterialWarehouses",
|
||||
column: "WarehouseId",
|
||||
principalTable: "Warehouses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProductTimecodes_Products_ProductId",
|
||||
table: "ProductTimecodes",
|
||||
column: "ProductId",
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProductTimecodes_Shows_ShowId",
|
||||
table: "ProductTimecodes",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProviderContacts_ServiceProviders_ProviderId",
|
||||
table: "ProviderContacts",
|
||||
column: "ProviderId",
|
||||
principalTable: "ServiceProviders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ServiceProviders_ProviderTypes_ProviderTypeId",
|
||||
table: "ServiceProviders",
|
||||
column: "ProviderTypeId",
|
||||
principalTable: "ProviderTypes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowMaterials_Materials_MaterialId",
|
||||
table: "ShowMaterials",
|
||||
column: "MaterialId",
|
||||
principalTable: "Materials",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowMaterials_Shows_ShowId",
|
||||
table: "ShowMaterials",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Shows_Cities_CityId",
|
||||
table: "Shows",
|
||||
column: "CityId",
|
||||
principalTable: "Cities",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowStaffs_Shows_ShowId",
|
||||
table: "ShowStaffs",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowStaffs_Staffs_StaffId",
|
||||
table: "ShowStaffs",
|
||||
column: "StaffId",
|
||||
principalTable: "Staffs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowTrucks_Shows_ShowId",
|
||||
table: "ShowTrucks",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowTrucks_Trucks_TruckId",
|
||||
table: "ShowTrucks",
|
||||
column: "TruckId",
|
||||
principalTable: "Trucks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ContactServiceProviders_Contacts_ContactId",
|
||||
table: "ContactServiceProviders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ContactServiceProviders_ServiceProviders_ServiceProviderId",
|
||||
table: "ContactServiceProviders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Contracts_ServiceProviders_ServiceProviderId",
|
||||
table: "Contracts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Contracts_Shows_ShowId",
|
||||
table: "Contracts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_MaterialWarehouses_Materials_MaterialId",
|
||||
table: "MaterialWarehouses");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_MaterialWarehouses_Warehouses_WarehouseId",
|
||||
table: "MaterialWarehouses");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProductTimecodes_Products_ProductId",
|
||||
table: "ProductTimecodes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProductTimecodes_Shows_ShowId",
|
||||
table: "ProductTimecodes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ProviderContacts_ServiceProviders_ProviderId",
|
||||
table: "ProviderContacts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ServiceProviders_ProviderTypes_ProviderTypeId",
|
||||
table: "ServiceProviders");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowMaterials_Materials_MaterialId",
|
||||
table: "ShowMaterials");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowMaterials_Shows_ShowId",
|
||||
table: "ShowMaterials");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Shows_Cities_CityId",
|
||||
table: "Shows");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowStaffs_Shows_ShowId",
|
||||
table: "ShowStaffs");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowStaffs_Staffs_StaffId",
|
||||
table: "ShowStaffs");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowTrucks_Shows_ShowId",
|
||||
table: "ShowTrucks");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ShowTrucks_Trucks_TruckId",
|
||||
table: "ShowTrucks");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShowServiceProviders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowTrucks",
|
||||
table: "ShowTrucks");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowStaffs",
|
||||
table: "ShowStaffs");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ShowMaterials",
|
||||
table: "ShowMaterials");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ServiceProviders",
|
||||
table: "ServiceProviders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ProductTimecodes",
|
||||
table: "ProductTimecodes");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_MaterialWarehouses",
|
||||
table: "MaterialWarehouses");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_Contracts",
|
||||
table: "Contracts");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_ContactServiceProviders",
|
||||
table: "ContactServiceProviders");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_Cities",
|
||||
table: "Cities");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowTrucks",
|
||||
newName: "ShowTruck");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowStaffs",
|
||||
newName: "ShowStaff");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ShowMaterials",
|
||||
newName: "ShowMaterial");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ServiceProviders",
|
||||
newName: "Providers");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ProductTimecodes",
|
||||
newName: "ProductTimecode");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "MaterialWarehouses",
|
||||
newName: "MaterialWarehouse");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Contracts",
|
||||
newName: "Contract");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ContactServiceProviders",
|
||||
newName: "ContactServiceProvider");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Cities",
|
||||
newName: "City");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowTrucks_TruckId",
|
||||
table: "ShowTruck",
|
||||
newName: "IX_ShowTruck_TruckId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowStaffs_ShowId",
|
||||
table: "ShowStaff",
|
||||
newName: "IX_ShowStaff_ShowId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ShowMaterials_MaterialId",
|
||||
table: "ShowMaterial",
|
||||
newName: "IX_ShowMaterial_MaterialId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ServiceProviders_ProviderTypeId",
|
||||
table: "Providers",
|
||||
newName: "IX_Providers_ProviderTypeId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ProductTimecodes_ShowId",
|
||||
table: "ProductTimecode",
|
||||
newName: "IX_ProductTimecode_ShowId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_MaterialWarehouses_WarehouseId",
|
||||
table: "MaterialWarehouse",
|
||||
newName: "IX_MaterialWarehouse_WarehouseId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_Contracts_ServiceProviderId",
|
||||
table: "Contract",
|
||||
newName: "IX_Contract_ServiceProviderId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_ContactServiceProviders_ServiceProviderId",
|
||||
table: "ContactServiceProvider",
|
||||
newName: "IX_ContactServiceProvider_ServiceProviderId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowTruck",
|
||||
table: "ShowTruck",
|
||||
columns: new[] { "ShowId", "TruckId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowStaff",
|
||||
table: "ShowStaff",
|
||||
columns: new[] { "StaffId", "ShowId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ShowMaterial",
|
||||
table: "ShowMaterial",
|
||||
columns: new[] { "ShowId", "MaterialId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Providers",
|
||||
table: "Providers",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ProductTimecode",
|
||||
table: "ProductTimecode",
|
||||
columns: new[] { "ProductId", "ShowId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_MaterialWarehouse",
|
||||
table: "MaterialWarehouse",
|
||||
columns: new[] { "MaterialId", "WarehouseId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Contract",
|
||||
table: "Contract",
|
||||
columns: new[] { "ShowId", "ServiceProviderId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_ContactServiceProvider",
|
||||
table: "ContactServiceProvider",
|
||||
columns: new[] { "ContactId", "ServiceProviderId" });
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_City",
|
||||
table: "City",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ContactServiceProvider_Contacts_ContactId",
|
||||
table: "ContactServiceProvider",
|
||||
column: "ContactId",
|
||||
principalTable: "Contacts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ContactServiceProvider_Providers_ServiceProviderId",
|
||||
table: "ContactServiceProvider",
|
||||
column: "ServiceProviderId",
|
||||
principalTable: "Providers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Contract_Providers_ServiceProviderId",
|
||||
table: "Contract",
|
||||
column: "ServiceProviderId",
|
||||
principalTable: "Providers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Contract_Shows_ShowId",
|
||||
table: "Contract",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_MaterialWarehouse_Materials_MaterialId",
|
||||
table: "MaterialWarehouse",
|
||||
column: "MaterialId",
|
||||
principalTable: "Materials",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_MaterialWarehouse_Warehouses_WarehouseId",
|
||||
table: "MaterialWarehouse",
|
||||
column: "WarehouseId",
|
||||
principalTable: "Warehouses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProductTimecode_Products_ProductId",
|
||||
table: "ProductTimecode",
|
||||
column: "ProductId",
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProductTimecode_Shows_ShowId",
|
||||
table: "ProductTimecode",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ProviderContacts_Providers_ProviderId",
|
||||
table: "ProviderContacts",
|
||||
column: "ProviderId",
|
||||
principalTable: "Providers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Providers_ProviderTypes_ProviderTypeId",
|
||||
table: "Providers",
|
||||
column: "ProviderTypeId",
|
||||
principalTable: "ProviderTypes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowMaterial_Materials_MaterialId",
|
||||
table: "ShowMaterial",
|
||||
column: "MaterialId",
|
||||
principalTable: "Materials",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowMaterial_Shows_ShowId",
|
||||
table: "ShowMaterial",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Shows_City_CityId",
|
||||
table: "Shows",
|
||||
column: "CityId",
|
||||
principalTable: "City",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowStaff_Shows_ShowId",
|
||||
table: "ShowStaff",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowStaff_Staffs_StaffId",
|
||||
table: "ShowStaff",
|
||||
column: "StaffId",
|
||||
principalTable: "Staffs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowTruck_Shows_ShowId",
|
||||
table: "ShowTruck",
|
||||
column: "ShowId",
|
||||
principalTable: "Shows",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ShowTruck_Trucks_TruckId",
|
||||
table: "ShowTruck",
|
||||
column: "TruckId",
|
||||
principalTable: "Trucks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("City");
|
||||
b.ToTable("Cities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Classification", b =>
|
||||
@@ -228,7 +228,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("ServiceProviderId");
|
||||
|
||||
b.ToTable("ContactServiceProvider");
|
||||
b.ToTable("ContactServiceProviders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Contract", b =>
|
||||
@@ -247,7 +247,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("ServiceProviderId");
|
||||
|
||||
b.ToTable("Contract");
|
||||
b.ToTable("Contracts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Customer", b =>
|
||||
@@ -439,7 +439,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("WarehouseId");
|
||||
|
||||
b.ToTable("MaterialWarehouse");
|
||||
b.ToTable("MaterialWarehouses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Movement", b =>
|
||||
@@ -644,7 +644,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("ShowId");
|
||||
|
||||
b.ToTable("ProductTimecode");
|
||||
b.ToTable("ProductTimecodes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.ProviderContact", b =>
|
||||
@@ -780,7 +780,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("ProviderTypeId");
|
||||
|
||||
b.ToTable("Providers");
|
||||
b.ToTable("ServiceProviders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Setting", b =>
|
||||
@@ -856,7 +856,20 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("MaterialId");
|
||||
|
||||
b.ToTable("ShowMaterial");
|
||||
b.ToTable("ShowMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.ShowServiceProvider", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ShowServiceProviders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.ShowStaff", b =>
|
||||
@@ -871,7 +884,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("ShowId");
|
||||
|
||||
b.ToTable("ShowStaff");
|
||||
b.ToTable("ShowStaffs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.ShowTruck", b =>
|
||||
@@ -886,7 +899,7 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.HasIndex("TruckId");
|
||||
|
||||
b.ToTable("ShowTruck");
|
||||
b.ToTable("ShowTrucks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PyroFetes.Models.Sound", b =>
|
||||
|
||||
@@ -1,18 +1,42 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
using AutoMapper;
|
||||
using AutoMapper.EquivalencyExpression;
|
||||
using PyroFetes;
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Swagger;
|
||||
using FastEndpoints.Security;
|
||||
using PyroFetes.MappingProfiles;
|
||||
using IMapper = FastEndpoints.IMapper;
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var app = builder.Build();
|
||||
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
||||
builder.Services
|
||||
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
||||
.AddAuthorization()
|
||||
.AddFastEndpoints()
|
||||
.SwaggerDocument();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
// On ajoute ici la configuration de la base de données
|
||||
builder.Services.AddDbContext<PyroFetesDbContext>();
|
||||
|
||||
|
||||
MapperConfiguration mappingConfig = new(mc =>
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
mc.AddCollectionMappers();
|
||||
mc.AddProfile(new DtoToEntityMappings());
|
||||
mc.AddProfile(new EntityToDtoMappings());
|
||||
}, new LoggerFactory());
|
||||
|
||||
|
||||
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
|
||||
builder.Services.AddSingleton(mapper);
|
||||
|
||||
// On construit l'application en lui donnant vie
|
||||
WebApplication app = builder.Build();
|
||||
app.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseFastEndpoints()
|
||||
.UseSwaggerGen();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
|
||||
@@ -7,7 +7,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="9.3.1" />
|
||||
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||
<PackageReference Include="AutoMapper.Collection" Version="11.0.0" />
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
||||
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
||||
<PackageReference Include="FastEndpoints.Swagger" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
|
||||
@@ -15,6 +21,8 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
||||
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
||||
<PackageReference Include="Plainquire.Page" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@ public class PyroFetesDbContext : DbContext
|
||||
// Entities
|
||||
public DbSet<Availability> Availabilities { get; set; }
|
||||
public DbSet<Brand> Brands { get; set; }
|
||||
public DbSet<City> Cities { get; set; }
|
||||
public DbSet<Classification> Classifications { get; set; }
|
||||
public DbSet<Color> Colors { get; set; }
|
||||
public DbSet<Communication> Communications { get; set; }
|
||||
public DbSet<Contact> Contacts { get; set; }
|
||||
public DbSet<ContactServiceProvider> ContactServiceProviders { get; set; }
|
||||
public DbSet<Contract> Contracts { get; set; }
|
||||
public DbSet<Customer> Customers { get; set; }
|
||||
public DbSet<CustomerType> CustomerTypes { get; set; }
|
||||
public DbSet<Deliverer> Deliverers { get; set; }
|
||||
@@ -21,6 +24,7 @@ public class PyroFetesDbContext : DbContext
|
||||
public DbSet<ExperienceLevel> ExperienceLevels { get; set; }
|
||||
public DbSet<HistoryOfApproval> HistoryOfApprovals { get; set; }
|
||||
public DbSet<Material> Materials { get; set; }
|
||||
public DbSet<MaterialWarehouse> MaterialWarehouses { get; set; }
|
||||
public DbSet<Movement> Movements { get; set; }
|
||||
public DbSet<Price> Prices { get; set; }
|
||||
public DbSet<Product> Products { get; set; }
|
||||
@@ -28,15 +32,20 @@ public class PyroFetesDbContext : DbContext
|
||||
public DbSet<ProductColor> ProductColors { get; set; }
|
||||
public DbSet<ProductDelivery> ProductDeliveries { get; set; }
|
||||
public DbSet<ProductEffect> ProductEffects { get; set; }
|
||||
public DbSet<ServiceProvider> Providers { get; set; }
|
||||
public DbSet<ProductTimecode> ProductTimecodes { get; set; }
|
||||
public DbSet<ProviderContact> ProviderContacts { get; set; }
|
||||
public DbSet<ProviderType> ProviderTypes { get; set; }
|
||||
public DbSet<PurchaseOrder> PurchaseOrders { get; set; }
|
||||
public DbSet<PurchaseProduct> PurchaseProducts { get; set; }
|
||||
public DbSet<Quotation> Quotations { get; set; }
|
||||
public DbSet<QuotationProduct> QuotationProducts { get; set; }
|
||||
public DbSet<ServiceProvider> ServiceProviders { get; set; }
|
||||
public DbSet<Setting> Settings { get; set; }
|
||||
public DbSet<Show> Shows { get; set; }
|
||||
public DbSet<ShowMaterial> ShowMaterials { get; set; }
|
||||
public DbSet<ShowServiceProvider> ShowServiceProviders { get; set; }
|
||||
public DbSet<ShowStaff> ShowStaffs { get; set; }
|
||||
public DbSet<ShowTruck> ShowTrucks { get; set; }
|
||||
public DbSet<Sound> Sounds { get; set; }
|
||||
public DbSet<SoundCategory> SoundCategories { get; set; }
|
||||
public DbSet<SoundTimecode> SoundTimecodes { get; set; }
|
||||
|
||||
328
PyroFetes/Repositories/PyrofetesRepository.cs
Normal file
328
PyroFetes/Repositories/PyrofetesRepository.cs
Normal file
@@ -0,0 +1,328 @@
|
||||
using System.Linq.Expressions;
|
||||
using Ardalis.Specification;
|
||||
using Ardalis.Specification.EntityFrameworkCore;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Plainquire.Page;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class PyrofetesRepository<T>(DbContext databaseContext, AutoMapper.IMapper mapper) : RepositoryBase<T>(databaseContext) where T : class
|
||||
{
|
||||
private readonly DbContext _databaseContext = databaseContext;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T?> FirstOrDefaultAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _databaseContext.Set<T>().AsQueryable().FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> FirstAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _databaseContext.Set<T>().AsQueryable().FirstAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> SingleAsync(ISpecification<T> specification, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification).SingleAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> SingleAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _databaseContext.Set<T>().AsQueryable().SingleAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<decimal> SumAsync(
|
||||
ISpecification<T> specification,
|
||||
Expression<Func<T, decimal>> selector,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification).SumAsync(selector, cancellationToken);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="specification"></param>
|
||||
// /// <param name="selector"></param>
|
||||
// /// <param name="cancellationToken"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<int> SumAsync(
|
||||
// ISpecification<T> specification,
|
||||
// Expression<Func<T, int>> selector,
|
||||
// CancellationToken cancellationToken = default)
|
||||
// {
|
||||
// return await ApplySpecification(specification).SumAsync(selector, cancellationToken);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
Action<TResult?> postProcessor,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
TResult? result = await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||
postProcessor(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="cancellationToken"></param>
|
||||
// /// <typeparam name="TResult"></typeparam>
|
||||
// /// <returns></returns>
|
||||
// public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||
// CancellationToken cancellationToken = default)
|
||||
// {
|
||||
// return await _databaseContext.Set<T>().AsQueryable().ProjectTo<TResult>(mapper.ConfigurationProvider).SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.SingleAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
Action<TResult?> postProcessor,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
TResult result = await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.SingleAsync(cancellationToken: cancellationToken);
|
||||
postProcessor(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _databaseContext.Set<T>()
|
||||
.AsQueryable()
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.SingleAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _databaseContext.Set<T>()
|
||||
.AsQueryable()
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
Action<List<TResult>> postProcessor,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<TResult> results = await _databaseContext.Set<T>()
|
||||
.AsQueryable()
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
postProcessor(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
Action<List<TResult>> postProcessor,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<TResult> results = await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
postProcessor(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="postProcessor"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
EntityPage page,
|
||||
Action<List<TResult>> postProcessor,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<TResult> results = await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.Page(page)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
postProcessor(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
EntityPage page,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification)
|
||||
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||
.Page(page)
|
||||
.ToListAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> SelectManyAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
Expression<Func<T, IEnumerable<TResult>>> selector,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification).SelectMany(selector).ToListAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="specification"></param>
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TResult>> SelectAsync<TResult>(
|
||||
ISpecification<T> specification,
|
||||
Expression<Func<T, TResult>> selector,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification).Select(selector).ToListAsync(cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user