Example #1
0
        public ActionResult ChangeEmail(EditEmailViewModel viewModel)
        {
            // model state checks out
            if (ModelState.IsValid)
            {
                // username and password check out
                if (Membership.ValidateUser(viewModel.CurrentEmail, viewModel.Password))
                {

                    var toUpdate = _serviceLayer.GetUserProfile(viewModel.UserId);
                    toUpdate.Email = viewModel.NewEmail;

                    // if update successfull
                    if (_serviceLayer.UpdateUserProfile(toUpdate))
                    {
                        // logout and back in unobtrusively to refresh context
                        _security.Logout();
                        _security.Login(viewModel.NewEmail, viewModel.Password);
                        return RedirectToAction("Manage", new { message = ManageMessageId.ChangeEmailSuccess });
                    }
                    else
                    {
                        Util.MapValidationErrors(_serviceLayer.ValidationDic, this.ModelState);
                        return View(viewModel);
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", "Incorrect Password");
                    return View(viewModel);
                }
            }
            else
            {
                return View(viewModel);
            }
        }
Example #2
0
        public ActionResult ChangeEmail()
        {
            // get user profile
            var raw = _serviceLayer.GetUserProfile(_security.GetUserId(User.Identity.Name));
            // create view model
            EditEmailViewModel viewModel = new EditEmailViewModel();
            viewModel.UserId = raw.UserId;
            viewModel.CurrentEmail = raw.Email;

            return View(viewModel);
        }