예제 #1
0
        public IQueryable <T> GenericSortQuery <T>(IQueryable <T> queryableData, SortingModel Model)
        {
            IQueryable <T> results = null;

            if (!Model.ShouldReOrder)
            {
                string methodName = GetOrderbyMethodName(Model.SortingOrderCurrent == SortingOrder.Descending ? true : false);
                results = SortQueryDefaultColumn(queryableData, Model, methodName);
                return(results);
            }


            if (Model.SortingColumnNew.IsEmpty())
            {
                results = SortQueryDefaultColumn(queryableData, Model);
            }
            else
            {
                var  orderByExp        = ExpBuilder.CreatePropertyExpressionNoConvert <T>(Model.SortingColumnNew.Trim());
                bool OrderByDescending = CalculateSortingOrder(Model);

                string methodName = GetOrderbyMethodName(OrderByDescending);
                var    methodExp  = ExpBuilder.BuildMethodExpression(queryableData, methodName, orderByExp);
                results = queryableData.EvalQueryMethodCallExpression(methodExp);
            }
            Model.HasBeenSorted = true;
            Model.ShouldReOrder = false;
            return(results);
        }