Пример #1
0
        private static Expression <Func <LogError, bool> > CreateFilter(string search)
        {
            var serializer = new JavaScriptSerializer();
            var dict       = serializer.Deserialize <Dictionary <string, object> >(search);

            var predicate = PredicateBuilder.True <LogError>();

            if (CheckEmpty.String(ref dict, "Type") != "")
            {
                predicate = predicate.And(p => p.Type == Convert.ToInt64(dict["Type"]));
            }

            if (CheckEmpty.String(ref dict, "Severity") != "")
            {
                predicate = predicate.And(p => p.Severity == Convert.ToInt64(dict["Severity"]));
            }

            if (CheckEmpty.String(ref dict, "Text") != "")
            {
                predicate = predicate.And(p => p.Text.Contains(dict["Text"].ToString()));
            }

            if (CheckEmpty.String(ref dict, "UserId") != "")
            {
                predicate = predicate.And(p => p.UserId == Convert.ToInt64(dict["UserId"]));
            }

            if (CheckEmpty.String(ref dict, "BranchId") != "")
            {
                predicate = predicate.And(p => p.BranchId == Convert.ToInt64(dict["BranchId"]));
            }

            if (CheckEmpty.String(ref dict, "DateFilter") != "")
            {
                var dtLimits = DateUtilities.GetDateFilter(dict["DateFilter"].ToString(), dict["FromDate"].ToString(), dict["ToDate"].ToString());
                predicate = predicate.And(p => p.EntryDate >= dtLimits.FromDate);
                predicate = predicate.And(p => p.EntryDate <= dtLimits.ToDate);
            }

            return(predicate);
        }