public ActionResult Edit(int id, CourseViewModel courseViewModel) { Course course = courseViewModel.Course; IEnumerable <int> prerequisites = courseViewModel.PrerequisiteIds; try { prerequisiteService.DeletePrequisiteByCourse(course.Id); courseService.Edit(course); if (prerequisites != null) { foreach (int prerequisiteId in prerequisites) { Prerequisite prerequisite = new Prerequisite { CourseId = course.Id, CoursePrerequisiteId = prerequisiteId }; prerequisiteService.Add(prerequisite); } } return(RedirectToAction("Index")); } catch (Exception ex) { return(View(courseViewModel)); } }