Пример #1
0
        public static void SetPropertyTags(IContentBase content, Property property, object convertedPropertyValue, string delimiter, bool replaceTags, string tagGroup, TagValueType valueType)
        {
            if (convertedPropertyValue == null)
            {
                convertedPropertyValue = "";
            }

            switch (valueType)
            {
                case TagValueType.FromDelimitedValue:
                    var tags = convertedPropertyValue.ToString().Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
                    content.SetTags(property.Alias, tags, replaceTags, tagGroup);
                    break;
                case TagValueType.CustomTagList:
                    //for this to work the object value must be IENumerable<string>
                    var stringList = convertedPropertyValue as IEnumerable<string>;
                    if (stringList != null)
                    {
                        content.SetTags(property.Alias, stringList, replaceTags, tagGroup);
                    }
                    break;
            }
        }
        ///// <summary>
        ///// Returns the tags for the given property
        ///// </summary>
        ///// <param name="content"></param>
        ///// <param name="propertyTypeAlias"></param>
        ///// <param name="tagGroup"></param>
        ///// <returns></returns>
        ///// <remarks>
        ///// The tags returned are only relavent for published content & saved media or members
        ///// </remarks>
        //public static IEnumerable<ITag> GetTags(this IContentBase content, string propertyTypeAlias, string tagGroup = "default")
        //{

        //}

        /// <summary>
        /// Sets tags for the property - will add tags to the tags table and set the property value to be the comma delimited value of the tags.
        /// </summary>
        /// <param name="content">The content item to assign the tags to</param>
        /// <param name="propertyTypeAlias">The property alias to assign the tags to</param>
        /// <param name="tags">The tags to assign</param>
        /// <param name="replaceTags">True to replace the tags on the current property with the tags specified or false to merge them with the currently assigned ones</param>
        /// <param name="tagGroup">The group/category to assign the tags, the default value is "default"</param>
        /// <returns></returns>
        public static void SetTags(this IContentBase content, string propertyTypeAlias, IEnumerable <string> tags, bool replaceTags, string tagGroup = "default")
        {
            content.SetTags(TagCacheStorageType.Csv, propertyTypeAlias, tags, replaceTags, tagGroup);
        }