示例#1
0
 public vmEnrollment()
 {
     Course    = new vmCourse();
     Student   = new vmStudent();
     Semester  = new vmSemester();
     Semesters = new List <Semester>();
     Courses   = new List <Course>();
     Students  = new Dictionary <int, string>();
 }
示例#2
0
 public vmEnrollment()
 {
     Course = new vmCourse();
     Student = new vmStudent();
     Semester = new vmSemester();
     Semesters = new List<Semester>();
     Courses = new List<Course>();
     Students = new Dictionary<int, string>();
 }
 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);
 }
 public ActionResult Delete(int id)
 {
     using (PeopleManager)
     {
         using (StudManager)
         {
             var item = StudManager.GetStudentbyID(id);
             var disp = Mapper.Map<vmStudent>(item);
             if (disp != null)
             {
                 disp.Person = new vmPerson();
                 disp.Person = Mapper.Map<vmPerson>(PeopleManager.GetPersonbyID(disp.PersonID));
                 return View(disp);
             }
             else
             {
                 disp = new vmStudent();
                 ModelState.AddModelError("", "Failed to load details for requested item.");
             }
             return View(disp);
         }
     }
 }
 public ActionResult Create()
 {
     var disp = new vmStudent();
     return View(disp);
 }
 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);
 }
 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);
 }