public ActionResult Create() { using (EnrollmentsManager) { using (CoursesManager) { using (StudManager) { using (PeopleManager) { using (SemestersManager) { var disp = new vmEnrollment(); disp.Courses = CoursesManager.GetAllCourses().ToList(); disp.Semesters = SemestersManager.GetAllSemesters().ToList(); var students = StudManager.GetAllStudents(); var people = PeopleManager.GetAllPeople(); var studs = from student in students join person in people on student.PersonID equals person.ID select new KeyValuePair <int, string>(student.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName)); disp.Students = studs.ToDictionary(t => t.Key, t => t.Value); return(View(disp)); } } } } } }
public ActionResult Create(vmEnrollment enroll) { try { if (ModelState.IsValid) { using (EnrollmentsManager) { var item = Mapper.Map <Enrollment>(enroll); var success = EnrollmentsManager.AddEnrollment(item); if (success) { return(RedirectToAction("Index")); } throw new DataException("Failed to save enrollment #" + enroll.ID + ". Please try again"); } } } catch (DataException ex) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", ex.Message); } using (EnrollmentsManager) { using (CoursesManager) { using (StudManager) { using (PeopleManager) { using (SemestersManager) { enroll.Courses = CoursesManager.GetAllCourses().ToList(); enroll.Semesters = SemestersManager.GetAllSemesters().ToList(); var students = StudManager.GetAllStudents(); var people = PeopleManager.GetAllPeople(); var studs = from student in students join person in people on student.PersonID equals person.ID select new KeyValuePair <int, string>(student.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName)); enroll.Students = studs.ToDictionary(t => t.Key, t => t.Value); return(View(enroll)); } } } } } }
public ViewResult Index() { using (StudManager) { using (PeopleManager) { var items = StudManager.GetAllStudents(); var disp = Mapper.Map <IEnumerable <vmStudent> >(items); foreach (var d in disp) { d.Person = new vmPerson(); d.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(d.PersonID)); } return(View(disp)); } } }