public async Task <IActionResult> DeleteDefendant(int assetId, int defendantId)
        {
            var request = new DeleteDefendant {
                AssetId = assetId, DefendantId = defendantId
            };
            await mediator.Send(request);

            return(Ok());
        }
Example #2
0
        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);
        }