Ejemplo n.º 1
0
        public async Task <UsersDto> GetAsync(GetUsersQuery query)
        {
            var sortColumn = string.IsNullOrEmpty(query.SortColumn)
                ? PropertyName.Get((User x) => x.Id)
                : query.SortColumn.FirstLetterToUpper();

            var sortType = query.SortType == "desc" ? " descending" : "";

            var users = await _context.Users.Where(SearchCriteria(query.SearchTerm))
                        .OrderBy(sortColumn + sortType)
                        .Skip((query.Page - 1) * query.PageSize)
                        .Take(query.PageSize)
                        .Project().To <UserItemDto>()
                        .ToListAsync();

            return(new UsersDto()
            {
                List = users,
                Total = await _context.Users.CountAsync(SearchCriteria(query.SearchTerm))
            });
        }
Ejemplo n.º 2
0
        public async Task<UsersDto> GetAsync(GetUsersQuery query)
        {
            var sortColumn = string.IsNullOrEmpty(query.SortColumn) 
                ? PropertyName.Get((User x) => x.Id) 
                : query.SortColumn.FirstLetterToUpper();

            var sortType = query.SortType == "desc" ? " descending" : "";

            var users = await _context.Users.Where(SearchCriteria(query.SearchTerm))
                .OrderBy(sortColumn + sortType)
                .Skip((query.Page - 1) * query.PageSize)
                .Take(query.PageSize)
                .Project().To<UserItemDto>()
                .ToListAsync();                

            return new UsersDto()
            {
                List = users,
                Total = await _context.Users.CountAsync(SearchCriteria(query.SearchTerm))
            };
        }