Пример #1
0
        /// <summary>
        /// GetPageData
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="querableList"></param>
        /// <param name="orderByKeySelector"></param>
        /// <param name="pageParam"></param>
        /// <param name="bIsAscOrder"></param>
        /// <param name="strOrder">Id Asc, Date Desc</param>
        /// <returns>PageData<TEntity></returns>
        public static PageData <TEntity> GetPageData <TEntity, TKey>(IQueryable <TEntity> querableList
                                                                     , Expression <Func <TEntity, TKey> > orderByKeySelector
                                                                     , PageParam pageParam, bool bIsAscOrder = true, string strOrder = "")
        {
            pageParam.Check();

            PageData <TEntity> pageData = new PageData <TEntity>(pageParam, querableList.Count());

            IQueryable <TEntity> orderQuerableList = null;

            if (string.IsNullOrEmpty(strOrder))
            {
                orderQuerableList = bIsAscOrder
                                    ?
                                    querableList.OrderBy(orderByKeySelector)
                                    :
                                    querableList.OrderByDescending(orderByKeySelector);
            }
            else
            {
                orderQuerableList = querableList.OrderBy(strOrder);
            }

            int intPageSkip = pageParam.GetPageSkip();

            pageData.Data = orderQuerableList.Skip(intPageSkip)
                            .Take(pageParam.PageSize).ToList();
            return(pageData);
        }
        /// <summary>
        /// GetPageData
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="querableList"></param>
        /// <param name="orderByKeySelector"></param>
        /// <param name="pageParam"></param>
        /// <param name="bIsAscOrder"></param>
        /// <param name="strOrder">Id Asc, Date Desc</param>
        /// <returns>PageData<TEntity></returns>
        public static PageData <TEntity> GetPageData <TEntity, TKey>(IQueryable <TEntity> querableList
                                                                     , Expression <Func <TEntity, TKey> > orderByKeySelector
                                                                     , PageParam pageParam, bool bIsAscOrder = true, string strOrder = "")
        {
            pageParam.Check();

            PageData <TEntity> pageData = new PageData <TEntity>(pageParam, querableList.Count());

            IQueryable <TEntity> orderQuerableList = GetOrderQueryable(querableList, orderByKeySelector, bIsAscOrder, strOrder);

            pageData.Data = GetPageData(orderQuerableList, pageParam).ToList();
            return(pageData);
        }