// // GET: /Courses/ public ActionResult Index() { String contextUserName = User.Identity.Name; if (String.IsNullOrEmpty(contextUserName)) { ViewBag.Message = "we couldn't locate your profile"; return View("Error"); } StudentRecord studentRecord = null; List<StudentEnrollmentViewModel> listOfEnrolledCourses = null; try { var enrollmentModel = new StudentEnrollmentsModel(); studentRecord = enrollmentModel.GetStudentRecord(contextUserName); if (studentRecord == null) { ViewBag.Message = "our records show that you're not enrolled in any classes.."; return View("Error"); } // TO DO: // Find a more elegant way to do this // probably move it to the service. listOfEnrolledCourses = new List<StudentEnrollmentViewModel>(); foreach (var item in studentRecord.StudentCourseEnrollments) { listOfEnrolledCourses.Add(new StudentEnrollmentViewModel { Course = m_contextCoursesService.GetCourse(item.CourseId), EnrollmentInfo = item }); } } catch (Exception ex) { ViewBag.Message = ex.Message; return View("Error"); } return View(listOfEnrolledCourses); }
public EnrollmentService() { m_contextEnrollment = new StudentEnrollmentsModel(); }