// GET: /Profile/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            this.ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess
                    ? "Your password has been changed."
                    : message == ManageMessageId.SetPasswordSuccess
                          ? "Your password has been set."
                          : message == ManageMessageId.SetTwoFactorSuccess
                                ? "Your two-factor authentication provider has been set."
                                : message == ManageMessageId.Error
                                      ? "An error has occurred."
                                      : message == ManageMessageId.EditProfileSuccess
                                            ? "Your profile has been edited."
                                            : "";

            var userId = this.User.Identity.GetUserId();
            var model = new ProfileViewModel
                {
                    HasPassword = this.HasPassword(),
                    PhoneNumber = await this.UserManager.GetPhoneNumberAsync(userId),
                    TwoFactor = await this.UserManager.GetTwoFactorEnabledAsync(userId),
                    Logins = await this.UserManager.GetLoginsAsync(userId),
                    BrowserRemembered = await this.AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                };

            var user = this.Data.Users.GetAll().FirstOrDefault(u => u.Id == userId);
            if (user == null)
            {
                return this.View(model);
            }

            model.EditProfileViewModel = new EditProfileViewModel();
            model.EditProfileViewModel.Email = user.Email;
            model.EditProfileViewModel.FirstName = user.FirstName ?? string.Empty;
            model.EditProfileViewModel.LastName = user.LastName ?? string.Empty;

            return this.View(model);
        }
 public async Task<ActionResult> ChangePassword(ProfileViewModel model)
 {
     if (!this.ModelState.IsValid)
     {
         return this.View(model);
     }
     var result =
         await
         this.UserManager.ChangePasswordAsync(
             this.User.Identity.GetUserId(),
             model.ChangePasswordViewModel.OldPassword,
             model.ChangePasswordViewModel.NewPassword);
     if (result.Succeeded)
     {
         var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());
         if (user != null)
         {
             await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return this.RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     }
     this.AddErrors(result);
     return this.View(model);
 }
        public async Task<ActionResult> SetPassword(ProfileViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var result =
                    await
                    this.UserManager.AddPasswordAsync(
                        this.User.Identity.GetUserId(),
                        model.SetPasswordViewModel.NewPassword);
                if (result.Succeeded)
                {
                    var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());
                    if (user != null)
                    {
                        await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    }
                    return this.RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess });
                }
                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }
        public ActionResult EditProfile(ProfileViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.RedirectToAction("Index");
            }

            var userId = this.User.Identity.GetUserId();
            var user = this.Data.Users.GetAll().FirstOrDefault(u => u.Id == userId);
            if (user == null)
            {
                return this.RedirectToAction("Index");
            }

            user.Email = model.EditProfileViewModel.Email;
            user.FirstName = model.EditProfileViewModel.FirstName;
            user.LastName = model.EditProfileViewModel.LastName;

            this.Data.SaveChanges();

            return this.RedirectToAction("Index", new { Message = ManageMessageId.EditProfileSuccess });
        }