public async Task <IActionResult> DeleteDefendant(int assetId, int defendantId) { var request = new DeleteDefendant { AssetId = assetId, DefendantId = defendantId }; await mediator.Send(request); return(Ok()); }
public async Task <Unit> Handle(DeleteDefendant request, CancellationToken cancellationToken) { var assetDefendantToDelete = await context.AssetDefendants .FirstOrDefaultAsync(x => x.AssetId == request.AssetId && x.PersonId == request.DefendantId); context.AssetDefendants.Remove(assetDefendantToDelete); context.Persons.Remove(assetDefendantToDelete.Defendant); await context.SaveChangesAsync(); return(Unit.Value); }