public int Update(UpdateAnswerRequestModel model) { var answer = _repo.GetById(model.Id); answer.Text = model.Text; return(_repo.Update(answer)); }
public async Task DeleteAnswer(int questionId, int answerId, string username, string role) { var answer = await answerRepo.FindById(answerId); if (answer == null) { throw new NotFoundException(); } if (answer.Author != username || answer.Type != AnswerType.Simple) { throw new ConflictedDataException(); } answer.Content = ""; answer.Type = AnswerType.Deleted; await answerRepo.Update(answer); await questionHub.OnAnswerEdited(questionId, answer); }
public async Task <ActionResult> EditQuestionAsync(Guid Id, IFormCollection collection, EditQuestion_VM vm) { try { if (ModelState.IsValid) { // TODO: Add update logic here if (Id == null) { return(RedirectToAction("Quizzes")); } Question question = new Question() { QuizId = vm.QuizId, QuestionId = vm.QuestionId, QuestionText = vm.QuestionText }; var resultQuestion = await questionRepo.Update(question); if (resultQuestion == null) { return(BadRequest()); } Answer answer = new Answer() { AnswerID = Guid.Parse(vm.QuestionAnswerId), AnswerText = vm.QuestionAnswer, QuestionID = vm.QuestionId }; var resultAnswer = await answerRepo.Update(answer); if (resultAnswer == null) { return(BadRequest()); } Choice a = new Choice() { ChoiceID = Guid.Parse(vm.ChoiceAId), QuestionID = vm.QuestionId, ChoiceText = vm.QuestionChoiceA }; var resultChoiceA = await choiceRepo.Update(a); if (resultChoiceA == null) { return(BadRequest()); } Choice b = new Choice() { ChoiceID = Guid.Parse(vm.ChoiceBId), QuestionID = vm.QuestionId, ChoiceText = vm.QuestionChoiceB }; var resultChoiceB = await choiceRepo.Update(b); if (resultChoiceB == null) { return(BadRequest()); } Choice c = new Choice() { ChoiceID = Guid.Parse(vm.ChoiceCId), QuestionID = vm.QuestionId, ChoiceText = vm.QuestionChoiceC }; var resultChoiceC = await choiceRepo.Update(c); if (resultChoiceC == null) { return(BadRequest()); } return(RedirectToAction("Questions", new { id = vm.QuizId })); } return(View(vm)); } catch (Exception ex) { Debug.WriteLine($"update error. {ex.Message}"); ModelState.AddModelError("", "Update actie mislukt." + ex.InnerException.Message); return(View(vm)); } }