public IActionResult Update(EditQuestionAnswerViewModel vm) { vm.Courses = context.ReadAllCourses().ToList(); vm.LearnOutcomes = context.ReadAllOutcomes().ToList(); // Validate the model if (!ModelState.IsValid) { // Get the view model and return it return(View("Update", vm)); } // Add the qa try { // TODO: add a boolean to the update questions and answers vm.QuesAnswer.Course = context.ReadCourse(vm.CourseId); vm.QuesAnswer.LearnOutcome = context.ReadOutcome(vm.LearnOutcomeId); context.UpdateQuestion(vm.QuesAnswer.Id, vm.QuesAnswer); } catch { // For some reason the system could not create the Q&A. Redirect back to Update. ModelState.AddModelError(string.Empty, "Sorry, the system could not create the Q&A requested. Try again later."); return(View("Update", vm)); } return(RedirectToAction("Index")); }