public virtual ActionResult Create(Course course) { if(ModelState.IsValid) { MvcApplication.CurrentSession.Store(course); MvcApplication.CurrentSession.SaveChanges(); TempData.SetMessage("New course created"); return RedirectToAction("Index"); } else { return View(ConvertToCourseViewModel(course)); } }
CourseViewModel ConvertToCourseViewModel(Course course) { CourseViewModel courseViewModel = new CourseViewModel { Centre = MvcApplication.CurrentSession.Load<Centre>(course.CentreId), CentreId = course.CentreId, EndDate = course.EndDate, Id = course.Id, Name = course.Name, StartDate = course.StartDate, StudentIds = course.StudentIds, Tutor = MvcApplication.CurrentSession.Load<Person>(course.TutorId), TutorId = course.TutorId, Unit = MvcApplication.CurrentSession.Load<Unit>(course.UnitId), UnitId = course.UnitId, VerifierId = course.VerifierId }; if (course.VerifierId != null) { courseViewModel.Verifier = MvcApplication.CurrentSession.Load<Person>(course.VerifierId); } courseViewModel.Students = MvcApplication.CurrentSession.Load<Person>(course.StudentIds.ToArray()).ToList(); return courseViewModel; }