/// <summary> /// Insert this current category. /// </summary> /// <returns>Return the new category id if success, -1 if the name already exists, -2 if parent not found.</returns> public int Insert(int userId) { int result; result = CategoryExtProvider.CM_InsertCategory(this.PortalId, this.Name, this.Description, this.ToolTip, this.IsDefaultXSL, this.XSLFile, this.Icon, this.ParentId, this.DefaultFolder, this.TypeId, this.IsNeedPublic, this.IsNeedApprove, this.ExtendedSettings, this.Order, this.LanguageId, this.CultureCode, this.Dip1, this.Dip2, this.Dip3, this.Dip4, this.Dip5, this.AddInfo1, this.AddInfo2, this.AddInfo3, this.AddInfo4, this.AddInfo5); //If insert successfully, start to update related categories. if (result != -1 && this.ParentId != -1) { string strOldRelatedString; int i; DataTable tblRelated; tblRelated = CategoryExtProvider.CM_GetChildrenCategories(this.ParentId); strOldRelatedString = ","; if (tblRelated.Rows.Count > 0) { for (i = 0; i < tblRelated.Rows.Count; i++) { strOldRelatedString = strOldRelatedString + tblRelated.Rows[i]["CategoryId"].ToString() + ","; } } CategoryExtProvider.CM_UpdateRelatedCategory(result, PortalId, strOldRelatedString); } return(result); }
/// <summary> /// Fill this category with information from the database. /// </summary> public int Fill(int categoryId) { DataTable tblUnit = CategoryExtProvider.CM_GetCategory(categoryId); if (tblUnit.Rows.Count > 0) { this.CategoryId = categoryId; this.Name = tblUnit.Rows[0]["Name"].ToString(); this.ToolTip = tblUnit.Rows[0]["ToolTip"].ToString(); this.ParentId = int.Parse(tblUnit.Rows[0]["ParentId"].ToString()); m_level = int.Parse(tblUnit.Rows[0]["Level"].ToString()); m_path = tblUnit.Rows[0]["Path"].ToString(); this.PortalId = int.Parse(tblUnit.Rows[0]["PortalId"].ToString()); this.IsDeleted = bool.Parse(tblUnit.Rows[0]["IsDeleted"].ToString()); this.DefaultFolder = tblUnit.Rows[0]["defaultFolder"].ToString(); this.IsDefaultXSL = bool.Parse(tblUnit.Rows[0]["IsDefaultXSL"].ToString()); this.XSLFile = tblUnit.Rows[0]["XSLFile"].ToString(); this.Icon = tblUnit.Rows[0]["Icon"].ToString(); this.Description = tblUnit.Rows[0]["Description"].ToString(); this.TypeId = int.Parse(tblUnit.Rows[0]["TypeId"].ToString()); this.IsNeedApprove = bool.Parse(tblUnit.Rows[0]["IsNeedApprove"].ToString()); this.IsNeedPublic = bool.Parse(tblUnit.Rows[0]["IsNeedPublic"].ToString()); this.ExtendedSettings = tblUnit.Rows[0]["ExtendedSettings"].ToString(); this.m_Order = int.Parse(tblUnit.Rows[0]["Order"].ToString()); this.m_LanguageId = int.Parse(tblUnit.Rows[0]["LanguageId"].ToString()); this.m_CultureCode = tblUnit.Rows[0]["CultureCode"].ToString(); this.m_Dip1 = bool.Parse(tblUnit.Rows[0]["Dip1"].ToString()); this.m_Dip2 = bool.Parse(tblUnit.Rows[0]["Dip2"].ToString()); this.m_Dip3 = bool.Parse(tblUnit.Rows[0]["Dip3"].ToString()); this.m_Dip4 = bool.Parse(tblUnit.Rows[0]["Dip4"].ToString()); this.m_Dip5 = bool.Parse(tblUnit.Rows[0]["Dip5"].ToString()); this.m_AddInfo1 = tblUnit.Rows[0]["AddInfo1"].ToString(); this.m_AddInfo2 = tblUnit.Rows[0]["AddInfo2"].ToString(); this.m_AddInfo3 = tblUnit.Rows[0]["AddInfo3"].ToString(); this.m_AddInfo4 = tblUnit.Rows[0]["AddInfo4"].ToString(); this.m_AddInfo5 = tblUnit.Rows[0]["AddInfo5"].ToString(); return(this.CategoryId); } else { FillEmpty(); return(-1); } }
/// <summary> /// Copy the information of the current category into a new one. /// </summary> /// <param name="strNewTitle">The title for the new category</param> /// <param name="strNewDescription">The description for the new category</param> /// <param name="userId">The action owner</param> /// <returns>Return the new category id if success, -1 if the name already exists, -2 if parent not found.</returns> public int Copy(string strNewTitle, string strNewDescription, int userId) { int newId, i; int sampleId; string strOldRelatedString = ""; sampleId = this.CategoryId; //Change the current category into -1 this.CategoryId = -1; this.Name = strNewTitle; if (strNewDescription != "") { this.Description = strNewDescription; } //Insert a new category with the information of the sample one newId = Insert(userId); if (newId > 0) { //Copy roles CategoryExtProvider.CM_CopyCategoryRoles(sampleId, newId); //Copy tag groups CategoryExtProvider.CM_CopyCategoryTagGroups(sampleId, newId); DataTable tblRelated; //Copy related categories tblRelated = CategoryExtProvider.CM_GetRelatedCategories(sampleId, TypeId); strOldRelatedString = ","; strOldRelatedString = strOldRelatedString + sampleId.ToString() + ","; if (tblRelated.Rows.Count > 0) { for (i = 0; i < tblRelated.Rows.Count; i++) { strOldRelatedString = strOldRelatedString + tblRelated.Rows[i]["CategoryId"].ToString() + ","; } } CategoryExtProvider.CM_UpdateRelatedCategory(newId, PortalId, strOldRelatedString); } // Change the current category back to its old information. this.CategoryId = sampleId; return(newId); }
/// <summary> /// Delete the current category permanently. /// </summary> public void Remove(int userId) { CategoryExtProvider.CM_DeleteCategory(this.CategoryId, this.PortalId, 0); }