Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 // GET: /Account/Register
 /// <summary>
 /// Account registration
 /// </summary>
 /// <returns>
 /// Account registration View
 /// </returns>
 public ActionResult Register()
 {
     var model = new RegisterViewModel();
     model.State = StateList;
     model.StateInt = 44;
     return View(model);
 }