public int DeleteWidgets(Filter filter) { return 0; }
private List<Filter> FormFilterList(DataFilter dataFilter) { List<Filter> filterList = new List<Filter>(); try { foreach (org.iringtools.library.Expression expression in dataFilter.Expressions) { Filter filter = new Filter(); string propertyName = expression.PropertyName; DataProperty dataProperty = (from dp in _dataObjectDefinition.dataProperties where dp.propertyName.ToUpper() == propertyName.ToUpper() select dp).FirstOrDefault(); bool isString = (dataProperty.dataType == DataType.String || dataProperty.dataType == DataType.Char); filter.AttributeName = propertyName; if (expression.RelationalOperator == RelationalOperator.StartsWith) { if (!isString) throw new Exception("StartsWith operator used with non-string property"); filter.RelationalOperator = "like"; filter.Value = "\"" + expression.Values.FirstOrDefault() + "\""; } else if (expression.RelationalOperator == RelationalOperator.EndsWith) { if (!isString) throw new Exception("EndsWith operator used with non-string property"); filter.RelationalOperator = "like"; filter.Value = "\"" + expression.Values.FirstOrDefault() + "\""; } else if (expression.RelationalOperator == RelationalOperator.Contains) { if (!isString) throw new Exception("Contains operator used with non-string property"); filter.RelationalOperator = "like"; filter.Value = "\"" + expression.Values.FirstOrDefault() + "\""; } else if (expression.RelationalOperator == RelationalOperator.In) { filter.RelationalOperator = expression.RelationalOperator.ToString(); string values = String.Empty; int valueIndex = 1; int valueCount = expression.Values.Count(); foreach (string value in expression.Values) { if (isString) { if (valueIndex == valueCount) values += "\"" + value + "\""; else values += "\"" + value + "\", "; } else { if (valueIndex == valueCount) values += value; else values += value + ", "; } valueIndex++; } filter.Value = values; } else { filter.RelationalOperator = expression.RelationalOperator.ToString(); if (isString) filter.Value = "\"" + expression.Values.FirstOrDefault() + "\""; else filter.Value = expression.Values.FirstOrDefault(); } if (expression.LogicalOperator != LogicalOperator.None) filter.Logical = expression.LogicalOperator.ToString(); filterList.Add(filter); } } catch (Exception ex) { _logger.ErrorFormat("Error while marshalling a data filter into a filter list: {1}", ex); throw new Exception("Error while marshalling a data filter into a filter list.", ex); } return filterList; }
public Widgets SearchWidgets(string query) { List<Filter> filters = new List<Filter>(); Filter name = new Filter { AttributeName = "Name", RelationalOperator = "like", Value = query, }; filters.Add(name); Filter description = new Filter { Logical = "or", AttributeName = "Description", RelationalOperator = "like", Value = query, }; filters.Add(description); Filter material = new Filter { Logical = "or", AttributeName = "Material", RelationalOperator = "like", Value = query, }; filters.Add(material); // for database applications ,the following function has to be called to build filters. // Currently it is difficult to implement search functionality on Enum types //filters = BuildSearchFiltersForResources("Widgets", query); return ReadWidgets(filters); }