public ActionResult RuleOrder(policyData vData, int id, int linkId, FormCollection collection)
        {
            RuleEntity rule = new RuleEntity(id);
            RuleCollection coll = new RuleCollection();

            PredicateExpression pe = new PredicateExpression(RuleFields.Id != rule.Id);
            pe.Add(RuleFields.PolicyId == rule.PolicyId);
            SortExpression se = null;

            if (collection["up"] != null)
            {
                // Find all categories with display index less than ours.
                pe.Add(RuleFields.Order <= rule.Order);

                // Order by display index, highest first.
                se = new SortExpression(RuleFields.Order | SortOperator.Descending);
            }
            else
            {
                // Find all categories with display index greater than ours.
                pe.Add(RuleFields.Order >= rule.Order);

                // Order by display index, lowest first.
                se = new SortExpression(RuleFields.Order | SortOperator.Ascending);
            }

            // Swap with closest one.
            if (coll.GetMulti(pe, 1, se) && coll.Count > 0)
            {
                int temp = coll[0].Order;
                coll[0].Order = rule.Order;
                rule.Order = temp;

                rule.Save();
                coll.SaveMulti();
            }

            return RedirectToAction("EditPolicy", new { id = linkId });
        }
        private void loadRule(int idx,PolicyEntity pe, XmlNode node)
        {
            RuleEntity re = new RuleEntity();
            re.Policy = pe;
            re.Order = idx;

            string effect = "permit";
            XmlNode attr = node.Attributes.GetNamedItem("effect");
            if (attr != null)
                effect = attr.Value;

            EffectCollection ecoll = new EffectCollection();
            ecoll.GetMulti(EffectFields.Name == effect);
            if (ecoll.Count != 1)
                throw new Exception(string.Format("unrecognised rule effect {0}", effect));
            re.Effect = ecoll[0];

            DecisionNodeEntity ce = new DecisionNodeEntity();
            re.Condition = ce;
            ce.Type = constants.conditionType;
            ce.IsDirty = true;

            XmlNode condition = node.SelectSingleNode("condition");
            if (condition != null)
                loadCondition(ce, condition);
        }
Ejemplo n.º 3
0
        /// <summary>Creates a new, empty RuleEntity object.</summary>
        /// <returns>A new, empty RuleEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new RuleEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewRule
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }