Example #1
0
        /*
        "filter":{
            "logic":"and",
            "filters":[
                {
                "field":"LastName",
                "operator":"eq",
                "value":"d"
                },
                {
                "field":"LastName",
                "operator":"eq",
                "value":"ddd"
                },
                {
                "field":"Email",
                "operator":"startswith",
                "value":"d"
                },
                {
                "logic":"or",
                "filters":[
                    {
                        "field":"FirstName",
                        "operator":"contains",
                        "value":"s"
                    },
                    {
                        "field":"FirstName",
                        "operator":"contains",
                        "value":"d"
                    }
                ]
                }
            ]
        }
        */
        public static FilterObjectWrapper MapRootFilter(Filter mainFilter)
        {
            if (mainFilter != null)
            {
                var filters = new List<FilterObject>();

                foreach (var filter in mainFilter.Filters)
                {
                    FilterObject filterObject;
                    if (filter.Logic == "or" || filter.Logic == "and")
                    {
                        var filter1 = filter.Filters.First();
                        filterObject = Map(filter1);

                        var filter2 = filter.Filters.Last();
                        filterObject.Field2 = filter2.Field;
                        filterObject.Operator2 = filter2.Operator;
                        filterObject.Value2 = filter2.Value;
                        filterObject.IgnoreCase2 = filter2.IgnoreCase;
                        filterObject.Logic = filter.Logic;
                    }
                    else
                    {
                        filterObject = Map(filter);
                    }

                    filters.Add(filterObject);
                }

                return new FilterObjectWrapper(mainFilter.Logic, filters);
            }

            return null;
        }
Example #2
0
 private static FilterObject Map(Filter filter)
 {
     return new FilterObject
     {
         Field1 = filter.Field,
         Operator1 = filter.Operator,
         Value1 = filter.Value,
         IgnoreCase1 = filter.IgnoreCase,
         Logic = filter.Logic
     };
 }