public ActionResult Edit(EditUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string errorMessage = "Sorry, we were unable to edit your account.";

            try
            {
                int    userId;
                string userLogin;

                if (model.IsAdminEdit)
                {
                    userId    = model.UserId;
                    userLogin = model.Email;

                    if (model.IsInactiveUser && Roles.IsUserInRole(userLogin, "ActiveUser"))
                    {
                        Roles.RemoveUserFromRole(userLogin, "ActiveUser");
                    }
                    else if (!Roles.IsUserInRole(userLogin, "ActiveUser"))
                    {
                        Roles.AddUserToRole(userLogin, "ActiveUser");
                    }
                }
                else
                {
                    userId    = WebSecurity.CurrentUserId;
                    userLogin = WebSecurity.CurrentUserName;
                }

                if (model.Password != null)
                {
                    // Change password
                    try
                    {
                        string tempToken = WebSecurity.GeneratePasswordResetToken(userLogin);
                        WebSecurity.ResetPassword(tempToken, model.Password);
                        ViewBag.Message = model.IsAdminEdit ? "The password has been changed. " :
                                          "Your password has been changed. ";
                    }
                    catch
                    {
                        ViewBag.Message = model.IsAdminEdit ? "Unable to change the password. " :
                                          "We were unable to change your password. ";
                    }
                }

                ApplicationUser user = model.ToApplicationUser();
                user.ApplicationUserId = WebSecurity.GetUserId(userLogin);
                user.Email             = userLogin;

                ResultEnum result = userService.UpdateApplicationUser(user);
                switch (result)
                {
                case ResultEnum.Success:
                    ViewBag.Message += model.IsAdminEdit ? "The account details have been updated." :
                                       "Your account details have been updated.";

                    return(View(model));

                case ResultEnum.Fail:
                    ModelState.AddModelError("ErrorMessage", errorMessage);
                    return(View(model));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("ErrorMessage", errorMessage);
                return(View(model));
            }

            return(View(model));
        }