コード例 #1
0
        public async Task <ActionResult> EditQuestion(UpdatedQuestionDTO updatedQuestion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _adminService.EditQuestionAsync(updatedQuestion);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(Problem(
                           title: "Problem on updating question.",
                           detail: "Problem occured on updating question.",
                           statusCode: 500));
            }
        }
コード例 #2
0
        public async Task <QuestionDTO> EditQuestionAsync(UpdatedQuestionDTO updatedQuestion)
        {
            var question = await _quesitonRepository.GetQuestionAsync(updatedQuestion.QuestionId);

            if (updatedQuestion.Choices.Count != question.Choices.Choices.Length)
            {
                return(null);
            }

            _mapper.Map(updatedQuestion, question);

            var result = await _quesitonRepository.UpdateAsync(question);

            if (result != null)
            {
                return(_mapper.Map <QuestionDTO>(result));
            }
            else
            {
                return(null);
            }
        }