예제 #1
0
        //
        // GET: /Instructor/Delete/5

        public ActionResult Delete(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.Department = Mapper.Map <vmDepartment>(DeptManager.GetDepartmentbyID(item.DepartmentID));
                        }
                        else
                        {
                            disp = new vmInstructor();
                            ModelState.AddModelError("", "Failed to load details for requested object");
                        }
                        return(View(disp));
                    }
                }
            }
        }
예제 #2
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));
             }
         }
     }
 }
예제 #3
0
 public ActionResult Create()
 {
     using (DeptManager)
     {
         var disp = new vmInstructor();
         disp.Departments = DeptManager.GetAllDepartments().OrderBy(d => d.Name).ToList();
         return(View(disp));
     }
 }
예제 #4
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));
 }
예제 #5
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));
 }
예제 #6
0
 public ActionResult Delete(vmInstructor inst)
 {
     try
     {
         using (InstManager)
         {
             var item    = InstManager.GetInstructorbyID(inst.ID);
             var success = InstManager.RemoveInstructor(item);
             if (success)
             {
                 return(RedirectToAction("Index"));
             }
             throw new DataException("Enable to delete intructor " + inst.Person.FullName + ". Please try again.");
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(inst));
 }
예제 #7
0
 public ActionResult Details(int id)
 {
     using (DeptManager)
     {
         using (InstManager)
         {
             using (PeopleManager)
             {
                 using (TBManager)
                 {
                     var item = InstManager.GetInstructorbyID(id);
                     var disp = Mapper.Map <vmInstructor>(item);
                     if (disp != null)
                     {
                         disp.Person     = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(item.PersonID));
                         disp.Department = Mapper.Map <vmDepartment>(DeptManager.GetDepartmentbyID(item.DepartmentID));
                         disp.Textbooks  = TBManager.GetAllTextbooks().ToList();
                         var books = InstManager.FindInstructorBooks(i => i.InstructorID == id).Select(i => i.TextBookID);
                         foreach (var b in books)
                         {
                             var t = TBManager.GetTextbookbyID(b);
                             if (t != null)
                             {
                                 disp.InstructorTextbooks.Add(Mapper.Map <vmTextbook>(t));
                             }
                         }
                     }
                     else
                     {
                         disp = new vmInstructor();
                         ModelState.AddModelError("", "Failed to load details for requested item.");
                     }
                     return(View(disp));
                 }
             }
         }
     }
 }