Exemplo n.º 1
0
        public ActionResult Create(CreateStudentViewModel studentModel, string selectedUser, string lastName,
                                   string firstMidName, string email)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var student = new Student();

                    //Establish the student data
                    student.UserName = selectedUser;
                    student.LastName = lastName;
                    student.FirstMidName = firstMidName;
                    student.Email = email;
                    student.EnrollmentDate = DateTime.Now;

                    db.Students.Add(student); //inputs student data into database (is not saved yet)
                    db.SaveChanges(); //saves the student to database

                    MembershipUser user = Membership.GetUser(student.UserName); //gets the actual user
                    Roles.AddUserToRole(user.UserName, "Student"); //takes the user and sets role to student

                    // assigns Student data to the profile of the user (so the user is associated with this specified Student data)
                    CustomProfile profile = CustomProfile.GetUserProfile(student.UserName);
                    profile.FilledStudentInfo = "yes";
                    profile.Save();

                    return RedirectToAction("Index");
                }
            }
            catch (DataException)
            {
                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("",
                                         "Saving failed for some reason.  You may have left some information blank.  Please try again (several times in several different ways if possible (i.e. try using a different computer) - if the problem persists see your system administrator.");
            }

            // This code block is here to allow the page to render in case we get a DataException and have to re-display the screen.
            MembershipUserCollection users = Membership.GetAllUsers();
            var model = new CreateStudentViewModel
                            {
                                Users = users.OfType<MembershipUser>().Select(x => new SelectListItem
                                                                                       {
                                                                                           Value = x.UserName,
                                                                                           Text = x.UserName,
                                                                                       })
                            };
            return View(model);
        }
 public string IsPresent(Student student, int attendanceDay)
 {
     return Attendances.Single(a => a.StudentID == student.StudentID && a.AttendanceDay == attendanceDay).Present
                ? PaulSchoolResource.Present_Text
                : PaulSchoolResource.Absent_Text;
 }
Exemplo n.º 3
0
 public ActionResult Edit(Student student)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(student).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         ModelState.AddModelError("",
                                  "Saving failed for some reason. Please try again (several times in several different ways if possible (i.e. try using a different computer) - if the problem persists see your system administrator.");
     }
     return View(student);
 }
Exemplo n.º 4
0
 private void CreateEnrollmentAttendanceAndNotificationData(Course course, Student thisStudent)
 {
     course.SeatsTaken = course.SeatsTaken + 1;
     BuildEnrollmentData(course, thisStudent);
     BuildAttendanceData(course, thisStudent);
     BuildNotificationData(course, thisStudent);
     db.SaveChanges();
 }
Exemplo n.º 5
0
 private void CreatesInstructorDataAndAssignsRole(Student currentUser)
 {
     var newInstructor = new Instructor
         {
             UserName = User.Identity.Name,
             EnrollmentDate = DateTime.Now,
             LastName = currentUser.LastName,
             FirstMidName = currentUser.FirstMidName,
             Email = currentUser.Email
         };
     db.Instructors.Add(newInstructor);
     db.SaveChanges();
     if (!User.IsInRole("Instructor"))
     {
         Roles.AddUserToRole(User.Identity.Name, "Instructor");
     }
 }
Exemplo n.º 6
0
 private void BuildEnrollmentData(Course course, Student thisStudent)
 {
     bool hasPaid = course.Cost == 0;
     var newEnrollment = new Enrollment
         {
             CourseID = course.CourseID,
             StudentID = thisStudent.StudentID,
             Grade = "incomplete",
             Paid = hasPaid
         };
     db.Enrollments.Add(newEnrollment);
 }
Exemplo n.º 7
0
 private void BuildNotificationData(Course course, Student thisStudent)
 {
     var newNotification = new Notification
         {
             Time = DateTime.Now,
             Details =
                 "A Student by the name of " + thisStudent.FirstMidName + " " + thisStudent.LastName
                 + " has signed up for " + course.Title,
             Link = Url.Action("Details", "Student", new { id = thisStudent.StudentID }),
             ViewableBy = "Admin",
             Complete = false
         };
     db.Notification.Add(newNotification);
 }
Exemplo n.º 8
0
        /// <summary>
        /// The update students table with updated profile data from register model.
        /// </summary>
        /// <param name="profile">
        /// The model.
        /// </param>
        /// <param name="isStudent">
        /// The is student.
        /// </param>
        private void UpdateStudentsTableWithUpdatedProfileDataFromRegisterModel(CustomProfile profile, Student isStudent)
        {
            isStudent.LastName = profile.LastName;
            isStudent.FirstMidName = profile.FirstMidName;
            isStudent.StreetAddress = profile.StreetAddress;
            isStudent.City = profile.City;
            isStudent.State = profile.State;
            isStudent.ZipCode = profile.ZipCode;
            isStudent.Phone = profile.Phone;
            isStudent.DateOfBirth = profile.DateOfBirth;
            isStudent.ParishAffiliation = profile.ParishAffiliation;
            isStudent.MinistryInvolvement = profile.MinistryInvolvement;
            MembershipUser u = Membership.GetUser(User.Identity.Name);

            // needed to get email for isStudent.Email = u.Email;
            if (u != null)
            {
                isStudent.Email = u.Email;
            }

            db.SaveChanges();
        }
Exemplo n.º 9
0
 private void BuildAttendanceData(Course course, Student thisStudent)
 {
     for (int i = 0; i < course.AttendingDays; i++)
     {
         // Adds attendance rows for every day needed in the attendance table
         var newAttendance = new Attendance
             {
                 CourseID = course.CourseID,
                 StudentID = thisStudent.StudentID,
                 AttendanceDay = i + 1,
                 Present = true
             };
         db.Attendance.Add(newAttendance);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// The create student table data with new profile data and assign student role.
 /// </summary>
 /// <param name="profile">
 /// The model.
 /// </param>
 /// <param name="user">
 /// The user.
 ///  </param>
 private void CreateStudentTableDataWithNewProfileDataAndAssignStudentRole(CustomProfile profile,
                                                                           MembershipUser user)
 {
     var newStudent = new Student
         {
             LastName = profile.LastName,
             FirstMidName = profile.FirstMidName,
             Email = user.Email,
             UserName = profile.UserName,
             EnrollmentDate = DateTime.Now,
             StreetAddress = profile.StreetAddress,
             City = profile.City,
             State = profile.State,
             ZipCode = profile.ZipCode,
             Phone = profile.Phone,
             DateOfBirth = profile.DateOfBirth,
             ParishAffiliation = profile.ParishAffiliation,
             MinistryInvolvement = profile.MinistryInvolvement
         };
     db.Students.Add(newStudent);
     db.SaveChanges();
     if (!User.IsInRole("Student"))
     {
         Roles.AddUserToRole(profile.UserName, "Student");
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// The update students table with updated profile data from profile view model.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="isStudent">
        /// The is student.
        /// </param>
        private void UpdateStudentsTableWithUpdatedProfileDataFromProfileViewModel(
            ProfileViewModel model, Student isStudent, string state)
        {
            isStudent.LastName = model.LastName;
            isStudent.FirstMidName = model.FirstMidName;
            isStudent.StreetAddress = model.StreetAddress;
            isStudent.City = model.City;
            isStudent.State = state;
            isStudent.ZipCode = model.ZipCode;
            isStudent.Phone = model.Phone;
            isStudent.DateOfBirth = model.DateOfBirth;
            isStudent.ParishAffiliation = model.ParishAffiliation;
            isStudent.MinistryInvolvement = model.MinistryInvolvement;
            MembershipUser u = Membership.GetUser(User.Identity.Name);

            // needed to get email for isStudent.Email = u.Email;
            if (u != null)
            {
                isStudent.Email = u.Email;
            }

            db.SaveChanges();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates Student in Student table from ProfileViewModel
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        private void CreateStudentInStudentTableFromProfileViewModel(ProfileViewModel model, string state)
        {
            MembershipUser u = Membership.GetUser(User.Identity.Name); // needed to get email for Email = u.Email;
            if (u == null)
            {
                throw new ArgumentNullException("model");
            }

            var newStudent = new Student
                {
                    LastName = model.LastName,
                    FirstMidName = model.FirstMidName,
                    Email = u.Email,
                    UserName = User.Identity.Name,
                    EnrollmentDate = DateTime.Now,
                    StreetAddress = model.StreetAddress,
                    City = model.City,
                    State = state,
                    ZipCode = model.ZipCode,
                    Phone = model.Phone,
                    DateOfBirth = model.DateOfBirth,
                    ParishAffiliation = model.ParishAffiliation,
                    MinistryInvolvement = model.MinistryInvolvement
                };
            db.Students.Add(newStudent);
            db.SaveChanges();
            if (!User.IsInRole("Student"))
            {
                Roles.AddUserToRole(User.Identity.Name, "Student");
            }
        }
 private void BuildNewNotificationAndAddToDb(InstructorApplication instructorApplication, Student thisUser)
 {
     Notification newNotification = BuildNewNotification(instructorApplication, thisUser);
     db.Notification.Add(newNotification);
 }
 private Notification BuildNewNotification(InstructorApplication instructorApplication, Student thisUser)
 {
     var newNotification = new Notification
                               {
                                   Time = DateTime.Now,
                                   Details =
                                       "A user by the name of " + thisUser.FirstMidName + " " + thisUser.LastName
                                       + " has applied to become an Instructor",
                                   Link =
                                       Url.Action(
                                           "Details",
                                           "InstructorApplication",
                                           new {id = instructorApplication.InstructorApplicationID}),
                                   ViewableBy = "Admin",
                                   Complete = false
                               };
     return newNotification;
 }
 private InstructorApplication BuildNewInstructorApplicationAndAddToDb(
     InstructorApplicationViewModel applicationFromView, Student thisUser)
 {
     InstructorApplication instructorApplication = BuildNewInstructorApplication(applicationFromView, thisUser);
     db.InstructorApplication.Add(instructorApplication);
     return instructorApplication;
 }
 private static InstructorApplication BuildNewInstructorApplication(
     InstructorApplicationViewModel applicationFromView, Student thisUser)
 {
     var educationList = new List<EducationalBackground>();
     foreach (EducationalBackGround educate in applicationFromView.EducationalBackgrounds)
     {
         var education = new EducationalBackground
                             {
                                 YearReceived = educate.YearReceived,
                                 Degree = educate.Degree,
                                 AreaOfStudy = educate.AreaOfStudy,
                                 UniversityOrCollege = educate.UniversityOrCollege
                             };
         educationList.Add(education);
     }
     var instructorApplication = new InstructorApplication
                                     {
                                         StudentID = thisUser.StudentID,
                                         EducationalBackground = new List<EducationalBackground>(),
                                         Experience = applicationFromView.Experience,
                                         WillingToTravel = applicationFromView.WillingToTravel,
                                         Approved = false
                                     };
     instructorApplication.EducationalBackground.AddRange(educationList);
     return instructorApplication;
 }