Exemple #1
0
 public ActionResult Edit(int id)
 {
     using (DeptManager)
     {
         using (InstManager)
         {
             using (PeopleManager)
             {
                 var item = InstManager.GetInstructorbyID(id);
                 var disp = Mapper.Map <vmInstructor>(item);
                 if (disp != null)
                 {
                     disp.Person      = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(item.PersonID));
                     disp.Departments = DeptManager.GetAllDepartments().OrderBy(d => d.Name).ToList();
                 }
                 else
                 {
                     disp = new vmInstructor();
                     ModelState.AddModelError("", "Failed to load details fo requested item.");
                 }
                 return(View(disp));
             }
         }
     }
 }
        public ActionResult Create()
        {
            var disp = new vmCourse();

            using (DeptManager)
            {
                using (InstManager)
                {
                    using (PeopleManager)
                    {
                        using (TBManager)
                        {
                            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();
                            return(View(disp));
                        }
                    }
                }
            }
        }
Exemple #3
0
 public ActionResult Index()
 {
     using (DeptManager)
     {
         var disp = new vmInstructorSearch();
         disp.Departments = DeptManager.GetAllDepartments().ToList();
         return(View(disp));
     }
 }
Exemple #4
0
 public ActionResult Create()
 {
     using (DeptManager)
     {
         var disp = new vmInstructor();
         disp.Departments = DeptManager.GetAllDepartments().OrderBy(d => d.Name).ToList();
         return(View(disp));
     }
 }
Exemple #5
0
 public ActionResult Index()
 {
     using (DeptManager)
     {
         var items = DeptManager.GetAllDepartments().OrderBy(d => d.Name);
         var disp  = Mapper.Map <IEnumerable <vmDepartment> >(items);
         return(View(disp));
     }
 }
        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));
        }
Exemple #7
0
 public ActionResult Edit(vmInstructor inst)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (InstManager)
             {
                 using (PeopleManager)
                 {
                     var person = PeopleManager.GetPersonbyID(inst.PersonID);
                     person.FirstMidName = inst.Person.FirstMidName;
                     person.LastName     = inst.Person.LastName;
                     var success = PeopleManager.UpdatePerson(person);
                     if (success)
                     {
                         var item = InstManager.GetInstructorbyID(inst.ID);
                         item.PersonID     = person.ID;
                         item.HireDate     = inst.HireDate;
                         item.DepartmentID = inst.DepartmentID;
                         success           = InstManager.UpdateInstructor(item);
                         if (success)
                         {
                             return(RedirectToAction("Details", new { id = item.ID }));
                         }
                         else
                         {
                             throw new DataException("Unable to save Instructor. Please try again.");
                         }
                     }
                     else
                     {
                         throw new DataException("Unable to save person. Please try again.");
                     }
                 }
             }
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     using (DeptManager)
     {
         inst.Departments = DeptManager.GetAllDepartments().OrderBy(d => d.Name).ToList();
     }
     return(View(inst));
 }
Exemple #8
0
 public ActionResult Create(vmInstructor inst)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (InstManager)
             {
                 using (PeopleManager)
                 {
                     var person  = Mapper.Map <Person>(inst.Person);
                     var success = PeopleManager.AddPerson(person);
                     if (success)
                     {
                         var item = Mapper.Map <Instructor>(inst);
                         item.PersonID = person.ID;
                         success       = InstManager.AddInstructor(item);
                         if (success)
                         {
                             return(RedirectToAction("Details", new { id = item.ID }));
                         }
                         else
                         {
                             throw new DataException("Unable to save Instructor. Please try again.");
                         }
                     }
                     else
                     {
                         throw new DataException("Unable to save person. Please try again.");
                     }
                 }
             }
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     using (DeptManager)
     {
         inst.Departments = DeptManager.GetAllDepartments().OrderBy(d => d.Name).ToList();
     }
     return(View(inst));
 }
        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));
                            }
                        }
                    }
                }
            }
        }