示例#1
0
        public async Task <PagedAndSortedList <User> > ListAllAsync(int pageNumber, int pageSize, string sort)
        {
            IQueryable <User> users = _context.Users;

            users = sort.ToLowerInvariant() == "desc"
                ? users.OrderByDescending(user => user.Username)
                : users.OrderBy(user => user.Username);
            return(await PagedAndSortedList <User> .ToPagedListAsync(users, pageNumber, pageSize,
                                                                     sort.ToLowerInvariant(), "username"));
        }
        public async Task <PagedAndSortedList <PostalCode> > SearchAsync(int pageNumber, int pageSize, string sort,
                                                                         string code,
                                                                         string countryIso)
        {
            var postalCodes = _context.PostalCodes.Include(pc => pc.PostalCodeCities)
                              .ThenInclude(pcc => pcc.City).Where(pc =>
                                                                  (string.IsNullOrEmpty(code) || pc.Code.StartsWith(code)) &&
                                                                  (string.IsNullOrEmpty(countryIso) || pc.CountryIso == countryIso));

            postalCodes = sort.ToLowerInvariant() == "desc"
                ? postalCodes.OrderByDescending(postalCode => postalCode.Code)
                : postalCodes.OrderBy(postalCode => postalCode.Code);
            return(await PagedAndSortedList <PostalCode> .ToPagedListAsync(postalCodes, pageNumber, pageSize,
                                                                           sort.ToLowerInvariant(), "code"));
        }