Пример #1
0
        /// <summary>
        ///     Returns a list of content types where a particular composition content type is used
        /// </summary>
        /// <param name="type">Type of content Type, eg documentType or mediaType</param>
        /// <param name="contentTypeId">Id of composition content type</param>
        /// <returns></returns>
        protected ActionResult <IEnumerable <EntityBasic> > PerformGetWhereCompositionIsUsedInContentTypes(
            int contentTypeId, UmbracoObjectTypes type)
        {
            var id = 0;

            if (contentTypeId > 0)
            {
                IContentTypeComposition?source;

                switch (type)
                {
                case UmbracoObjectTypes.DocumentType:
                    source = ContentTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MediaType:
                    source = MediaTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MemberType:
                    source = MemberTypeService.Get(contentTypeId);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
                }

                if (source == null)
                {
                    return(NotFound());
                }

                id = source.Id;
            }

            IEnumerable <IContentTypeComposition> composedOf;

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                composedOf = ContentTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MediaType:
                composedOf = MediaTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MemberType:
                composedOf = MemberTypeService.GetComposedOf(id);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            EntityBasic TranslateName(EntityBasic e)
            {
                e.Name = TranslateItem(e.Name);
                return(e);
            }

            return(composedOf
                   .Select(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>)
                   .WhereNotNull()
                   .Select(TranslateName)
                   .ToList());
        }