Copied to clipboard

Flag this post as spam?

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


  • Chuck 71 posts 69 karma points
    Jul 21, 2014 @ 23:32
    Chuck
    0

    Where Statement Help Needed

    I'm creating a listing of nodes that contain tour data. The issue I ran into when uploading is that the date format in the provided excel docs wouldn't upload correctly to the datepicker property type so we dumped the date data into a textfield properties instead. I now need to list my nodes by date, and I don't know how to do that converting the properties from strings to dates.

    var tours = Model.NodeById(-1).Descendants("tour");

    the properties on the node for the dates are this startDate & endDate

    I need to get all tours that have a endDate that is equal or greater than todays date, I then need to order them by startDate asc. I have no idea how to write the query for this. I'm contemplating adding datePicker properties and then manually updating the nodes, that should make it easier, any opinions on that?

    Thanks for reading!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 22, 2014 @ 10:17
    Jeavon Leopold
    0

    Hi Chuck,

    Using DynamicNode in a Legacy Razor Macro, something like this:

    DynamicNodeList tours = Library.NodeById(-1).Descendants("tour");
    dynamic filteredCollection = tours.Where(x => x.GetPropertyValue("endDate").AsDateTime().Date >= DateTime.Now.Date).OrderBy(x => x.GetPropertyValue("startDate").AsDateTime());
    

    But are you fixed to using a legacy Razor Macro? This would be better using the recommended Partial View Macro (Umbraco v4.10+)

    Jeavon

  • Chuck 71 posts 69 karma points
    Jul 22, 2014 @ 15:31
    Chuck
    0

    I'm more than happy to switch this to a partial view macro... how would it benefit me here?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 22, 2014 @ 17:41
    Jeavon Leopold
    0

    Ok, did you you try the above snippet?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 22, 2014 @ 17:54
    Jeavon Leopold
    0

    It would be like this in a Partial View Macro:

    var tours = Umbraco.TypedContent(1234).Descendants("tour");
    var filteredCollection = tours.Where(x => x.GetPropertyValue<DateTime>("endDate").Date >= DateTime.Now.Date).OrderBy(x => x.GetPropertyValue<DateTime>("startDate"));
    

    However I very good reason is that Descendants() has much better performance in a Partial View Macro, well everything does but especially that!

Please Sign in or register to post replies

Write your reply to:

Draft