Ejemplo n.º 1
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));
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public ActionResult Index()
 {
     using (EnrollmentsManager)
     {
         using (CoursesManager)
         {
             using (StudManager)
             {
                 using (PeopleManager)
                 {
                     using (SemestersManager)
                     {
                         var disp = Mapper.Map <IEnumerable <vmEnrollment> >(EnrollmentsManager.GetAllEnrollments());
                         foreach (var d in disp)
                         {
                             d.Course         = Mapper.Map <vmCourse>(CoursesManager.GetCoursebyID(d.CourseID));
                             d.Student        = Mapper.Map <vmStudent>(StudManager.GetStudentbyID(d.StudentID));
                             d.Student.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(d.Student.PersonID));
                             d.Semester       = Mapper.Map <vmSemester>(SemestersManager.GetSemesterbyID(d.SemesterID));
                         }
                         return(View(disp));
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public ActionResult Edit(vmCourse course)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (CoursesManager)
                    {
                        var item = CoursesManager.GetCoursebyID(course.ID);
                        item.Credits      = course.Credits;
                        item.DepartmentID = course.DepartmentID;
                        item.Description  = course.Description;
                        item.InstructorID = course.InstructorID;
                        item.TextBookID   = course.TextBookID;
                        item.Title        = course.Title;
                        var success = CoursesManager.UpdateCourse(item);
                        if (success)
                        {
                            return(RedirectToAction("Details", new { id = item.ID }));
                        }
                        throw new DataException("Failed to save " + course.Title + ". Please try again");
                    }
                }
            }
            catch (DataException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            using (DeptManager)
            {
                using (InstManager)
                {
                    using (PeopleManager)
                    {
                        using (TBManager)
                        {
                            course.Departments = DeptManager.GetAllDepartments().ToList();
                            var inst   = InstManager.GetAllInstructors();
                            var people = PeopleManager.GetAllPeople();

                            var instr = from instructor in inst
                                        join person in people on instructor.PersonID equals person.ID
                                        select new KeyValuePair <int, string>(instructor.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName));
                            course.Instructors = instr.ToDictionary(t => t.Key, t => t.Value);
                            course.Textbooks   = TBManager.GetAllTextbooks().ToList();
                        }
                    }
                }
            }
            return(View(course));
        }
Ejemplo n.º 4
0
 public ActionResult Delete(vmCourse course)
 {
     try
     {
         using (CoursesManager)
         {
             var item    = CoursesManager.GetCoursebyID(course.ID);
             var success = CoursesManager.RemoveCourse(item);
             if (success)
             {
                 return(RedirectToAction("Index"));
             }
             throw new DataException();
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
         return(View(course));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            using (DeptManager)
            {
                using (InstManager)
                {
                    using (PeopleManager)
                    {
                        using (TBManager)
                        {
                            using (CoursesManager)
                            {
                                var disp = Mapper.Map <vmCourse>(CoursesManager.GetCoursebyID(id));
                                if (disp != null)
                                {
                                    disp.Departments = DeptManager.GetAllDepartments().ToList();
                                    var inst   = InstManager.GetAllInstructors();
                                    var people = PeopleManager.GetAllPeople();

                                    var instr = from instructor in inst
                                                join person in people on instructor.PersonID equals person.ID
                                                select new KeyValuePair <int, string>(instructor.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName));
                                    disp.Instructors = instr.ToDictionary(t => t.Key, t => t.Value);

                                    disp.Textbooks = TBManager.GetAllTextbooks().ToList();
                                }
                                else
                                {
                                    disp = new vmCourse();
                                    ModelState.AddModelError("", "Failed to load details for requested object");
                                }
                                return(View(disp));
                            }
                        }
                    }
                }
            }
        }