コード例 #1
0
        public async IAsyncEnumerable <(User, IList <string>)> ListAllowedUsersBySensorAsync(Sensor sensor, int offset, int limit)
        {
            RangeQueryValidations.ValidateRangeQueryParameters(offset, limit);

            var admins = await _userManager.GetUsersInRoleAsync("Admin");

            var adminIds = admins.Select(a => a.Id);
            var yields   = 0;

            await foreach (var user in
                           AllowedUsersBySensor(sensor, adminIds)
                           .Skip(offset)
                           .Take(limit).AsAsyncEnumerable())
            {
                admins.Remove(user);
                var roles = await _userManager.GetRolesAsync(user);

                yields++;
                yield return(user, roles);
            }
            foreach (var admin in admins)
            {
                if (yields++ < limit)
                {
                    var roles = await _userManager.GetRolesAsync(admin);

                    yield return(admin, roles);
                }
                else
                {
                    break;
                }
            }
        }
コード例 #2
0
 public async IAsyncEnumerable <Device> ListDevicesAsync(int offset, int limit)
 {
     RangeQueryValidations.ValidateRangeQueryParameters(offset, limit);
     await foreach (var device in _dbContext.Devices.OrderBy(u => u.Id).Skip(offset).Take(limit).AsAsyncEnumerable())
     {
         yield return(device);
     }
 }
コード例 #3
0
        public async IAsyncEnumerable <Sensor> ListSensorsAsync(int offset, int limit)
        {
            RangeQueryValidations.ValidateRangeQueryParameters(offset, limit);

            await foreach (var sensor in _dbContext.Sensors.Include(s => s.Device).OrderBy(u => u.Id).Skip(offset).Take(limit).AsAsyncEnumerable())
            {
                yield return(sensor);
            }
        }
コード例 #4
0
        public async IAsyncEnumerable <(User, IList <string>)> SearchUserWithQueryAsync(string query, int limit)
        {
            RangeQueryValidations.ValidateRangeQueryParameters(0, limit);

            await foreach (var user in
                           _dbContext.Users.Where(u => EF.Functions.Like(u.UserName, $"{query}%")).Take(limit).AsAsyncEnumerable())
            {
                var roles = await _userManager.GetRolesAsync(user);

                yield return(user, roles);
            }
        }
コード例 #5
0
        /// if roles are empty, we return every users
        /// otherwise we return the users have designated roles
        public async IAsyncEnumerable <(User, IList <string>)> ListBasicUserResultAsync(int offset, int limit, IEnumerable <string?>?roles = null)
        {
            RangeQueryValidations.ValidateRangeQueryParameters(offset, limit);
            var sanitized = SanitizedRoles(roles);
            var roleIds   = await GetRoleIdsFromNamesAsync(sanitized);

            var query = GetUserQuery(roleIds);

            await foreach (var user in query.OrderBy(u => u.Id).Skip(offset).Take(limit).AsAsyncEnumerable())
            {
                yield return(user, await _userManager.GetRolesAsync(user));
            }
        }
コード例 #6
0
        public async IAsyncEnumerable <Sensor> ListSensorsByUserAsync(User user, int offset, int limit)
        {
            RangeQueryValidations.ValidateRangeQueryParameters(offset, limit);

            if (await _userManager.IsInRoleAsync(user, "Admin"))
            {
                await foreach (var s in _dbContext.Sensors.Include(s => s.Device).Skip(offset).Take(limit).AsAsyncEnumerable())
                {
                    yield return(s);
                }
            }
            else
            {
                await foreach (var s in
                               SensorsByUserQuery(user)
                               .Skip(offset)
                               .Take(limit).AsAsyncEnumerable())
                {
                    yield return(s);
                }
            }
        }