コード例 #1
0
        public async Task <ActionResult> UpdateQuestionWithAnswers(long questionId, UpdateQuestionDTO updateQuestion)
        {
            var result = await Send(updateQuestion.CreateCommand(questionId));

            if (result.Status == ResultStatus.Conflict)
            {
                var newQuestionVersion = await Send(new ReadQuestionWithAnswersQuery(questionId));

                return(Conflict(newQuestionVersion.Value));
            }

            return(ActionResult(result));
        }
コード例 #2
0
        /// <summary>
        /// Updates single question which that equals <paramref name="updateQuestionDTO"/> in repository by <paramref name="updateQuestionDTO"/>'s properties.
        /// </summary>
        /// <param name="updateQuestionDTO">Question to be updated.</param>
        /// <returns></returns>
        public async Task UpdateQuestionAsync(UpdateQuestionDTO updateQuestionDTO)
        {
            var toBeUpdatedQuestion = await _questionRepository.GetByIdAsync(updateQuestionDTO.Id).ConfigureAwait(false);

            toBeUpdatedQuestion.ThrowIfNullForGuidObject();

            toBeUpdatedQuestion.IsUseful        = updateQuestionDTO.IsUseful;
            toBeUpdatedQuestion.MentorReply     = updateQuestionDTO.MentorReply;
            toBeUpdatedQuestion.ProfessionId    = updateQuestionDTO.ProfessionId;
            toBeUpdatedQuestion.QuestionContent = updateQuestionDTO.QuestionContent;
            toBeUpdatedQuestion.WillShown       = updateQuestionDTO.WillShown;

            await _questionRepository.UpdateAsync(toBeUpdatedQuestion).ConfigureAwait(false);
        }
コード例 #3
0
        public async Task ExisitngQuestionCanBeUpdated(long questionId, long answerId)
        {
            var command = new UpdateQuestionDTO
            {
                Content = "Who is your momy?",
                Answers = new List <UpdateAnswerDTO>
                {
                    new UpdateAnswerDTO {
                        AnswerId = answerId, Content = "Alicia", IsCorrect = false
                    }
                },
                CatalogId        = TestUtils.ValidQuestionsCatalog2Id,
                ConcurrencyToken = 0
            };

            var response = await client.PutAsync($"{EndpointName}/{questionId}/", command);

            AssertExt.EnsureSuccessStatusCode(response);

            var context        = factory.GetService <TestCreationDbContext>();
            var actualQuestion = context.Questions.Include(x => x.Answers).FirstOrDefault(x => x.QuestionId == questionId);

            AssertExt.AreEquivalent(command, actualQuestion);
        }
コード例 #4
0
 public async Task <IActionResult> UpdateQuestion([FromBody] UpdateQuestionDTO updateQuestion)
 {
     return(await _questionService.UpdateQuestionAsync(updateQuestion).ConfigureAwait(false).GetObjectResponseAsync <UpdateQuestionDTO>("Success").ConfigureAwait(false));
 }