/// <summary> /// The save new profile. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="profile"> /// The profile. /// </param> private static void SaveNewProfile(RegisterModel model, CustomProfile profile) { profile.LastName = model.LastName; profile.FirstMidName = model.FirstMidName; profile.StreetAddress = model.StreetAddress; profile.City = model.City; profile.State = model.State; profile.ZipCode = model.ZipCode; profile.Phone = model.Phone; profile.DateOfBirth = model.DateOfBirth; profile.ParishAffiliation = model.ParishAffiliation; profile.MinistryInvolvement = model.MinistryInvolvement; profile.Save(); }
/// <summary> /// The set default state of user. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="profile"> /// The profile. /// </param> private static void SetDefaultStateOfUser(RegisterModel model, CustomProfile profile) { profile.IsTeacher = "no"; profile.FilledStudentInfo = "no"; profile.Save(); Roles.AddUserToRole(model.UserName, "Default"); // Adds student to the "Default" role so we can force them to become a "Student" role. }
public ActionResult Register(RegisterViewModel viewModel, int stateInt) { string stringStateAbbreviation = StateList.First(m => m.Value == stateInt.ToString()).Text; if (ModelState.IsValid) { var model = new RegisterModel { UserName = viewModel.UserName, Email = viewModel.Email, FirstMidName = viewModel.FirstMidName, LastName = viewModel.LastName, StreetAddress = viewModel.StreetAddress, City = viewModel.City, State = stringStateAbbreviation, ZipCode = viewModel.ZipCode, Phone = viewModel.Phone, DateOfBirth = viewModel.DateOfBirth, ParishAffiliation = viewModel.ParishAffiliation, MinistryInvolvement = viewModel.MinistryInvolvement, Password = viewModel.Password, ConfirmPassword = viewModel.ConfirmPassword }; // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser( model.UserName, model.Password, model.Email, null, null, false, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); CustomProfile profile = CustomProfile.GetUserProfile(model.UserName); SetDefaultStateOfUser(model, profile); SaveNewProfile(model, profile); MembershipUser user = Membership.GetUser(model.UserName, false); AccountMembershipService.SendConfirmationEmail(user); return RedirectToAction("confirmation"); } ModelState.AddModelError(string.Empty, ErrorCodeToString(createStatus)); } // If we got this far, something failed, redisplay form viewModel.State = StateList; return View(viewModel); }