Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// suppose to generate query like this
        /// Where(x => x.propertyA.ToLower().Contains(TargetValue.ToLower()));
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="MemberName"></param>
        /// <param name="TargetValue"></param>
        /// <returns></returns>
        public IQueryable <T> AppendQueryWithContains <T>(string MemberName, string TargetValue, IQueryable <T> queryableData, SortingFilterModel Model)
        {
            //create chainedrules at two-level deep, tolower as level1 and contains as level2
            var root = new ChainedRule(MemberName, Operator.ToLower, null);

            root.ChildRule = new ChainedRule(MemberName, Operator.Contains, TargetValue.ToLower());
            ParameterExpression p     = Expression.Parameter(typeof(T), "x");
            Expression          right = ExpBuilder.EvaluateChainedRule <T>(root, p);
            var whereExp = Expression.Lambda <Func <T, bool> >(right, new ParameterExpression[] { p });

            var whereMethodExpression = ExpBuilder.BuildMethodExpression(queryableData, Where, whereExp, typeArguments: new Type[] { queryableData.ElementType });


            IQueryable <T> results = queryableData.EvalQueryMethodCallExpression(whereMethodExpression);

            //ShouldResetPageIndex value is set at the front end, when freetext search is triggered, always get the content from pageindex1
            if (Model.ShouldResetPageIndex)
            {
                ResetPageIndex(Model);
            }
            return(results);
        }