public static PagingList <T> ExecuteQueryWithCriteria <T>(
            IQueryable <T> query,
            Criteria criteria) where T : class
        {
            var toReturn = new PagingList <T>();

            IQueryable <T> queryBuilder = query;

            if (criteria.FilterFieldName != null && criteria.FilterFieldValue != null)
            {
                queryBuilder = query.Where(
                    DynamicExpressionBuilder.BuildFilterExpression <T>(
                        criteria.FilterFieldName,
                        criteria.FilterFieldValue,
                        StringFilterOperator.Contains));
            }

            toReturn.TotalCount = queryBuilder.Count();

            if (criteria.SortFieldName != null)
            {
                queryBuilder = queryBuilder.OrderBy(
                    property: criteria.SortFieldName,
                    direction: (criteria.SortDirection == SortDirection.Ascending) ? "ASC" : "DESC");
            }

            if (criteria.PageSize != -1)
            {
                queryBuilder = queryBuilder
                               .Skip(criteria.PageSize * (criteria.PageNumber - 1))
                               .Take(criteria.PageSize);
            }

            toReturn.AddRange(queryBuilder);
            return(toReturn);
        }
Esempio n. 2
0
 public PagedResponse(PagingList <T> inner)
 {
     this.Body       = new List <T>(inner);
     this.TotalCount = inner.TotalCount;
 }