从存储库中的代码获取媒体

时间:2014-10-09 09:18:37

标签: umbraco umbraco7

我在Umbraco 7工作,我正在尝试将数据映射到我创建的自定义实体。映射字符串,等等。很简单但有人可以告诉我如何映射从媒体选择器,多媒体选择器和内容选择器创建的内容?

我的简单模型:

public class Frontpage : Master
{
    public string Headline { get; set; }
    public HtmlString Content { get; set; }
    public string Image { get; set; }

    public IEnumerable<XXXX> Images { get; set; } <-- What class/type should I place here (IMedia mayby)
    public IEnumerable<XXXX> Links { get; set; }    <-- What class/type should I place here (IContent mayby)
    public IEnumerable<NewsItem> News { get; set; }
}

在我的存储库中,我有这个方法:

public Frontpage GetFrontPage(IPublishedContent content)
{
    var imageObject = <-- How do I map a image from image picker here
    var imagesObject = <-- How do I map images from multi media picker here
    var linksObject = <-- How do I map a multiple links from content picker here

    var model = new Frontpage {
        Headline = !string.IsNullOrEmpty(content.GetPropertyValue<string>("headline")) ? content.GetPropertyValue<string>("headline") : content.Name,
        Content = new HtmlString(content.GetPropertyValue<string>("content")),
        Image = <-- And finally what goes here,
        Images = <-- And finally what goes here,
        Links = <-- And finally what goes here,
        News = null
    };

    return model;
}

我希望这对你们中的一些人/女孩有所帮助; o)

1 个答案:

答案 0 :(得分:0)

我发现我可以在我的存储库中调用TypedMedia和TypedContent,如下所示:

var helper = new UmbracoHelper(UmbracoContext.Current);
var image = helper.TypedMedia(content.GetPropertyValue("image"));
var link = helper.TypedContent(content.GetPropertyValue("link"));
通过这种方式,我可以获得媒体和内容选择器所需的内容; o)