Exemple #1
0
        public async Task <IActionResult> AddRoles(string UserId)
        {
            var userid = await _userManager.FindByIdAsync(UserId);

            var GetUserData = new UserManagementRoleViewModel
            {
                UserId = userid.Id,
                Email  = userid.Email,
                Roles  = new SelectList(_roleManager.Roles.OrderBy(o => o.Name))
            };

            return(View(GetUserData));
        }
Exemple #2
0
        public async Task <IActionResult> AddRoles(UserManagementRoleViewModel urm)
        {
            var user = await _userManager.FindByIdAsync(urm.UserId);

            if (ModelState.IsValid)
            {
                var result = await _userManager.AddToRoleAsync(user, urm.NewRole);

                if (result.Succeeded)
                {
                    return(RedirectToAction("SignUpUsers", "UserManagement"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }
            }
            urm.Email = user.Email;
            urm.Roles = GetRoles();
            return(View(urm));
        }