/// <summary> /// Gets and bulk updates tag groups. Called when the "Get and bulk update groups" button is pressed. /// Expects the CreateTagGroup method to be run first. /// </summary> private bool GetAndBulkUpdateTagGroups() { // Prepare the parameters string where = "TagGroupName LIKE 'MyNew%'"; // Get the data DataSet groups = TagGroupInfoProvider.GetTagGroups(where, null); if (!DataHelper.DataSourceIsEmpty(groups)) { // Loop through the individual items foreach (DataRow groupDr in groups.Tables[0].Rows) { // Create object from DataRow TagGroupInfo modifyGroup = new TagGroupInfo(groupDr); // Update the property modifyGroup.TagGroupDisplayName = modifyGroup.TagGroupDisplayName.ToUpper(); // Update the tag group TagGroupInfoProvider.SetTagGroupInfo(modifyGroup); } return(true); } return(false); }
/// <summary> /// Creates tag group. Called when the "Create group" button is pressed. /// </summary> private bool CreateTagGroup() { // Create new tag group object TagGroupInfo newGroup = new TagGroupInfo(); // Set the properties newGroup.TagGroupDisplayName = "My new group"; newGroup.TagGroupName = "MyNewGroup"; newGroup.TagGroupDescription = ""; newGroup.TagGroupSiteID = CMSContext.CurrentSiteID; newGroup.TagGroupIsAdHoc = false; // Create the tag group TagGroupInfoProvider.SetTagGroupInfo(newGroup); return(true); }
/// <summary> /// Gets and updates tag group. Called when the "Get and update group" button is pressed. /// Expects the CreateTagGroup method to be run first. /// </summary> private bool GetAndUpdateTagGroup() { // Get the tag group TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", CMSContext.CurrentSiteID); if (updateGroup != null) { // Update the property updateGroup.TagGroupDisplayName = updateGroup.TagGroupDisplayName.ToLower(); // Update the tag group TagGroupInfoProvider.SetTagGroupInfo(updateGroup); return(true); } return(false); }
/// <summary> /// Process additional department tasks. /// </summary> public void ProcessDepartment(object sender, EventArgs e) { TreeNode editedNode = Form.EditedObject as TreeNode; // Get department template source document TreeNode sourceNode = DocumentHelper.GetDocument(SiteContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, TreeProvider.ALL_LEVELS, false, null, TreeProvider); // Copy relevant template data to department document. Proceed only when creating a department, updating a department must not rewrite its data with template's data. if (Form.IsInsertMode && (sourceNode != null)) { var excludeColumns = new [] { "DocumentName", "NodeAlias", "DocumentTagGroupID", "DocumentStylesheetID", "DocumentPublishFrom", "DocumentPublishTo" }; DocumentHelper.CopyNodeData(sourceNode, editedNode, new CopyNodeDataSettings(true, true, false, true, true, false, false, false, excludeColumns)); DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #region "Create department tag group" // Get tag group info TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID); // If not exist, create new tag group and set it to document if (tgi == null) { // Populate tag group info fields tgi = new TagGroupInfo(); tgi.TagGroupDisplayName = editedNode.GetDocumentName(); tgi.TagGroupName = editedNode.NodeGUID.ToString(); tgi.TagGroupDescription = ""; tgi.TagGroupSiteID = SiteContext.CurrentSiteID; tgi.TagGroupIsAdHoc = false; // Store tag group info to DB TagGroupInfoProvider.SetTagGroupInfo(tgi); // Update document Tag group ID editedNode.DocumentTagGroupID = tgi.TagGroupID; DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #endregion if (!DataHelper.DataSourceIsEmpty(TemplateDocuments)) { // List of selected documents string selectedDocs = ";" + Value + ";"; // Get already created documents under edited document DataSet dsExistingDocs = DocumentHelper.GetDocuments(SiteContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS, null); StringBuilder sbExistDocs = new StringBuilder(); // Process existing documents to obtain list of aliases foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows) { sbExistDocs.Append(";"); sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLowerCSafe()); } sbExistDocs.Append(";"); string existingDocs = sbExistDocs.ToString(); // Set same ordering as for original template documents bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering; TreeProvider.UseAutomaticOrdering = false; // Process template documents foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows) { if (DocumentHelper.IsDocumentTypeAllowed(editedNode, ValidationHelper.GetInteger(drDoc["NodeClassID"], 0))) { string nodeAlias = drDoc["NodeAlias"].ToString().ToLowerCSafe(); string contNodeAlias = ";" + nodeAlias + ";"; // Set marks bool existing = existingDocs.Contains(contNodeAlias); bool selected = selectedDocs.Contains(contNodeAlias); int nodeId = ValidationHelper.GetInteger(drDoc["NodeID"], 0); string docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], ""); TreeNode srcNode = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider); // Check if section exists if (srcNode != null) { // Copy or remove marked document sections if (selected) { if (!existing) { CopyDocumentSection(srcNode, editedNode, TreeProvider); } } else { if (existing) { // Select node to delete var aliasPath = editedNode.NodeAliasPath + "/" + nodeAlias; var combineWithDefaultCulture = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCombineWithDefaultCulture"); TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); TreeNode delNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliasPath, LocalizationContext.PreferredCultureCode, combineWithDefaultCulture); if (delNode != null) { DeleteDocumentSection(delNode, TreeProvider); } } } // Process additional operations if (selected && !existing) { switch (nodeAlias) { // Create department forum case FORUM_DOCUMENT_ALIAS: CreateDepartmentForumGroup(editedNode); CreateDepartmentForumSearchIndex(editedNode); break; // Create media library case MEDIA_DOCUMENT_ALIAS: CreateDepartmentMediaLibrary(editedNode); break; } } } } } // Set previous ordering TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering; } mDocumentSaved = true; }
protected void btnOK_Click(object sender, EventArgs e) { // Validate form entries string errorMessage = ValidateForm(); if (errorMessage == "") { TagGroupInfo tgi = null; try { // Edit existing tag group if (GroupID > 0) { tgi = TagGroupInfoProvider.GetTagGroupInfo(GroupID); } else { tgi = new TagGroupInfo(); } // Update tag group info fields tgi.TagGroupDisplayName = txtDisplayName.Text; tgi.TagGroupName = txtCodeName.Text; tgi.TagGroupDescription = txtDescription.Text; tgi.TagGroupSiteID = SiteID; // If the new tag group is created set the default value for TagGroupIsAdHoc property if (!IsEdit) { tgi.TagGroupIsAdHoc = false; } // Update tag group info TagGroupInfoProvider.SetTagGroupInfo(tgi); // Redirect to edit page once the new tag group is created if (!IsEdit) { string editUrl = "~/CMSModules/TagGroups/Pages/Development/TagGroup_Edit.aspx?groupid=" + tgi.TagGroupID.ToString() + "&siteid=" + SiteID.ToString() + "&saved=1"; URLHelper.Redirect(editUrl); } // Show message ShowChangesSaved(); // Refresh header ScriptHelper.RefreshTabHeader(Page, "general"); } catch (Exception ex) { // Show error message ShowError(GetString("general.erroroccurred") + " " + ex.Message); } } else { // Show error message ShowError(errorMessage); } }
/// <summary> /// Process additional department tasks. /// </summary> public void ProcessDepartment(object sender, EventArgs e) { TreeNode editedNode = Form.EditedObject as TreeNode; // Get department template source document TreeNode sourceNode = DocumentHelper.GetDocument(CMSContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, 0, false, null, TreeProvider); // Copy relevant template data to department document if (sourceNode != null) { DocumentHelper.CopyNodeData(sourceNode, editedNode, true, true, false, true, true, false, false, "DocumentName;NodeAlias;DocumentTagGroupID;DocumentStylesheetID;DocumentPublishFrom;DocumentPublishTo"); DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #region "Create department tag group" // Get tag group info TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID); // If not exist, create new tag group and set it to document if (tgi == null) { // Populate tag group info fields tgi = new TagGroupInfo(); tgi.TagGroupDisplayName = editedNode.DocumentName; tgi.TagGroupName = editedNode.NodeGUID.ToString(); tgi.TagGroupDescription = ""; tgi.TagGroupSiteID = CMSContext.CurrentSiteID; tgi.TagGroupIsAdHoc = false; // Store tag group info to DB TagGroupInfoProvider.SetTagGroupInfo(tgi); // Update document Tag group ID editedNode.DocumentTagGroupID = tgi.TagGroupID; DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #endregion if (!DataHelper.DataSourceIsEmpty(TemplateDocuments)) { // List of selected documents string selectedDocs = ";" + Value + ";"; // Get already created documents under edited document DataSet dsExistingDocs = DocumentHelper.GetDocuments(CMSContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + TreeProvider.SELECTNODES_REQUIRED_COLUMNS, null); StringBuilder sbExistDocs = new StringBuilder(); // Process existing documents to obtain list of aliases foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows) { sbExistDocs.Append(";"); sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLower()); } sbExistDocs.Append(";"); string existingDocs = sbExistDocs.ToString(); // Set same ordering as for original template documents bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering; TreeProvider.UseAutomaticOrdering = false; // Process template documents foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows) { string nodeAlias = drDoc["NodeAlias"].ToString().ToLower(); string contNodeAlias = ";" + nodeAlias + ";"; // Set marks bool existing = existingDocs.Contains(contNodeAlias); bool selected = selectedDocs.Contains(contNodeAlias); int nodeId = ValidationHelper.GetInteger(drDoc["NodeID"], 0); string docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], ""); TreeNode srcNode = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider); // Check if section exists if (srcNode != null) { // Copy or remove marked document sections if (selected) { if (!existing) { CopyDocumentSection(srcNode, editedNode.NodeID, TreeProvider); } } else { if (existing) { // Select node to delete TreeNode delNode = TreeHelper.SelectSingleNode(editedNode.NodeAliasPath + "/" + nodeAlias); if (delNode != null) { DeleteDocumentSection(delNode, TreeProvider); } } } // Process additional operations if (selected && !existing) { switch (nodeAlias) { // Create department forum case FORUM_DOCUMENT_ALIAS: CreateDepartmentForumGroup(editedNode); CreateDepartmentForumSearchIndex(editedNode); break; // Create media library case MEDIA_DOCUMENT_ALIAS: CreateDepartmentMediaLibrary(editedNode); break; } } } } // Set previous ordering TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering; } mDocumentSaved = true; }