コード例 #1
0
        /// <summary>
        /// Adds each property's Sort Order as defined in Umbraco to a list of GenericPropertyElements
        /// Does not take into account the master doctype properties
        /// </summary>
        /// <param name="properties">List of GenericPropertyElements to add the sort order to</param>
        /// <param name="contentTypeId">Content type where the properties exist</param>
        /// <returns>IEnumerable containing GenericPropertyElements with SortOrder populated</returns>
        private static IEnumerable<GenericPropertyElement> AddSortOrder(this IEnumerable<GenericPropertyElement> properties, int contentTypeId)
        {
            var umbracoProperties = new ContentType(contentTypeId).PropertyTypes.Where(p => p.ContentTypeId == contentTypeId).ToList();

            var _properties = properties.ToList();
            foreach (var property in _properties)
            {
                var umbracoProperty = umbracoProperties.FirstOrDefault(p => p.Alias == property.Alias);
                if (umbracoProperty != null)
                {
                    property.SortOrder = umbracoProperty.SortOrder;
                }
            }

            return properties;
        }
コード例 #2
0
        /// <summary>
        /// Adds each property's Sort Order as defined in Umbraco to a list of GenericPropertyElements
        /// Does not take into account the master doctype properties
        /// </summary>
        /// <param name="properties">List of GenericPropertyElements to add the sort order to</param>
        /// <param name="contentTypeId">Content type where the properties exist</param>
        /// <returns>IEnumerable containing GenericPropertyElements with SortOrder populated</returns>
        private static IEnumerable<GenericPropertyElement> AddSortOrder(this IEnumerable<GenericPropertyElement> properties, int contentTypeId)
        {
            var umbracoProperties = new ContentType(contentTypeId).PropertyTypes.Where(p => p.ContentTypeId == contentTypeId).ToList();

            // By default properties have a 0 sortorder until manually sorted - check for this situation
            var arePropertiesSorted = umbracoProperties.Any(p => p.SortOrder > 0);

            var _properties = properties.ToList();
            foreach (var property in _properties)
            {
                var umbracoProperty = umbracoProperties.FirstOrDefault(p => p.Alias == property.Alias);
                if (umbracoProperty != null)
                {
                    property.SortOrder = arePropertiesSorted ? umbracoProperty.SortOrder : umbracoProperties.IndexOf(umbracoProperty);
                }
            }

            return properties;
        }