forked from sanchezvem/PyroFetes
17:17 09/10
This commit is contained in:
@@ -6,17 +6,17 @@ public class DeleteMaterialRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteMaterialRequest>
|
||||
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/materials/{@id}", x => new { x.Id });
|
||||
Delete("/materials/{@id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
|
||||
{
|
||||
Models.Material? materialToDelete = await appDbContext
|
||||
Models.Material? materialToDelete = await pyrofetesdbcontext
|
||||
.Materials
|
||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
@@ -27,8 +27,8 @@ public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<
|
||||
return;
|
||||
}
|
||||
|
||||
appDbContext.Materials.Remove(materialToDelete);
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
pyrofetesdbcontext.Materials.Remove(materialToDelete);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user