예제 #1
0
 public ActionResult Edit(vmStudent student)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (PeopleManager)
             {
                 using (StudManager)
                 {
                     var person = PeopleManager.GetPersonbyID(student.PersonID);
                     person.FirstMidName = student.Person.FirstMidName;
                     person.LastName     = student.Person.LastName;
                     var success = PeopleManager.UpdatePerson(person);
                     if (success)
                     {
                         var stu = StudManager.GetStudentbyID(student.ID);
                         stu.EnrollmentDate = student.EnrollmentDate;
                         success            = StudManager.UpdateStudent(stu);
                         if (success)
                         {
                             return(RedirectToAction("Details", new { id = student.ID }));
                         }
                         else
                         {
                             throw new DataException("Unable to save Student. Please try again.");
                         }
                     }
                     else
                     {
                         throw new DataException("Unable to save person. Please try again.");
                     }
                 }
             }
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(student));
 }
예제 #2
0
 public ActionResult Details(int id)
 {
     using (PeopleManager)
     {
         using (StudManager)
         {
             var item = StudManager.GetStudentbyID(id);
             var disp = Mapper.Map <vmStudent>(item);
             if (disp != null)
             {
                 disp.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(disp.PersonID));
             }
             else
             {
                 disp = new vmStudent();
                 ModelState.AddModelError("", "Failed to load details for requested item.");
             }
             return(View(disp));
         }
     }
 }
예제 #3
0
 public ActionResult Delete(vmStudent student)
 {
     try
     {
         using (StudManager)
         {
             var stu     = StudManager.GetStudentbyID(student.ID);
             var success = StudManager.RemoveStudent(stu);
             if (success)
             {
                 return(RedirectToAction("Index"));
             }
             throw new DataException("Enable to delete intructor " + student.Person.FullName + ". Please try again.");
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(student));
 }
예제 #4
0
 public ActionResult Create(vmStudent student)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (PeopleManager)
             {
                 using (StudManager)
                 {
                     var p       = Mapper.Map <Person>(student.Person);
                     var success = PeopleManager.AddPerson(p);
                     if (success)
                     {
                         var s = Mapper.Map <Student>(student);
                         s.PersonID = p.ID;
                         success    = StudManager.AddStudent(s);
                         if (success)
                         {
                             return(RedirectToAction("Details", new { id = s.ID }));
                         }
                         else
                         {
                             throw new DataException("Unable to save Student. Please try again.");
                         }
                     }
                     else
                     {
                         throw new DataException("Unable to save person. Please try again.");
                     }
                 }
             }
         }
     }
     catch (DataException ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return(View(student));
 }
예제 #5
0
        public ActionResult Create()
        {
            var disp = new vmStudent();

            return(View(disp));
        }