public async Task <IActionResult> Register(UserWithRoleVM model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser {
                    UserName = model.UserName
                };
                // добавляем пользователя
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await UpdateUserRoles(user, model.UserRoles.ToList());

                    return(RedirectToAction("UsersList"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
        public IActionResult Register()
        {
            UserWithRoleVM model = new UserWithRoleVM
            {
                AllRoles = _roleManager.Roles.ToList()
            };

            return(View("CreateUser", model));
        }
        public async Task <ActionResult> Edit(string id)
        {
            ApplicationUser user = await _userManager.FindByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }
            UserWithRoleVM model = new UserWithRoleVM
            {
                UserId    = user.Id,
                UserName  = user.UserName,
                UserRoles = _userManager.GetRolesAsync(user).Result,
                AllRoles  = _roleManager.Roles.ToList()
            };

            return(View("EditUser", model));
        }
        public async Task <IActionResult> Edit(string userId)
        {
            // получаем пользователя
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }
            var model = new UserWithRoleVM()
            {
                UserId    = user.Id,
                UserName  = user.UserName,
                UserRoles = await _userManager.GetRolesAsync(user),
                AllRoles  = _roleManager.Roles.ToList()
            };

            return(View(model));
        }