Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • yumin 51 posts 243 karma points
    Jan 09, 2014 @ 13:55
    yumin
    0

    How to solve this problem by using Union and OrderBy?

    umbraco ver is 7.0.2, umbraco.config data like this:

    <newsCenter nodeName="oneNewsCenter" id,parentId,path...>   
      <news updateDate="2014-01-07T15:18:54" id,parentId,nodeName,path...>
         <publishDate>2014-01-07T00:00:00</publishDate>   
      </news>
    </newsCenter>
    
    <newsCenter nodeName="otherNewsCenter" id,parentId,path...>
      <news updateDate="2014-01-07T17:14:45" id,parentId,nodeName,path...>
         <publishDate></publishDate>
      </news>
    </newsCenter>
    

    How to get news of all the newsCenter merged into one and then sort according publishdate property, if the property is empty by updatedate? The end result I want is like this:

    <news updateDate="2014-01-07T17:14:45" id,parentId,nodeName,path...>
       <publishDate></publishDate>
    </news>
    <news updateDate="2014-01-07T15:18:54" id,parentId,nodeName,path...>
       <publishDate>2014-01-07T00:00:00</publishDate>   
    </news>
    

    Beginning i want to use @Library.NodesById for merge all the newsCenter.Children into one,but a good person tell me @Library is part of the old Razor code and should not be used anymore, so I use Union instead, this is my partial views code:

    var keywords = new List<string>();
    keywords.Add("oneNewsCenter");
    keywords.Add("otherNewsCenter");
    var values = new Dictionary<string, object>();
    values.Add("keywords", keywords);
    
    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var newsCenters = homePage.Children.Where("Name.ContainsAny(keywords)", values);
    
    var allNews = new Umbraco.Web.Models.DynamicPublishedContentList();
    
    foreach (var news in newsCenters.Children)
    {
        allNews.Union(news);
    }
    
    allNews.OrderBy("I do not know how to write");
    

    run this will get a error:

    'Umbraco.Web.Models.DynamicPublishedContentList' has no applicable method named 'Union' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

    how to fix this code or there is a better way to solve this problem?

    thanks in advance

Please Sign in or register to post replies

Write your reply to:

Draft