Пример #1
0
        public async Task <IActionResult> Edit(string id, string password, string returnUrl = "", int page = 1, string sort = "")
        {
            AppUser user = await userManager.FindByIdAsync(id);

            if (user != null)
            {
                IdentityResult validPwd = null;
                if (!string.IsNullOrEmpty(password))
                {
                    validPwd = await passwordValidator.ValidateAsync(userManager, user, password);

                    if (validPwd.Succeeded)
                    {
                        user.PasswordHash = passwordHasher.HashPassword(user, password);
                        IdentityResult result = await userManager.UpdateAsync(user);

                        if (result.Succeeded)
                        {
                            TempData["message"] = $"Запись \"{user.UserName}\" сохранена!";
                            return(RedirectToAction("Index", new { page, sort, currentID = user.Id }));
                        }
                        else
                        {
                            AddErrorsFromResult(result);
                        }
                    }
                    else
                    {
                        AddErrorsFromResult(validPwd);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Введен некорретный пароль!");
                }
            }
            else
            {
                ModelState.AddModelError("", "Пользователь не найден");
            }

            AppUserEditModel editModel = new AppUserEditModel()
            {
                AppUser   = user,
                Page      = page,
                CurrentID = id,
                ReturnUrl = returnUrl,
                Sort      = sort
            };

            return(View(editModel));
        }
Пример #2
0
        // редактирование пользователя
        public async Task <IActionResult> Edit(string Id, string returnUrl = "", int page = 1, string sort = "")
        {
            ViewData["Title"] = "Редактирование данных пользователя";

            AppUser user = await userManager.FindByIdAsync(Id);

            if (user != null)
            {
                AppUserEditModel editModel = new AppUserEditModel()
                {
                    AppUser   = user,
                    Page      = page,
                    CurrentID = Id,
                    ReturnUrl = returnUrl,
                    Sort      = sort
                };
                return(View(editModel));
            }
            else
            {
                ModelState.AddModelError("", "Пользователь не найден");
                return(RedirectToAction("Index", new { page, sort }));
            }
        }