public ActionResult GetRoleUsers(string RoleName)
        {
            var model = new RoleUsersModel
            {
                Role  = Context.Roles.Where(x => x.RoleName == RoleName).ToList().FirstOrDefault(),
                Users = Context.Users.ToList()
            };

            return(View("~/Areas/Admin/Views/Shared/Partials/GetRoleUsers.cshtml", model));
        }
Exemple #2
0
        public ActionResult GetRoleUsers(string roleId)
        {
            // find the role
            var roleIdGuid = new Guid(roleId);
            var role       = Context.Roles.FirstOrDefault(x => x.RoleId == roleIdGuid);

            // need role users
            var roleUsers = role.Users;

            // get the users in that role selected into new model
            var queryUsersInRole =
                roleUsers.Select(x => new UserForRoleComparison {
                UserId = x.UserId, Username = x.Username
            }).ToList();
            var usersInRole = new List <UserForRoleComparison>();

            usersInRole.AddRange(queryUsersInRole);


            // get users not in role selected into new model
            var tempUsers           = roleUsers.Select(x => x.UserId).ToList();
            var queryUsersNotInRole = Context.Users
                                      .Where(x => !tempUsers.Contains(x.UserId))
                                      .Select(x => new UserForRoleComparison {
                UserId = x.UserId, Username = x.Username
            }).ToList();
            var usersNotInRole = new List <UserForRoleComparison>();

            usersNotInRole.AddRange(queryUsersNotInRole);


            var model = new RoleUsersModel
            {
                UsersInRole    = usersInRole,
                UsersNotInRole = usersNotInRole
            };

            return(View("~/Areas/Admin/Views/Shared/Partials/GetRoleUsers.cshtml", model));
        }
        public ActionResult GetRoleUsers(string RoleName)
        {
            var model = new RoleUsersModel
            {
                Role = Context.Roles.Where(x => x.RoleName == RoleName).ToList().FirstOrDefault(),
                Users = Context.Users.ToList()
            };

            return View("~/Areas/Admin/Views/Shared/Partials/GetRoleUsers.cshtml", model);
        }
        public ActionResult GetRoleUsers(string roleId)
        {
            // find the role
            var roleIdGuid = new Guid(roleId);
            var role = Context.Roles.FirstOrDefault(x => x.RoleId == roleIdGuid);

            // need role users
            var roleUsers = role.Users;

            // get the users in that role selected into new model
            var queryUsersInRole =
                roleUsers.Select(x => new UserForRoleComparison { UserId = x.UserId, Username = x.Username }).ToList();
            var usersInRole = new List<UserForRoleComparison>();
            usersInRole.AddRange(queryUsersInRole);


            // get users not in role selected into new model
            var tempUsers = roleUsers.Select(x => x.UserId).ToList();
            var queryUsersNotInRole = Context.Users
                .Where(x => !tempUsers.Contains(x.UserId))
                .Select(x => new UserForRoleComparison { UserId = x.UserId, Username = x.Username }).ToList();
            var usersNotInRole = new List<UserForRoleComparison>();
            usersNotInRole.AddRange(queryUsersNotInRole);


            var model = new RoleUsersModel
            {
                UsersInRole = usersInRole,
                UsersNotInRole = usersNotInRole
            };

            return View("~/Areas/Admin/Views/Shared/Partials/GetRoleUsers.cshtml", model);
        }