added
This commit is contained in:
@@ -5,8 +5,7 @@ using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database)
|
||||
: Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
|
@@ -1,6 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class DeletePurchaseProductEndpoint
|
||||
public class DeletePurchaseOrderRequest
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseOrders/{Id:int}");
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class UpdatePurchaseProductEndpoint
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user