public async Task <Response <object> > Handle(UpdateQuestionCommand request, CancellationToken cancellationToken)
        {
            var response = new Response <object>();
            var question = await _questionRepository.GetByIdAsync(request.Id);

            if (question is null)
            {
                response.ErrorReason = ErrorReason.NotFound;
                response.Errors      = new Dictionary <string, IList <string> >
                {
                    {
                        UpdateQuestionKey,
                        new List <string> {
                            ErrorMessages.Entity <Question> .GetNotFoundMessage(request.Id)
                        }
                    }
                };
                return(response);
            }

            if (request.BestAnswerId.HasValue &&
                !await _answerRepository.DoesAnswerExistAsync(request.BestAnswerId.Value))
            {
                response.ErrorReason = ErrorReason.NotFound;
                response.Errors      = new Dictionary <string, IList <string> >
                {
                    {
                        UpdateQuestionKey,
                        new List <string> {
                            ErrorMessages.Entity <Answer> .GetNotFoundMessage(request.BestAnswerId.Value)
                        }
                    }
                };
                return(response);
            }

            var userId = _currentUserService.UserId;

            if (!_accessValidator.HasAccessToModify(userId, question))
            {
                response.ErrorReason = ErrorReason.HaveNoAccess;
                response.Errors      = new Dictionary <string, IList <string> >()
                {
                    {
                        UpdateQuestionKey,
                        new List <string> {
                            ErrorMessages.Entity <Question> .GetNoAccessMessage(question.Id, userId)
                        }
                    }
                };
                return(response);
            }

            _mapper.Map(request, question);
            await _questionRepository.UpdateAsync(question);

            response.SetData();
            return(response);
        }
        public async Task <Response <object> > Handle(UpdateAnswerCommand request, CancellationToken cancellationToken)
        {
            var response = new Response <object>();
            var answer   = await _answerRepository.GetByIdAsync(request.Id);

            if (answer is null)
            {
                response.ErrorReason = ErrorReason.NotFound;
                response.Errors      = new Dictionary <string, IList <string> >
                {
                    {
                        UpdateAnswer,
                        new List <string> {
                            ErrorMessages.Entity <Answer> .GetNotFoundMessage(request.Id)
                        }
                    }
                };
                return(response);
            }

            var userId = _currentUserService.UserId;

            if (!_accessValidator.HasAccessToModify(userId, answer))
            {
                response.ErrorReason = ErrorReason.HaveNoAccess;
                response.Errors      = new Dictionary <string, IList <string> >()
                {
                    {
                        UpdateAnswer,
                        new List <string> {
                            ErrorMessages.Entity <Answer> .GetNoAccessMessage(answer.Id, userId)
                        }
                    }
                };
                return(response);
            }

            _mapper.Map(request, answer);
            await _answerRepository.UpdateAsync(answer);

            response.SetData();
            return(response);
        }