Ejemplo n.º 1
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;
                }
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates relationship between documents. Called when the "Create relationship" button is pressed.
    /// Expects the CreateRelationshipName method to be run first.
    /// </summary>
    private bool CreateRelationship()
    {
        // Get the relationship name
        RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName");

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

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

            // Create the relationship between documents
            RelationshipProvider.AddRelationship(root.NodeID, root.NodeID, relationshipName.RelationshipNameId);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 3
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);
    }