Exemplo n.º 1
0
        private void AddNewConditionElement([NotNull] XElement conditionsElement, [NotNull] RuleEditor.ConditionItem conditionItem)
        {
            Debug.ArgumentNotNull(conditionsElement, nameof(conditionsElement));
            Debug.ArgumentNotNull(conditionItem, nameof(conditionItem));

            var conditionElement = new XElement(@"condition");

            conditionElement.Add(new XAttribute(@"id", conditionItem.Id));
            conditionElement.Add(new XAttribute(@"uid", Guid.NewGuid().ToShortId()));

            var root = conditionsElement.Element(0);

            if (root == null)
            {
                conditionsElement.Add(conditionElement);
                return;
            }

            var rightLeaf = GetRightLeaf(root);

            var and = new XElement(@"and");

            and.Add(new XAttribute(@"uid", Guid.NewGuid().ToShortId()));

            rightLeaf.ReplaceWith(and);

            and.Add(rightLeaf);
            and.Add(conditionElement);
        }
        public void AddCondition([NotNull] RuleEditor.ConditionItem conditionItem)
        {
            Assert.ArgumentNotNull(conditionItem, nameof(conditionItem));

            if (RuleModel.CurrentRule == null && RuleModel.Rules.Elements().Count() == 1)
            {
                RuleModel.CurrentRule = RuleModel.Rules.Elements().FirstOrDefault();
            }

            RuleModel.AddCondition(conditionItem);

            Render();
            RaiseModified();
        }
Exemplo n.º 3
0
        public void AddCondition([NotNull] RuleEditor.ConditionItem conditionItem)
        {
            Assert.ArgumentNotNull(conditionItem, nameof(conditionItem));

            if (CurrentRule == null)
            {
                return;
            }

            var conditionsElement = CurrentRule.Element(@"conditions");

            if (conditionsElement == null)
            {
                conditionsElement = new XElement(@"conditions");
                CurrentRule.Add(conditionsElement);
            }

            AddNewConditionElement(conditionsElement, conditionItem);
        }