예제 #1
0
        static private bool DeletePolicyFromLib(int id)
        {
            PredicateExpression pe   = new PredicateExpression(PolicyLinkFields.PolicyId == id);
            PredicateExpression peOr = new PredicateExpression(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null));

            peOr.AddWithOr(PolicyLinkFields.ParentId != DBNull.Value);
            pe.Add(peOr);

            PolicyLinkCollection plcoll = new PolicyLinkCollection();

            if (plcoll.GetMulti(pe) && plcoll.Count == 0)
            {
                // Policy isn't referenced in any policy document.
                PolicyEntity delPolicy = new PolicyEntity(id);
                delPolicy.PolicyLink.DeleteMulti();

                DeletePolicy(delPolicy);

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public ActionResult ReferencePolicy(policyData vData, int id, bool isDoc, FormCollection collection)
        {
            int parse;

            if (int.TryParse(collection["libraryPolicyId"], out parse) && parse > 0)
            {
                PolicyEntity copy = duplicator.dupPolicy(parse);

                vData.PolicyLink          = new PolicyLinkEntity();
                vData.PolicyLink.PolicyId = copy.Id;

                if (isDoc)
                {
                    vData.PolicyDocument            = new PolicyDocumentEntity(id);
                    vData.PolicyDocument.PolicyLink = vData.PolicyLink;
                    vData.PolicyDocument.Save(true);

                    return(RedirectToAction("EditPolicyDoc", new { id = id }));
                }
                else
                {
                    vData.PolicyLink.ParentId = id;

                    PolicyLinkCollection maxColl = new PolicyLinkCollection();
                    PredicateExpression  pe      = new PredicateExpression(PolicyLinkFields.ParentId == id);
                    object maxObj = maxColl.GetScalar(PolicyLinkFieldIndex.Order, null, AggregateFunction.Max, pe);
                    if (maxObj != null && maxObj != DBNull.Value)
                    {
                        vData.PolicyLink.Order = (int)maxObj + 1;
                    }
                    else
                    {
                        vData.PolicyLink.Order = 0;
                    }

                    vData.PolicyLink.Save();

                    return(RedirectToAction("EditPolicySet", new { id = id }));
                }
            }
            else
            {
                return(RedirectToAction("AddPolicy", new { id = id, isDoc = isDoc }));
            }
        }
예제 #3
0
        public ActionResult PolicyOrder(policyData vData, int id, FormCollection collection)
        {
            PolicyLinkEntity     policyLink = new PolicyLinkEntity(id);
            PolicyLinkCollection coll       = new PolicyLinkCollection();

            PredicateExpression pe = new PredicateExpression(PolicyLinkFields.Id != policyLink.Id);

            pe.Add(PolicyLinkFields.ParentId == policyLink.ParentId);
            SortExpression se = null;

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

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

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

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

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

            return(RedirectToAction("EditPolicySet", new { id = policyLink.ParentId }));
        }
예제 #4
0
        public ActionResult EditPolicyFromLib(policyData vData, int id)
        {
            PredicateExpression pe = new PredicateExpression(PolicyLinkFields.ParentId == DBNull.Value);

            pe.Add(PolicyLinkFields.PolicyId == id);
            pe.Add(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null, true));

            PolicyLinkCollection plcoll = new PolicyLinkCollection();

            if (plcoll.GetMulti(pe) && plcoll.Count > 0)
            {
                vData.PolicyLink = plcoll[0];
            }
            else
            {
                vData.PolicyLink          = new PolicyLinkEntity();
                vData.PolicyLink.PolicyId = id;
                vData.PolicyLink.Save();
            }

            return(RedirectToAction("EditPolicy", new { id = vData.PolicyLink.Id }));
        }
예제 #5
0
        private void CreatePolicy(policyData vData, int?id, bool set, bool isLibrary)
        {
            vData.Policy                    = new PolicyEntity();
            vData.Policy.LibraryId          = vData.Library.Id;
            vData.Policy.Description        = set ? "new policy set" : "new policy";
            vData.Policy.Set                = set;
            vData.Policy.IsLibrary          = isLibrary;
            vData.Policy.Target.Description = string.Empty;

            vData.PolicyLink        = new PolicyLinkEntity();
            vData.PolicyLink.Policy = vData.Policy;

            if (id.HasValue)
            {
                vData.PolicyLink.ParentId = id;

                PolicyLinkCollection maxColl = new PolicyLinkCollection();
                PredicateExpression  pe      = new PredicateExpression(PolicyLinkFields.ParentId == id);
                object maxObj = maxColl.GetScalar(PolicyLinkFieldIndex.Order, null, AggregateFunction.Max, pe);
                if (maxObj != null && maxObj != DBNull.Value)
                {
                    vData.PolicyLink.Order = (int)maxObj + 1;
                }
                else
                {
                    vData.PolicyLink.Order = 0;
                }
            }

            CombineModeCollection cmcoll = new CombineModeCollection();

            cmcoll.GetMulti((CombineModeFields.Name == "deny-overrides"));
            vData.Policy.CombineModeId = cmcoll[0].Id;

            vData.Policy.Save(true);
        }
        private void CreatePolicy(policyData vData, int? id, bool set,bool isLibrary)
        {
            vData.Policy = new PolicyEntity();
            vData.Policy.LibraryId = vData.Library.Id;
            vData.Policy.Description = set ? "new policy set" : "new policy";
            vData.Policy.Set = set;
            vData.Policy.IsLibrary = isLibrary;
            vData.Policy.Target.Description = string.Empty;

            vData.PolicyLink = new PolicyLinkEntity();
            vData.PolicyLink.Policy = vData.Policy;

            if (id.HasValue)
            {
                vData.PolicyLink.ParentId = id;

                PolicyLinkCollection maxColl = new PolicyLinkCollection();
                PredicateExpression pe = new PredicateExpression(PolicyLinkFields.ParentId == id);
                object maxObj = maxColl.GetScalar(PolicyLinkFieldIndex.Order, null, AggregateFunction.Max, pe);
                if (maxObj != null && maxObj != DBNull.Value)
                    vData.PolicyLink.Order = (int)maxObj + 1;
                else
                    vData.PolicyLink.Order = 0;
            }

            CombineModeCollection cmcoll = new CombineModeCollection();
            cmcoll.GetMulti((CombineModeFields.Name == "deny-overrides"));
            vData.Policy.CombineModeId = cmcoll[0].Id;

            vData.Policy.Save(true);
        }
        private static bool DeletePolicyFromLib(int id)
        {
            PredicateExpression pe = new PredicateExpression(PolicyLinkFields.PolicyId == id);
            PredicateExpression peOr = new PredicateExpression(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null));
            peOr.AddWithOr(PolicyLinkFields.ParentId != DBNull.Value);
            pe.Add(peOr);

            PolicyLinkCollection plcoll = new PolicyLinkCollection();
            if (plcoll.GetMulti(pe) && plcoll.Count == 0)
            {
                // Policy isn't referenced in any policy document.
                PolicyEntity delPolicy = new PolicyEntity(id);
                delPolicy.PolicyLink.DeleteMulti();

                DeletePolicy(delPolicy);

                return true;
            }
            else
                return false;
        }
        public ActionResult ReferencePolicy(policyData vData,int id, bool isDoc, FormCollection collection)
        {
            int parse;
            if (int.TryParse(collection["libraryPolicyId"], out parse) && parse > 0)
            {
                PolicyEntity copy = duplicator.dupPolicy(parse);

                vData.PolicyLink = new PolicyLinkEntity();
                vData.PolicyLink.PolicyId = copy.Id;

                if (isDoc)
                {
                    vData.PolicyDocument = new PolicyDocumentEntity(id);
                    vData.PolicyDocument.PolicyLink = vData.PolicyLink;
                    vData.PolicyDocument.Save(true);

                    return RedirectToAction("EditPolicyDoc", new { id = id });
                }
                else
                {
                    vData.PolicyLink.ParentId = id;

                    PolicyLinkCollection maxColl = new PolicyLinkCollection();
                    PredicateExpression pe = new PredicateExpression(PolicyLinkFields.ParentId == id);
                    object maxObj = maxColl.GetScalar(PolicyLinkFieldIndex.Order, null, AggregateFunction.Max, pe);
                    if (maxObj != null && maxObj != DBNull.Value)
                        vData.PolicyLink.Order = (int)maxObj + 1;
                    else
                        vData.PolicyLink.Order = 0;

                    vData.PolicyLink.Save();

                    return RedirectToAction("EditPolicySet", new { id = id });
                }
            }
            else
                return RedirectToAction("AddPolicy", new { id = id, isDoc = isDoc });
        }
        public ActionResult PolicyOrder(policyData vData, int id, FormCollection collection)
        {
            PolicyLinkEntity policyLink = new PolicyLinkEntity(id);
            PolicyLinkCollection coll = new PolicyLinkCollection();

            PredicateExpression pe = new PredicateExpression(PolicyLinkFields.Id != policyLink.Id);
            pe.Add(PolicyLinkFields.ParentId == policyLink.ParentId);
            SortExpression se = null;

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

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

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

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

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

            return RedirectToAction("EditPolicySet", new { id = policyLink.ParentId });
        }
        public ActionResult EditPolicyFromLib(policyData vData, int id)
        {
            PredicateExpression pe = new PredicateExpression(PolicyLinkFields.ParentId == DBNull.Value);
            pe.Add(PolicyLinkFields.PolicyId == id);
            pe.Add(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null, true));

            PolicyLinkCollection plcoll = new PolicyLinkCollection();
            if (plcoll.GetMulti(pe) && plcoll.Count > 0)
                vData.PolicyLink = plcoll[0];
            else
            {
                vData.PolicyLink = new PolicyLinkEntity();
                vData.PolicyLink.PolicyId = id;
                vData.PolicyLink.Save();
            }

            return RedirectToAction("EditPolicy", new { id = vData.PolicyLink.Id });
        }