Exemplo n.º 1
0
        public async Task <HttpResponseMessage> GetMetadata(int id)
        {
            if (!await AuthorizationService.AuthorizeAsync(ClaimsPrincipal, new ContentResourceAccess(id), AuthorizationPolicies.ContentRead))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var found = Services.ContentService.GetById(id);

            if (found == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var helper = new ContentControllerHelper(Services.TextService);

            var result = new ContentMetadataRepresentation(LinkTemplates.Content.MetaData, LinkTemplates.Content.Self, found.Key)
            {
                Fields         = helper.GetDefaultFieldMetaData(ClaimsPrincipal),
                Properties     = Mapper.Map <IDictionary <string, ContentPropertyInfo> >(found),
                CreateTemplate = Mapper.Map <ContentCreationTemplate>(found)
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 2
0
        protected override ContentMetadataRepresentation GetMetadataForItem(int id)
        {
            var found = MediaService.GetById(id);

            if (found == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var result = new ContentMetadataRepresentation(LinkTemplate, id)
            {
                Fields         = GetDefaultFieldMetaData(),
                Properties     = Mapper.Map <IDictionary <string, ContentPropertyInfo> >(found),
                CreateTemplate = Mapper.Map <ContentTemplate>(found)
            };

            return(result);
        }
        protected override ContentMetadataRepresentation GetMetadataForItem(int id)
        {
            var found = Umbraco.TypedContent(id);

            if (found == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var result = new ContentMetadataRepresentation(LinkTemplate, id)
            {
                Fields = GetDefaultFieldMetaData(),
                // NOTE: we cannot determine this from IPublishedContent
                Properties = null,
                // NOTE: null because IPublishedContent is readonly
                CreateTemplate = null
            };

            return(result);
        }