예제 #1
0
        public IEnumerable <ContentTypeResponseItem> GetContentTypes()
        {
            var result = new List <ContentTypeResponseItem>();

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
                string pluralName;

                if (name.Contains(':') && !contentType.Id.Contains(':'))
                {
                    var nameSplit = name.Split(':');

                    name       = nameSplit.First();
                    pluralName = nameSplit.Last();
                }
                else
                {
                    name       = Humanizer.Humanize(name);
                    pluralName = Pluralizer.Pluralize(name);
                }

                var singleton = SingletonProvider.Get(contentType.Id);

                result.Add(new ContentTypeResponseItem
                {
                    Id                       = contentType.Id,
                    Name                     = name,
                    PluralName               = pluralName,
                    IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                    NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                    IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                    IsSingleton              = singleton != null,
                    Count                    = -1,
                    ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                    ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                });
            }

            return(result.AsReadOnly());
        }
예제 #2
0
        ContentTypeResponseItem GetItem(ContentTypeDescriptor contentType)
        {
            var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
            string pluralName;

            if (name.Contains(':') && !contentType.Id.Contains(':'))
            {
                var nameSplit = name.Split(':');

                name       = nameSplit.First();
                pluralName = nameSplit.Last();
            }
            else
            {
                name       = Humanizer.Humanize(name);
                pluralName = Pluralizer.Pluralize(name);
            }

            var singleton = SingletonProvider.Get(contentType.Id);

            var item = new ContentTypeResponseItem
            {
                Id                       = contentType.Id,
                Name                     = name,
                LowerCaseName            = name.Substring(0, 1).ToLower() + name.Substring(1),
                PluralName               = pluralName,
                LowerCasePluralName      = pluralName.Substring(0, 1).ToLower() + pluralName.Substring(1),
                IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                IsImageable              = typeof(IImageable).IsAssignableFrom(contentType.Type),
                ImageablePropertyName    = typeof(IImageable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(ImageExpressionParser.Parse(contentType.Type), false) : null,
                IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                IsSingleton              = singleton != null,
                Count                    = -1,
                ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                ContentTypeGroups        = ContentTypeGroupMatcher.GetContentTypeGroupsFor(contentType.Id).Select(t => t.Id).ToList().AsReadOnly(),
            };

            return(item);
        }