Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }