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)); }
/// <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); }
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); }
public async Task <IActionResult> UpdateQuestion([FromBody] UpdateQuestionDTO updateQuestion) { return(await _questionService.UpdateQuestionAsync(updateQuestion).ConfigureAwait(false).GetObjectResponseAsync <UpdateQuestionDTO>("Success").ConfigureAwait(false)); }