Exemple #1
0
        private Expression <Func <T, bool> > ConstructFilter <T> (int?userID, string roleCode, int?agentID, string search = null)
        {
            Expression <Func <T, bool> > expression = null;
            ParameterExpression          argument   = Expression.Parameter(typeof(T), "ip");
            Expression predicateBody = null;

            if (!string.IsNullOrEmpty(roleCode))
            {
                if (roleCode == "IPA" || roleCode == "PIPA" || roleCode == "APCO")
                {
                    predicateBody = argument.GetExpression("AgentID", agentID, "Equal", typeof(int));
                }
                else if (roleCode == "CSO")
                {
                    Expression e1 = argument.GetExpression("AssignedUserID", userID, "Equal", typeof(int?));
                    Expression e2 = argument.DynamicContains("ImportPermitStatusCode", new List <string> {
                        "DRFT", "WITH"
                    });
                    predicateBody = Expression.AndAlso(e1, Expression.Not(e2));
                }
                else if (roleCode == "PINS")
                {
                    predicateBody = argument.GetExpression("ImportPermitStatusCode", "APR", "Equal", typeof(string));
                }
                else
                {
                    predicateBody = Expression.Not(argument.DynamicContains("ImportPermitStatusCode", new List <string> {
                        "DRFT", "WITH"
                    }));
                }

                //Search filter expression
                if (!string.IsNullOrEmpty(search) && search.Length > 2)
                {
                    Expression pb = null;
                    foreach (var str in searchConfig.Strings)
                    {
                        var exp = argument.StringContains(str, search);
                        pb = pb == null ? exp : Expression.OrElse(pb, exp);
                    }
                    predicateBody = Expression.AndAlso(predicateBody, pb);
                }
            }

            expression = Expression.Lambda <Func <T, bool> > (predicateBody, new [] { argument });
            return(expression);
        }
Exemple #2
0
        private Expression <Func <T, bool> > ConstructFilter <T> (IList <int> suppliers = null, string search = null, bool isExpired = true, string submoduleTypeCode = null)
        {
            Expression <Func <T, bool> > expression = null;
            ParameterExpression          argument   = Expression.Parameter(typeof(T), "p");
            Expression predicateBody = null;

            if (suppliers != null && suppliers.Any())
            {
                predicateBody = argument.DynamicContains("SupplierID", suppliers);
            }
            if (submoduleTypeCode != null)
            {
                var exp = argument.GetExpression("SubmoduleTypeCode", submoduleTypeCode, "Equal", typeof(string));
                predicateBody = predicateBody == null ? exp : Expression.AndAlso(predicateBody, exp);
            }

            var e = argument.GetExpression("MAStatusCode", "APR", "Equal", typeof(string));

            predicateBody = predicateBody == null ? e : Expression.AndAlso(predicateBody, e);

            //Search filter expression
            if (!string.IsNullOrEmpty(search) && search.Length > 2)
            {
                Expression pb = null;
                foreach (var str in columns)
                {
                    var exp = argument.StringContains(str, search);
                    pb = pb == null ? exp : Expression.OrElse(pb, exp);
                }
                predicateBody = Expression.AndAlso(predicateBody, pb);
            }
            if (!isExpired)
            {
                var expired = Expression.OrElse(argument.GetExpression("IsExpired", false, "Equal", typeof(bool?)), argument.GetExpression("IsExpired", null, "Equal", typeof(bool?)));
                predicateBody = Expression.AndAlso(predicateBody, expired);
            }

            expression = Expression.Lambda <Func <T, bool> > (predicateBody, new [] { argument });
            return(expression);
        }