public async Task <bool> Handle(DeleteStatementByInvoiceIdCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid()) { await _mediatorHandler.RaiseEvent( new DomainValidationEvent(request.ValidationResult.ToString())); return(false); } var invoice = _invoiceRepository.GetById(request.InvoiceId); if (invoice == null) { await _mediatorHandler.RaiseEvent(new NotFoundEvent(request.InvoiceId, "Statement", "Invoice not found.")); return(false); } var deletedStatements = await _statementRepository.DeleteByInvoiceIdAsync(invoice.Id); foreach (var statement in deletedStatements) { await _mediatorHandler.RaiseEvent(new StatementDeletedEvent() { Old = statement }); } return(true); }