示例#1
0
        /// <summary>
        /// Get a list of all clients.
        /// </summary>
        /// <returns></returns>
        public async Task <IdServerUserCollection> List(IdServerUserQuery query)
        {
            IEnumerable <IdServerUserView> results = new IdServerUserView[0];
            //Count
            var users     = query.Create(userDb.Users);
            var userTotal = await users.CountAsync();

            var clientCreds = query.Create(configDb.Clients, guidFactory);
            var clientTotal = await clientCreds.CountAsync();

            //Skip
            var total = userTotal + clientTotal;
            var skip  = query.SkipTo(total);
            var limit = query.Limit;

            //Query users
            if (skip < userTotal) //If we are past all of these, don't load them
            {
                users = users.Skip(skip).Take(limit);
                var resultQuery = users.Select(i => new IdServerUserView()
                {
                    DisplayName = i.UserName,
                    Email       = i.Email,
                    UserId      = TempIdConverter.ConvertId(i.Id),
                    UserName    = i.UserName
                });
                results = results.Concat(await resultQuery.ToListAsync());
            }

            //Query client credentials
            if (skip + limit > userTotal) //If we are past the amount of actual users, include applications
            {
                var adjSkip = skip - userTotal;
                if (adjSkip < 0)
                {
                    limit  += adjSkip;
                    adjSkip = 0;
                }

                clientCreds = clientCreds.Skip(adjSkip).Take(limit);
                var resultQuery = clientCreds.Select(c => new IdServerUserView()
                {
                    DisplayName = c.Name,
                    UserId      = guidFactory.CreateGuid(c),
                    UserName    = c.ClientId
                });
                results = results.Concat(await resultQuery.ToListAsync());
            }

            return(new IdServerUserCollection(query, total, results));
        }
示例#2
0
 public Task <IdServerUserCollection> List([FromBody] IdServerUserQuery query)
 {
     return(repo.List(query));
 }