예제 #1
0
        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));
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
 public ActionResult Details(int id)
 {
     using (EnrollmentsManager)
     {
         using (StudManager)
         {
             using (PeopleManager)
             {
                 using (CoursesManager)
                 {
                     using (SemestersManager)
                     {
                         var disp = Mapper.Map <vmEnrollment>(EnrollmentsManager.GetEnrollmentbyID(id));
                         if (disp != null)
                         {
                             disp.Student        = Mapper.Map <vmStudent>(StudManager.GetStudentbyID(disp.StudentID));
                             disp.Student.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(disp.Student.PersonID));
                             disp.Course         = Mapper.Map <vmCourse>(CoursesManager.GetCoursebyID(disp.CourseID));
                             disp.Semester       = Mapper.Map <vmSemester>(SemestersManager.GetSemesterbyID(disp.SemesterID));
                         }
                         else
                         {
                             disp = new vmEnrollment();
                             ModelState.AddModelError("", "Failed to load details for requested object");
                         }
                         return(View(disp));
                     }
                 }
             }
         }
     }
 }
예제 #3
0
        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));
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
 public ActionResult Delete(vmEnrollment enroll)
 {
     try
     {
         using (EnrollmentsManager)
         {
             var item    = EnrollmentsManager.GetEnrollmentbyID(enroll.ID);
             var success = EnrollmentsManager.RemoveEnrollment(item);
             if (success)
             {
                 return(RedirectToAction("Index"));
             }
             throw new DataException("Enable to delete enrollment # " + enroll.ID + ". Please try again.");
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(enroll));
 }
예제 #5
0
 public ActionResult Edit(vmEnrollment enroll)
 {
     try
     {
         using (EnrollmentsManager)
         {
             var item = EnrollmentsManager.GetEnrollmentbyID(enroll.ID);
             item.Grade = enroll.Grade;
             var success = EnrollmentsManager.UpdateEnrollment(item);
             if (success)
             {
                 return(RedirectToAction("Index"));
             }
             throw new DataException("Failed to save enrollment #" + enroll.ID + ". Please try again");
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(enroll));
 }