/// <summary>
        /// Should apply sorting if needed.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="input">The input.</param>
        private IQueryable <Entities.Product> ApplySorting(IQueryable <Entities.Product> query, IPagedAndSortedResultRequest input)
        {
            //Try to sort query if available
            var sortInput = input as ISortedResultRequest;

            if (sortInput != null)
            {
                if (!sortInput.Sorting.IsNullOrWhiteSpace())
                {
                    return(query.OrderBy(sortInput.Sorting));
                }
            }

            //IQueryable.Task requires sorting, so we should sort if Take will be used.
            if (input is ILimitedResultRequest)
            {
                return(query.OrderByDescending(e => e.Id));
            }

            //No sorting
            return(query);
        }
Exemplo n.º 2
0
 public static IQueryable <T> Paging <T>(this ApplicationService self, IQueryable <T> query, IPagedAndSortedResultRequest input)
 {
     if (input.SkipCount != 0)
     {
         query = query.Skip(input.SkipCount);
     }
     if (input.MaxResultCount > 0)
     {
         query = query.Take(input.MaxResultCount);
     }
     return(query);
 }
        /// <summary>
        /// Should apply paging if needed.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="input">The input.</param>
        private IQueryable <Entities.Product> ApplyPaging(IQueryable <Entities.Product> query, IPagedAndSortedResultRequest input)
        {
            //Try to use paging if available
            var pagedInput = input as IPagedResultRequest;

            if (pagedInput != null)
            {
                return(query.PageBy(pagedInput));
            }

            //Try to limit query result if available
            var limitedInput = input as ILimitedResultRequest;

            if (limitedInput != null)
            {
                return(query.Take(limitedInput.MaxResultCount));
            }

            //No paging
            return(query);
        }