예제 #1
0
        /// <summary>
        /// Performs filtering of the data collection.
        /// </summary>
        /// <typeparam name="T">Type of elements in the collection to filter.</typeparam>
        /// <param name="collection">Sequence of elements to filter.</param>
        /// <param name="filter">Filter which apply to collection.</param>
        /// <param name="sortBy">Sorting function.</param>
        /// <param name="sortAscending">Sorting direction.</param>
        /// <param name="startRow">Row from which start filtering.</param>
        /// <param name="pageSize">Count of rows in the page.</param>
        /// <returns>Collection with specific filtering rules applied.</returns>
        protected IEnumerable <T> Filter <T>(
            IQueryable <T> collection,
            ICollectionFilter <T> filter,
            Func <T, IComparable> sortBy,
            bool sortAscending,
            int startRow,
            int pageSize)
        {
            collection = filter.Filter(collection);
            if (sortBy == null)
            {
                return(collection);
            }

            // Perform sorting
            var sortedCollection = sortAscending
                ? collection.OrderBy(sortBy)
                : collection.OrderByDescending(sortBy);

            // Perform filtering.
            var pagedCollection = sortedCollection.Skip(startRow).Take(pageSize);

            return(pagedCollection);
        }