コード例 #1
0
ファイル: UsersRepo.cs プロジェクト: atnartur/Ulearn
        /* Pass limit=0 to disable limiting */
        public Task <List <UserRolesInfo> > FilterUsers(UserSearchQueryModel query, UserManager <ApplicationUser> userManager, int limit = 100)
        {
            var role = db.Roles.FirstOrDefault(r => r.Name == query.Role);
            IQueryable <ApplicationUser> users = db.Users;

            if (!string.IsNullOrEmpty(query.NamePrefix))
            {
                var usersIds = GetUsersByNamePrefix(query.NamePrefix).Select(u => u.Id);
                users = users.Where(u => usersIds.Contains(u.Id));
            }
            return(users
                   .FilterByRole(role, userManager)
                   .FilterByUserIds(
                       userRolesRepo.GetListOfUsersWithCourseRole(query.CourseRole, query.CourseId, query.IncludeHighCourseRoles),
                       userRolesRepo.GetListOfUsersByPrivilege(query.OnlyPrivileged, query.CourseId)
                       )
                   .GetUserRolesInfo(limit, userManager));
        }
コード例 #2
0
ファイル: GroupsRepo.cs プロジェクト: atnartur/Ulearn
        private async Task CopyGroupAccesses(Group group, Group newGroup)
        {
            var accesses             = db.GroupAccesses.Where(a => a.GroupId == group.Id && a.IsEnabled).ToList();
            var courseInstructorsIds = userRolesRepo.GetListOfUsersWithCourseRole(CourseRole.Instructor, newGroup.CourseId, includeHighRoles: true);

            foreach (var access in accesses)
            {
                if (!courseInstructorsIds.Contains(access.UserId))
                {
                    continue;
                }
                db.GroupAccesses.Add(new GroupAccess
                {
                    GroupId     = newGroup.Id,
                    UserId      = access.UserId,
                    AccessType  = access.AccessType,
                    GrantedById = access.GrantedById,
                    GrantTime   = DateTime.Now,
                    IsEnabled   = true,
                });
            }

            await db.SaveChangesAsync();
        }