예제 #1
0
        public async Task <Response> SendCommand <T>(IRequest <T> request)
        {
            var commandResponse = await _mediator.Send(request);

            if (_domainNotifications.HasNotifications())
            {
                return(new Response
                {
                    Succeeded = false,
                    Errors = _domainNotifications.GetAll()
                });
            }
            else
            {
                return(new Response(commandResponse));
            }
        }
        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"
                        }
                    }));
                }
            }
        }
        public async Task <RequestResult> SendCommand <T>(IRequest <T> request)
        {
            var commandResponse = await _mediator.Send(request);

            // Fire pre post events
            await _eventDispatcher.FirePreCommitEvents();

            if (_domainNotifications.HasNotifications())
            {
                return(new RequestResult
                {
                    Success = false,
                    Messages = _domainNotifications.GetAll()
                });
            }
            else
            {
                if (await _unitOfWork.Commit())
                {
                    // Fire after commit events
                    await _eventDispatcher.FireAfterCommitEvents();

                    return(new RequestResult
                    {
                        Success = true,
                        Data = commandResponse
                    });
                }
                else
                {
                    return(new RequestResult
                    {
                        Success = false,
                        Messages = new List <string>()
                        {
                            "An error ocurred while saving data"
                        }
                    });
                }
            }
        }