Пример #1
0
        public async Task <IActionResult> EditUser(EditUserModelView model)
        {
            ApplicationUser user = await userManager.FindByIdAsync(model.ID);

            if (user != null)
            {
                user.UserName = model.UserName;
                user.Email    = model.Email;
                user.Gender   = model.Gender;

                var result = await userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(RedirectToAction("UserList"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
                return(View(model));
            }
            else
            {
                ViewBag.Message = $"User Id {model.ID} is not found";
                return(View("NotFound"));
            }
        }
Пример #2
0
        public async Task <IActionResult> EditUser(string id)
        {
            ApplicationUser user = await userManager.FindByIdAsync(id);

            if (user != null)
            {
                var userRole = await userManager.GetRolesAsync(user);

                var userClaims = await userManager.GetClaimsAsync(user);

                EditUserModelView model = new EditUserModelView
                {
                    ID        = user.Id,
                    Email     = user.Email,
                    UserName  = user.UserName,
                    Gender    = user.Gender,
                    UserRoles = userRole,
                    UserClaim = userClaims.Select(y => y.Value).ToList()
                };
                return(View(model));
            }
            else
            {
                ViewBag.Message = $"User Id {id} is not found";
                return(View("NotFound"));
            }
        }