Exemplo n.º 1
0
        public async Task <IActionResult> RemoveRoleFromUser(string userId, string roleName)
        {
            IdentityUser userFound = await _userManager.FindByIdAsync(userId);

            if (userFound == null)
            {
                return(RedirectToAction(nameof(UserList)));
            }

            var result = await _userManager.RemoveFromRoleAsync(userFound, roleName);

            if (result.Succeeded)
            {
                return(RedirectToAction("RolesManagment", new { id = userId }));
            }

            IList <string> userRoles = await _userManager.GetRolesAsync(userFound);

            List <IdentityRole> identityRoles = _roleManager.Roles.ToList();

            RolesManagmentViewModel viewModel = new RolesManagmentViewModel(userId, userRoles, identityRoles);

            ViewBag.ErrorMsg = "Failed to change role for user!";

            return(View("RolesManagment", viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RolesManagment(string id)
        {
            UserApplication userFound = await _userManager.FindByIdAsync(id);

            if (userFound == null)
            {
                return(RedirectToAction(nameof(UserList)));
            }

            IList <string> UserRoles = await _userManager.GetRolesAsync(userFound);

            List <IdentityRole> IdentityRole = _roleManager.Roles.ToList();

            RolesManagmentViewModel RviewModel = new RolesManagmentViewModel(id, UserRoles, IdentityRole);

            return(View(RviewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RolesManagment(string id)
        {
            AppUser userFound = await _AppUser.FindByIdAsync(id);



            if (userFound == null)
            {
                return(RedirectToAction(nameof(UserList)));
            }

            IList <string> userRoles = await _AppUser.GetRolesAsync(userFound);

            List <IdentityRole> identityRoles = _roleManager.Roles.ToList();

            RolesManagmentViewModel viewModel = new RolesManagmentViewModel(id, userRoles, identityRoles);

            return(View(viewModel));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddRoleToUser(string userId, string roleName)
        {
            UserApplication userFound = await _userManager.FindByIdAsync(userId);

            if (userFound == null)
            {
                return(RedirectToAction(nameof(UserList)));
            }
            var result = await _userManager.AddToRoleAsync(userFound, roleName);

            if (result.Succeeded)
            {
                return(RedirectToAction("RolesManagment", new { id = userId }));
            }

            IList <string> UserRoles = await _userManager.GetRolesAsync(userFound);

            List <IdentityRole> IdentityRole = _roleManager.Roles.ToList();

            RolesManagmentViewModel RviewModel = new RolesManagmentViewModel(userId, UserRoles, IdentityRole);

            ViewBag.ErroMsg = "Failed to change role for user";
            return(View("RolesManagment", RviewModel));
        }