Example #1
0
        /// <summary>
        /// Gets the dictionary for the Archetype model
        /// </summary>
        /// <param name="mapper">Umbraco mapper</param>
        /// <param name="archetypeModel">Archetype model</param>
        /// <returns>Collection of dictionaries</returns>
        private static IEnumerable <Dictionary <string, object> > GetDictionary(IUmbracoMapper mapper, ArchetypeModel archetypeModel)
        {
            var propertyDictionary = archetypeModel
                                     .Select(item => item.Properties.ToDictionary(m => m.Alias, m => GetTypedValue(mapper, m)));
            var dictionary = propertyDictionary
                             .Zip(archetypeModel
                                  .Select(item => new Dictionary <string, object> {
                { "alias", item.Alias }
            }),
                                  (a, b) => a.Concat(b).ToDictionary(k => k.Key, k => k.Value,
                                                                     StringComparer.InvariantCultureIgnoreCase))
                             .ToList();

            return(dictionary);
        }
Example #2
0
        public static object MapCallouts(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propName, bool isRecursive)
        {
            var result = new List <CalloutViewModel>();

            ArchetypeModel archetypeModel = contentToMapFrom.GetPropertyValue <ArchetypeModel>(propName, isRecursive, null);

            if (archetypeModel != null)
            {
                var archetypeAsDictionary = archetypeModel
                                            .Select(item => item.Properties.ToDictionary(m => m.Alias, m => GetTypedValue(m), StringComparer.InvariantCultureIgnoreCase))
                                            .ToList();
                mapper.MapCollection(archetypeAsDictionary, result);
            }

            return(result);
        }