Ejemplo n.º 1
0
 public void AddFilterItem(string key, FilterItem item)
 {
     if (filterCollection.ContainsKey(key))
     {
         filterCollection[key].Add(item);
     }
     else
     {
         filterCollection.Add(key, new FilterItemList {
             item
         });
     }
 }
Ejemplo n.º 2
0
        private static Dictionary <string, FilterItemList> QueryStringToDictionary(string queryString)
        {
            var dict  = new Dictionary <string, FilterItemList>();
            var split = queryString.Split('&');

            foreach (var part in split)
            {
                var keyValue = part.Split('=');
                if (keyValue.Length == 2)
                {
                    var val  = keyValue[1];
                    var key  = keyValue[0];
                    var oper = FilterOperator.Equals;

                    if (key.Contains("__neq"))
                    {
                        key  = key.Replace("__neq", string.Empty);
                        oper = FilterOperator.NotEqual;
                    }

                    if (key.Contains("__lte"))
                    {
                        key  = key.Replace("__lte", string.Empty);
                        oper = FilterOperator.LessThan;
                    }

                    if (key.Contains("__gte"))
                    {
                        key  = key.Replace("__gte", string.Empty);
                        oper = FilterOperator.GreaterThan;
                    }

                    if (key.Contains("__in"))
                    {
                        key  = key.Replace("__in", string.Empty);
                        oper = FilterOperator.In;
                    }

                    if (key.Contains("__nin"))
                    {
                        key  = key.Replace("__nin", string.Empty);
                        oper = FilterOperator.NotIn;
                    }

                    var queryAttribute = new FilterItem(val, oper);
                    if (dict.ContainsKey(key))
                    {
                        var tmp = dict[key];
                        tmp.Add(queryAttribute);
                        dict.Remove(key);
                        dict.Add(key, tmp);
                    }
                    else
                    {
                        dict.Add(key, new FilterItemList {
                            queryAttribute
                        });
                    }
                }
            }

            return(dict);
        }