public async Task <IActionResult> CreateAnswer(NewAnswerInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var newAnswerId = await this.surveysService.CreateAnswerAsync(inputModel.QuestionId, inputModel.Text); if (newAnswerId == null) { return(this.CustomCommonError()); } return(this.RedirectToAction(nameof(this.SurveyIndex))); }
public async Task <IActionResult> EditAnswer(NewAnswerInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } try { await this.surveysService.EditAnswerAsync(inputModel.Id, inputModel.Text); } catch (Exception) { return(this.CustomCommonError()); } return(this.RedirectToAction(nameof(this.SurveyIndex))); }
public async Task <IActionResult> EditAnswer(string answerId) { if (answerId == null) { return(this.CustomNotFound()); } var inputModel = new NewAnswerInputModel(); try { var existingAnswer = await this.surveysService.GetSingleAnswerAsync <AnswerViewModel>(answerId); inputModel.Id = existingAnswer.Id; inputModel.Text = existingAnswer.Text; } catch (Exception) { return(this.CustomCommonError()); } return(this.View(inputModel)); }
// =============================================== Answer =============================================== public async Task <IActionResult> CreateAnswer(string surveyId, string questionId) { var surveyTitle = await this.surveysService.GetSurveyTitleByIdAsync(surveyId); var question = await this.surveysService.GetQuestionByIdAsync <QuestionViewModel>(questionId); var questionText = question.Text; if (surveyTitle == null || questionText == null) { return(this.CustomNotFound()); } var model = new NewAnswerInputModel { SurveyTitle = surveyTitle, SurveyId = surveyId, QuestionId = questionId, QuestionText = questionText, }; return(this.View(model)); }