public async Task <IActionResult> ReturnCommand(IRequestResponse commandResponse) { // Fire pre post events _eventDispatcher.GetPreCommitEvents().ForEach(async x => { await _mediator.Publish(x); }); if (_domainNotifications.HasNotifications()) { return(Ok(new { success = false, messages = _domainNotifications.GetAll() })); } else { if (await _unitOfWork.Commit()) { // Fire after commit events _eventDispatcher.GetAfterCommitEvents().ForEach(x => { _mediator.Publish(x); }); return(Ok(new { success = true, data = commandResponse })); } else { return(Ok(new { success = false, messages = new List <string>() { "Houve uma falha durante a gravação das informações no banco de dados" } })); } } }