通过 UmbracoApiController 发送文档类型的内容

Sending The Content of a Document Type Via UmbracoApiController

如何通过Web输出某种文档类型的发布内容Api?

示例: 我有一个名为

的文档类型

评论

它具有三个属性 "Name, Date, Text" 我想将这些属性的值输出到 UmbracoApiController 以便我可以在其他网站中使用它 有什么想法吗 ?提前致谢

 public class  publishedContentapiController  : UmbracoApiController
{
    //What Logic To Put Here In Order to get the Content OF published 
   // Document Types With the Alias "comment" 
}

下面的代码通过 webapi

输出 all 类型 "comment" 的文档
public class  publishedContentapiController  : UmbracoApiController
{
    public IHttpActionResult GetComments()
    {
        // Create an UmbracoHelper for retrieving published content
        var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);

        // Get all comments from the Umbraco tree (this is not a optimized way of doing this, since it queries the complete Umbraco tree)
        var comments = umbracoHelper.TypedContentAtRoot().DescendantsOrSelf("comment");     

        // Map the found nodes from IPublishedContent to a strongly typed object of type Comment (defined below)
        var mappedComments = comments.Select(x => new Comment{
            Name = x.Name,                              // Map name of the document
            Date = x.CreatedTime,                       // Map createdtime
            Text = x.GetPropertyValue<string>("text")   // Map custom property "text"
        });

        return Ok(mappedComments);
    }


    private class Comment
    {
        public string Name { get; set; }
        public DateTime Date { get; set; }
        public string Text { get; set; }
    }
}

免责声明:代码未经测试,显然需要重构