예제 #1
0
        public IActionResult OnGetAddUserToRole(string userId)
        {
            var UsersId  = UserManagers.FindByIdAsync(userId).Result;
            var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name;
            var result1  = UserManagers.AddToRoleAsync(UsersId, rolename).Result;

            if (result1.Succeeded)
            {
                flashMessage = "User added to role";
            }
            else
            {
                flashMessage = "Error adding user to role";
            }
            return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
        }
예제 #2
0
        public IActionResult OnGetDeleteUserRole(string userId)
        {
            var UsersId  = UserManagers.FindByIdAsync(userId).Result;
            var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name;

            if (UsersId.Email == "*****@*****.**" && rolename == "Admin")
            {
                return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
            }
            else
            {
                var result1 = UserManagers.RemoveFromRoleAsync(UsersId, rolename).Result;
                if (result1.Succeeded)
                {
                    flashMessage = "User removed from role";
                }
                else
                {
                    flashMessage = "Error removing user from role";
                }
            }
            return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
        }