コード例 #1
0
        public IActionResult Edit()
        {
            AccountEditViewModel viewModel = new AccountEditViewModel
            {
                Message = (string)TempData["Message"]
            };

            return(View(viewModel));
        }
コード例 #2
0
        public IActionResult Edit(AccountEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (authenticationBusinessLogic.VerifyPassword(ApplicationUser.Password, viewModel.OldPassword))
            {
                ModelState.AddModelError(nameof(AccountEditViewModel.OldPassword), "Old password is incorrect.");

                return(View(viewModel));
            }

            ApplicationUser.Password = authenticationBusinessLogic.HashPassword(viewModel.NewPassword);
            ApplicationUser.Save(Database.Connection);

            TempData["Message"] = "Account saved successfully.";

            return(RedirectToAction(nameof(Edit)));
        }