protected void CustomUniSelector_OnSelectionChanged(object sender, EventArgs e)
    {
        string SelectedItems      = ValidationHelper.GetString(((UniSelector)sender).Value, "");
        int    RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId;

        int[] NodeIDs = SelectedItems.Split(";|,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => ValidationHelper.GetInteger(x, -1)).ToArray();
        if (MaxRelationships > -1 && GetRelationshipCount() + NodeIDs.Length > MaxRelationships)
        {
            AddMessage(CMS.Base.Web.UI.MessageTypeEnum.Error, "Too many relationships, max allowed is " + MaxRelationships);
            return;
        }

        foreach (int NodeID in NodeIDs)
        {
            if (NodeID > 0)
            {
                if (ddlCurrentNodeDirection.SelectedValue == "LeftNode")
                {
                    RelationshipInfoProvider.AddRelationship(CurrentNodeID, NodeID, RelationshipNameID);
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(NodeID, CurrentNodeID, RelationshipNameID);
                }
            }
        }
        // Save direction
        SessionHelper.SetValue("RelatedPageTreeDirection_" + CurrentNodeID + "_" + UIContext.ElementGuid, ddlCurrentNodeDirection.SelectedValue);
        URLHelper.RefreshCurrentPage();
    }
예제 #2
0
    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode == null)
        {
            return;
        }

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

        bool currentNodeIsOnLeftSide = !DefaultSide;

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

        var relationshipName     = UseAdHocRelationshipName ? RelationshipNameInfoProvider.GetAdHocRelationshipNameCodeName(TreeNode.ClassName, FieldInfo) : RelationshipName;
        var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName);

        int relationshipNameId;

        if (relationshipNameInfo != null)
        {
            relationshipNameId = relationshipNameInfo.RelationshipNameId;
        }
        else
        {
            throw new NullReferenceException("[RelatedDocuments.SaveRelationship]: Missing relationship name to use for relation.");
        }

        if ((selectedNodeId <= 0) || (relationshipNameId <= 0))
        {
            return;
        }

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

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

            ShowConfirmation(GetString("relationship.wasadded"));
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
    protected void AddPagesToRelationship(int[] SelectedNodeIDs)
    {
        int RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId;

        if (MaxRelationships > -1 && GetRelationshipCount() + SelectedNodeIDs.Length > MaxRelationships)
        {
            AddMessage(CMS.Base.Web.UI.MessageTypeEnum.Error, "Too many relationships, max allowed is " + MaxRelationships);
            return;
        }

        foreach (int NodeID in SelectedNodeIDs)
        {
            if (NodeID > 0)
            {
                if (ddlCurrentNodeDirection.SelectedValue == "LeftNode")
                {
                    RelationshipInfoProvider.AddRelationship(CurrentNodeID, NodeID, RelationshipNameID);
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(NodeID, CurrentNodeID, RelationshipNameID);
                }
            }
        }
        // Save direction
        SessionHelper.SetValue("RelatedPageTreeDirection_" + CurrentNodeID + "_" + UIContext.ElementGuid, ddlCurrentNodeDirection.SelectedValue);
        URLHelper.RefreshCurrentPage();
    }
    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode == null)
        {
            return;
        }

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

        bool currentNodeIsOnLeftSide = !DefaultSide;

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

        // Get relationshipNameId
        var relationshipNameId = GetRelationshipNameId();

        if ((selectedNodeId <= 0) || (relationshipNameId <= 0))
        {
            return;
        }

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

            if (RelHelper.IsStagingEnabled())
            {
                // Log synchronization
                DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
            }

            ShowConfirmation(GetString("relationship.wasadded"));
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
예제 #5
0
        protected void ProcessCategory(int productNodeId, string categoryPath)
        {
            if (!string.IsNullOrEmpty(categoryPath))
            {
                var categoryItem = FindProductCategory(categoryPath);
                if (categoryItem != null)
                {
                    RelationshipInfoProvider.AddRelationship(productNodeId, categoryItem.NodeID,
                                                             productCategoryProductRelationshipID);
                }
                // if product detail or product category are null log error and add to error tracker (add error tracking custom table)fields, product detail name, product category name and explanation of what's wrong
                else
                {
                    // Prepares the code name (class name) of the custom table to which the data record will be added
                    string customTableClassName = "PbcLinear.ProcessCategoryErrors";

                    // Gets the custom table
                    DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
                    if (customTable != null)
                    {
                        // Creates a new custom table item
                        CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);

                        // Sets the values for the fields of the custom table (ItemText in this case)
                        newCustomTableItem.SetValue("ProductNodeId", productNodeId);
                        newCustomTableItem.SetValue("CategoryPath", categoryPath);
                        newCustomTableItem.SetValue("Error", "categoryItem is null ");

                        if (productNodeId == 0)
                        {
                            var newError = newCustomTableItem.GetValue("Error") + " productNodeId is empty";
                            newCustomTableItem.SetValue("Error", newError);
                        }

                        if (!string.IsNullOrEmpty(categoryPath))
                        {
                            var newError = newCustomTableItem.GetValue("Error") + " categoryPath is empty";
                            newCustomTableItem.SetValue("Error", newError);
                        }

                        // Save the new custom table record into the database
                        newCustomTableItem.Insert();
                    }
                }
            }
        }
예제 #6
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(MembershipContext.AuthenticatedUser);

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

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

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Saves relationship.
    /// </summary>
    public void SaveRelationship()
    {
        if (TreeNode == null)
        {
            return;
        }

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

        bool currentNodeIsOnLeftSide = !DefaultSide;

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

        if (BindOnPrimaryNodeOnly)
        {
            selectedNodeId = RelHelper.GetPrimaryNodeID(selectedNodeId);
        }

        var relationshipName     = RelationshipName;
        var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName);

        int relationshipNameId;

        if (relationshipNameInfo != null)
        {
            relationshipNameId = relationshipNameInfo.RelationshipNameId;
        }
        else
        {
            throw new NullReferenceException("[RelatedDocuments.SaveRelationship]: Missing relationship name to use for relation.");
        }

        if ((selectedNodeId <= 0) || (relationshipNameId <= 0))
        {
            return;
        }

        try
        {
            // Test to make sure the selected page is a Right Side macro-allowed page or left side, and also matches the Page type limiter
            var SelectedTreeNode = (AllowAllTypes ? new DocumentQuery() : new DocumentQuery(AllowedPageTypes)).WhereEquals("NodeID", selectedNodeId).FirstOrDefault();

            // If null probably not an allowed page type, but we will need it to validate below
            if (SelectedTreeNode == null)
            {
                SelectedTreeNode = new DocumentQuery().WhereEquals("NodeID", selectedNodeId).FirstOrDefault();
            }
            var CurrentPageMacroResolver = MacroResolver.GetInstance();
            CurrentPageMacroResolver.SetNamedSourceData("CurrentDocument", TreeNode);
            var PageMacroResolver = MacroResolver.GetInstance();
            PageMacroResolver.SetNamedSourceData("CurrentDocument", SelectedTreeNode);

            // Left side
            if (currentNodeIsOnLeftSide)
            {
                if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower()))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType"));
                }
                else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid"));
                }
                else if (TreeNode.NodeID == SelectedTreeNode.NodeID)
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf"));
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId);

                    if (RelHelper.IsStagingEnabled())
                    {
                        // Log synchronization
                        DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
                    }

                    ShowConfirmation(GetString("relationship.wasadded"));
                }
            }
            // Right side
            else
            {
                if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower()))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType"));
                }
                else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false))
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid"));
                }
                else if (TreeNode.NodeID == SelectedTreeNode.NodeID)
                {
                    AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf"));
                }
                else
                {
                    RelationshipInfoProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId);

                    if (RelHelper.IsStagingEnabled())
                    {
                        // Log synchronization
                        DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, SelectedTreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider);
                    }

                    ShowConfirmation(GetString("relationship.wasadded"));
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
    /// <summary>
    /// Saves relationship.
    /// </summary>
    /// <returns>True, if relatioship was successfully saved.</returns>
    public bool SaveRelationship()
    {
        bool saved = false;

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

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

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

            if (aliaspath != string.Empty)
            {
                node = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliaspath, TreeProvider.ALL_CULTURES);
                if (node != null)
                {
                    selectedNodeId = node.NodeID;
                }
                else
                {
                    ShowError(GetString("relationship.selectcorrectrelateddoc"));
                }
            }
            else
            {
                ShowError(GetString("relationship.selectrelateddoc"));
            }
        }

        int selectedValue = 0;

        // Only one relationship 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)
                {
                    RelationshipInfoProvider.AddRelationship(currentNodeId, selectedNodeId, relationshipNameId);
                }
                // Right side
                else
                {
                    RelationshipInfoProvider.AddRelationship(selectedNodeId, currentNodeId, relationshipNameId);
                }

                // Log synchronization for single document
                TreeNode currentNode = node ?? tree.SelectSingleNode(currentNodeId);
                DocumentSynchronizationHelper.LogDocumentChange(currentNode, TaskTypeEnum.UpdateDocument, tree);

                saved = true;

                ShowChangesSaved();
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }

        return(saved);
    }