Example #1
0
        public ParsedFilter Parse(FilterDescription definition, CommerceDataSourceContext context)
        {
            var paramValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

            foreach (var paramDef in definition.Parameters)
            {
                var param = ParameterValues.Find(p => p.ParameterName.Equals(paramDef.Name, StringComparison.OrdinalIgnoreCase));

                // Parameter is required but it's missing in data source settings (might cause by code changes). Parse failed.
                if (paramDef.Required && param == null)
                {
                    return null;
                }

                var strParamValue = ParameterizedFieldValue.GetFieldValue(param.ParameterValue, context.ValueProvider);
                // Parameter is required but it's missing in current context. Parse failed.
                if (paramDef.Required && strParamValue == null)
                {
                    return null;
                }

                var paramValue = StringConvert.ToObject(strParamValue, paramDef.ValueType);
                paramValues.Add(paramDef.Name, paramValue);
            }

            return new ParsedFilter(definition.Name)
            {
                ParameterValues = paramValues
            };
        }
Example #2
0
 public FilterModel(FilterDescription filter)
 {
     Name = filter.Name;
     Parameters = filter.Parameters.Select(p => new FilterParameterModel
     {
         Name = p.Name
     })
     .ToList();
 }