public async Task <IActionResult> Edit(int id) { try { QuestionnairesDetailViewModel viewModel = new QuestionnairesDetailViewModel { Questionnaire = await _questionnaireService.GetByIdAsync(id, true) }; return(View(viewModel)); } catch (GraException gex) { ShowAlertWarning("Unable to view questionnaire: ", gex); return(RedirectToAction("Index")); } }
public async Task <IActionResult> Edit(QuestionnairesDetailViewModel model) { if (ModelState.IsValid) { try { var questionnaire = await _questionnaireService.UpdateAsync(model.Questionnaire); if (!string.IsNullOrWhiteSpace(model.QuestionSortOrder)) { List <int> questionOrderList = model.QuestionSortOrder .Replace("question[]=", "") .Split('&') .Where(_ => !string.IsNullOrWhiteSpace(_)) .Select(int.Parse) .Distinct() .ToList(); await _questionnaireService.UpdateQuestionListAsync(questionnaire.Id, questionOrderList); } else { await _questionnaireService.UpdateQuestionListAsync(questionnaire.Id, new List <int>()); } ShowAlertSuccess($"Questionnaire '{questionnaire.Name}' successfully updated!"); return(RedirectToAction("Edit", new { id = questionnaire.Id })); } catch (GraException gex) { ShowAlertDanger("Unable to edit questionnaire: ", gex); return(RedirectToAction("Edit", new { id = model.Questionnaire.Id })); } } return(View(model)); }