public async Task <IActionResult> Edit(int?formId) { if (formId == null) { return(NotFound()); } var form = await _repository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } var viewModel = new FormQuestionViewModel { Form = new FormViewModel { Id = form.Id, Title = form.Title, Description = form.Description } }; return(View(viewModel)); }
public async Task <IActionResult> Preview(int?formId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } var response = new ResponseViewModel { FormTitle = form.Title, FormDescription = form.Description, Answers = form.Questions .Select(q => new AnswerViewModel { Question = q.ToViewModel() }) .ToList() }; return(View(response)); }
public async Task <IActionResult> Index(int?formId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); if (formId == null) { return(NotFound()); } var viewModel = new ShareViewModel { FormId = formId.Value, FormTitle = form.Title, FormDescription = form.Description, Link = Url.Link("view", new { guid = form.Guid }) }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int?formId, int?questionId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } Question question = null; if (questionId == null) { question = form.Questions.FirstOrDefault(); if (question == null) { question = await AddNewQuestion(form); } } else { if (questionId == 0) // this logic should be moved to another action { question = await AddNewQuestion(form); } else { question = form.Questions.SingleOrDefault(question => question.Id == questionId); if (question == null) { return(NotFound()); } } } var viewModel = new FormQuestionViewModel(form, question); return(View("Edit", viewModel)); }
public async Task <IActionResult> Index(int?formId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); var viewModel = new FormQuestionViewModel { Form = form.ToViewModel() }; return(View(viewModel)); }