public ActionResult AddRule(int ruleSetId, RuleScope scope, string ruleType) { var provider = _ruleProvider(scope); var descriptor = provider.RuleDescriptors.FindDescriptor(ruleType); var op = descriptor.Operators.First(); var rule = new RuleEntity { RuleSetId = ruleSetId, RuleType = ruleType, Operator = op.Operator }; if (op == RuleOperator.In || op == RuleOperator.NotIn) { // Avoid ArgumentException "The 'In' operator only supports non-null instances from types that implement 'ICollection<T>'." rule.Value = string.Empty; } _ruleStorage.InsertRule(rule); var expression = provider.VisitRule(rule); PrepareTemplateViewBag(ruleSetId); return(PartialView("_Rule", expression)); }
public ActionResult AddRule(int ruleSetId, RuleScope scope, string ruleType) { var provider = _ruleProvider(scope); var descriptor = provider.RuleDescriptors.FindDescriptor(ruleType); var op = descriptor.Operators.First(); var rule = new RuleEntity { RuleSetId = ruleSetId, RuleType = ruleType, Operator = op.Operator }; if (descriptor.RuleType == RuleType.Boolean) { // Do not store NULL. Irritating because UI indicates 'yes'. var val = op == RuleOperator.IsEqualTo; rule.Value = val.ToString(CultureInfo.InvariantCulture).ToLower(); } else if (op == RuleOperator.In || op == RuleOperator.NotIn) { // Avoid ArgumentException "The 'In' operator only supports non-null instances from types that implement 'ICollection<T>'." rule.Value = string.Empty; } _ruleStorage.InsertRule(rule); var expression = provider.VisitRule(rule); PrepareTemplateViewBag(ruleSetId); return(PartialView("_Rule", expression)); }