Esempio n. 1
0
        private IQueryable <User> ApplyOrder(IQueryable <User> queryUsers,
                                             UserFieldEnum orderField, OrderEnum order)
        {
            switch (orderField)
            {
            case UserFieldEnum.email:
                if (order == OrderEnum.Ascending)
                {
                    queryUsers = queryUsers.OrderBy(x => x.email);
                }
                else
                {
                    queryUsers = queryUsers.OrderByDescending(x => x.email);
                }
                break;

            case UserFieldEnum.username:
                if (order == OrderEnum.Ascending)
                {
                    queryUsers = queryUsers.OrderBy(x => x.username);
                }
                else
                {
                    queryUsers = queryUsers.OrderByDescending(x => x.username);
                }
                break;

            default:
                queryUsers = queryUsers.OrderBy(x => x.username);
                break;
            }
            return(queryUsers);
        }
Esempio n. 2
0
        public async Task <(List <User>, int)> getUsers(int startat, int quantity, UserFieldEnum fieldFilter, string fieldValue, UserFieldEnum orderField, OrderEnum order)
        {
            var queryUser = _context.Users.Where(x => x.enabled == true);

            queryUser = ApplyFilter(queryUser, fieldFilter, fieldValue);
            queryUser = ApplyOrder(queryUser, orderField, order);
            var users = await queryUser.Include(x => x.userGroup)
                        .Skip(startat).Take(quantity).ToListAsync();

            var queryUserCount = _context.Users.Where(x => x.enabled == true);

            queryUserCount = ApplyFilter(queryUserCount, fieldFilter, fieldValue);
            queryUserCount = ApplyOrder(queryUserCount, orderField, order);
            var totalCount = await queryUserCount.CountAsync();

            return(users, totalCount);
        }
Esempio n. 3
0
        private IQueryable <User> ApplyFilter(IQueryable <User> queryUsers,
                                              UserFieldEnum fieldFilter, string fieldValue)
        {
            switch (fieldFilter)
            {
            case UserFieldEnum.email:
                queryUsers = queryUsers.Where(x => x.email.Contains(fieldValue));
                break;

            case UserFieldEnum.username:
                queryUsers = queryUsers.Where(x => x.username.Contains(fieldValue));
                break;

            default:
                break;
            }
            return(queryUsers);
        }