コード例 #1
0
    /// <summary>
    /// Fires on the grid action.
    /// </summary>
    /// <param name="actionName">Action name</param>
    /// <param name="actionArgument">Action argument</param>
    private void UniGridRelationship_OnAction(string actionName, object actionArgument)
    {
        // Check modify permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return;
        }

        if (actionName == "delete")
        {
            string[] parameters = ((string)actionArgument).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (parameters.Length == 3)
            {
                // Parse parameters
                int leftNodeId         = ValidationHelper.GetInteger(parameters[0], 0);
                int rightNodeId        = ValidationHelper.GetInteger(parameters[1], 0);
                int relationshipNameId = ValidationHelper.GetInteger(parameters[2], 0);

                // If parameters are valid
                if ((leftNodeId > 0) && (rightNodeId > 0) && (relationshipNameId > 0))
                {
                    // Remove relationship
                    RelationshipProvider.RemoveRelationship(leftNodeId, rightNodeId, relationshipNameId);

                    // Log synchronization
                    DocumentSynchronizationHelper.LogDocumentChange(CMSContext.CurrentSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);

                    ShowConfirmation(GetString("relationship.wasdeleted"));
                }
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode != null)
        {
            // Check modify permissions
            if (CMSContext.CurrentUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
            {
                return;
            }

            bool currentNodeIsOnLeftSide = !DefaultSide;
            // Selected node Id
            int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0);

            // Get relatioshipname
            RelationshipNameInfo relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName);

            int relationshipNameId = 0;
            if (relationshipNameInfo != null)
            {
                relationshipNameId = relationshipNameInfo.RelationshipNameId;
            }

            if ((selectedNodeId > 0) && (relationshipNameId > 0))
            {
                try
                {
                    // Left side
                    if (currentNodeIsOnLeftSide)
                    {
                        RelationshipProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId);
                    }
                    // Right side
                    else
                    {
                        RelationshipProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId);
                    }

                    // Log synchronization
                    DocumentSynchronizationHelper.LogDocumentChange(CMSContext.CurrentSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);

                    lblInfo.Text = GetString("relationship.wasadded");
                }
                catch (Exception ex)
                {
                    lblError.Visible = true;
                    lblError.Text    = ex.Message;
                }
            }
        }
    }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Deletes relationship between documents. Called when the "Delete relationship" button is pressed.
    /// Expects the CreateRelationshipName and the CreateRelationship methods to be run first.
    /// </summary>
    private bool DeleteRelationship()
    {
        // Get the relationship name
        RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName");

        if (relationshipName != null)
        {
            // Get the tree structure
            TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

            // Get documents which are in relationship (the Root document is used for both in this example)
            TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);

            // Delete the relationship between documents
            RelationshipProvider.RemoveRelationship(root.NodeID, root.NodeID, relationshipName.RelationshipNameId);

            return(true);
        }

        return(false);
    }
コード例 #4
0
    /// <summary>
    /// Returns true if document is in specified relationship with with selected document.
    /// </summary>
    /// <param name="document">Document to be checked</param>
    /// <param name="side">Relationship side</param>
    /// <param name="relationship">Relationship name</param>
    /// <param name="relatedDocumentPath">Alias path to selected document</param>
    /// <param name="relatedDocumentSite">Selected document site name</param>
    public static bool IsInRelationship(object document, string side, string relationship, string relatedDocumentPath, string relatedDocumentSite)
    {
        TreeNode doc = document as TreeNode;

        if (doc != null)
        {
            int leftNodeID  = 0;
            int rightNodeID = 0;

            // Use site of the checked document when no other is specified
            if (String.IsNullOrEmpty(relatedDocumentSite))
            {
                relatedDocumentSite = doc.NodeSiteName;
            }

            // Prepare left and right document for relationship
            side = side.ToLowerCSafe();
            if (side == "left")
            {
                leftNodeID  = doc.NodeID;
                rightNodeID = TreePathUtils.GetNodeIdByAliasPath(relatedDocumentSite, relatedDocumentPath);
            }
            else if (side == "right")
            {
                leftNodeID  = TreePathUtils.GetNodeIdByAliasPath(relatedDocumentSite, relatedDocumentPath);
                rightNodeID = doc.NodeID;
            }

            // Get relationship ID from relationship name
            RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationship);
            if (relationshipName != null)
            {
                // Check whether relationship between the two documents exists
                return(RelationshipProvider.GetRelationshipInfo(leftNodeID, rightNodeID, relationshipName.RelationshipNameId) != null);
            }
        }

        return(false);
    }
コード例 #5
0
    /// <summary>
    /// Saves relationship.
    /// </summary>
    /// <returns>True, if relatioship was successfully saved.</returns>
    public bool SaveRelationship()
    {
        bool saved = false;

        // Check modify permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
        {
            return(saved);
        }

        bool currentNodeIsOnLeftSide = ValidationHelper.GetBoolean(Request.Params[hdnCurrentOnLeft.UniqueID], false);
        int  selectedNodeId          = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0);

        // Try to get by path if not selected
        if (selectedNodeId <= 0)
        {
            string aliaspath = currentNodeIsOnLeftSide ? txtRightNode.Text.Trim() : txtLeftNode.Text.Trim();

            if (aliaspath != string.Empty)
            {
                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                node = tree.SelectSingleNode(CMSContext.CurrentSiteName, aliaspath, TreeProvider.ALL_CULTURES);
                if (node != null)
                {
                    selectedNodeId = node.NodeID;
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("relationship.selectcorrectrelateddoc");
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = GetString("relationship.selectrelateddoc");
            }
        }

        int selectedValue = 0;

        // Only one reletionship name in textbox
        if ((relationshipNameInfo != null) && (lblRelName.Visible))
        {
            selectedValue = relationshipNameInfo.RelationshipNameId;
        }
        // Value from relationship name selector
        else if (relNameSelector.Visible)
        {
            selectedValue = ValidationHelper.GetInteger(relNameSelector.Value, 0);
        }

        if ((currentNodeId > 0) && (selectedNodeId > 0) && (selectedValue > 0))
        {
            int relationshipNameId = selectedValue;

            try
            {
                // Left side
                if (currentNodeIsOnLeftSide)
                {
                    RelationshipProvider.AddRelationship(currentNodeId, selectedNodeId, relationshipNameId);
                }
                // Right side
                else
                {
                    RelationshipProvider.AddRelationship(selectedNodeId, currentNodeId, relationshipNameId);
                }

                string aliasPath = (node == null) ? TreePathUtils.GetAliasPathByNodeId(currentNodeId) : node.NodeAliasPath;

                // Log synchronization
                DocumentSynchronizationHelper.LogDocumentChange(CMSContext.CurrentSiteName, aliasPath, TaskTypeEnum.UpdateDocument, null);

                saved = true;

                lblInfo.Text    = GetString("general.changessaved");
                lblInfo.Visible = true;
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }

        return(saved);
    }