コード例 #1
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();
        }
コード例 #2
0
        // GET: /Account/Profile
        /// <summary>
        /// The update instructors table with updated profile data from profile view model.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="isInstructor">
        /// The is instructor.
        /// </param>
        private void UpdateInstructorsTableWithUpdatedProfileDataFromProfileViewModel(
            ProfileViewModel model, Instructor isInstructor)
        {
            isInstructor.LastName = model.LastName;
            isInstructor.FirstMidName = model.FirstMidName;
            MembershipUser u = Membership.GetUser(User.Identity.Name);

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

            db.SaveChanges();
        }
コード例 #3
0
 /// <summary>
 /// The preload profile view model with current users profile data.
 /// </summary>
 /// <returns>
 /// Returns a ProfileViewModel with the current user's profile data
 /// </returns>
 private ProfileViewModel PreloadProfileViewModelWithCurrentUsersProfileData()
 {
     CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
     var model = new ProfileViewModel
         {
             LastName = profile.LastName,
             FirstMidName = profile.FirstMidName,
             StreetAddress = profile.StreetAddress,
             City = profile.City,
             StateString = profile.State,
             ZipCode = profile.ZipCode,
             Phone = profile.Phone,
             DateOfBirth = profile.DateOfBirth,
             ParishAffiliation = profile.ParishAffiliation,
             MinistryInvolvement = profile.MinistryInvolvement
         };
     return model;
 }
コード例 #4
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");
            }
        }
コード例 #5
0
 /// <summary>
 /// The save new profile data.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 private static void SaveNewProfileData(ProfileViewModel model, string state)
 {
     CustomProfile profile = CustomProfile.GetUserProfile();
     profile.LastName = model.LastName;
     profile.FirstMidName = model.FirstMidName;
     profile.StreetAddress = model.StreetAddress;
     profile.City = model.City;
     profile.State = state;
     profile.ZipCode = model.ZipCode;
     profile.Phone = model.Phone;
     profile.DateOfBirth = model.DateOfBirth;
     profile.ParishAffiliation = model.ParishAffiliation;
     profile.MinistryInvolvement = model.MinistryInvolvement;
     profile.Save();
 }
コード例 #6
0
        public ActionResult ChangeProfile(ProfileViewModel model, int stateInt)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string stringStateAbbreviation = StateList.First(m => m.Value == stateInt.ToString()).Text;
            SaveNewProfileData(model, stringStateAbbreviation);

            // check if already existing on the student table - update the table if needed
            Student isStudent = db.Students.FirstOrDefault(o => o.UserName == User.Identity.Name);
            if (isStudent != null)
            {
                // IF the user already exists in the Student Table . . .
                UpdateStudentsTableWithUpdatedProfileDataFromProfileViewModel(model, isStudent, stringStateAbbreviation);
            }
            else
            {
                // Create student in student table if they have not been there before (everyone needs to be at least a student)
                CreateStudentInStudentTableFromProfileViewModel(model, stringStateAbbreviation);
            }

            // check if already existing on the instructor table - update the table if needed
            Instructor isInstructor = db.Instructors.FirstOrDefault(o => o.UserName == User.Identity.Name);
            if (isInstructor != null)
            {
                // IF the user already exists in the Instructor Table . . .
                UpdateInstructorsTableWithUpdatedProfileDataFromProfileViewModel(model, isInstructor);
            }

            return RedirectToAction("Profile");
        }