Copied to clipboard

Flag this post as spam?

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


  • Kristina 33 posts 49 karma points
    Jul 05, 2013 @ 13:32
    Kristina
    0

    Query to select all matchs of the following week

    Hello!

    I'm quite new in Umbraco.

    I'd like to add to the 'Home' page of a footballwebsite the football matchs from all 10 teams which take place the next 7 days. 

    All the matchs are already entered. I have one item 'matchs' in the website tree which has 10 children (the 10 teams). Each children item has several children with document type 'match' and a property 'date'. 

    How do I select now ALL matchs which take place the next 7 days?

    Thanks,

    Kristina

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 05, 2013 @ 13:56
    Jeavon Leopold
    1

    Hi Kristina,

    Are you using Webforms templates (.master) with Razor macro's or Mvc View templates (.cshtml)?

    For a Razor macro I think something like this:

        var nextMatches = Model.XPath("//matches/teams/match").Where("date < DateTime.Now.AddDays(7)").OrderBy("date");
        foreach (var match in nextMatches)
        {
            <p>@match.Name</p>
    
        }

    This assumes that your document types are named "matches", "teams" & "match" but you can update the XPath expression to match your document type aliases.

    If you are using Mvc, let me know.

    Thanks,

    Jeavon

  • Kristina 33 posts 49 karma points
    Jul 05, 2013 @ 14:57
    Kristina
    0

    Thanks for your reply but yes, I'm using MVC..

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 05, 2013 @ 17:15
    Jeavon Leopold
    0

    Ok, using the typed model:

         var nextMatches = Model.Content.AncestorOrSelf(1).Descendants("match").Where(x => x.GetPropertyValue<DateTime>("date") < DateTime.Now.AddDays(7)).OrderBy(x => x.GetPropertyValue<DateTime>("date"));
        foreach (var match in nextMatches)
        {
            <p>match: @match.Name- @match.GetPropertyValue("date")</p>
    
        }    

     

  • Kristina 33 posts 49 karma points
    Jul 11, 2013 @ 10:47
    Kristina
    0

    Thank you. I tried it and got this error:

    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 11, 2013 @ 10:50
    Jeavon Leopold
    0

    Hi Kristina,

    Can you please post your complete code?

    Thanks,

    Jeavon

  • Kristina 33 posts 49 karma points
    Jul 11, 2013 @ 12:14
    Kristina
    0

    @{
      var nextMatches Model.Content.AncestorOrSelf(1).Descendants("Spiel").Where(=x.GetPropertyValue<DateTime>("Datum"DateTime.Now.AddDays(7)).OrderBy(=x.GetPropertyValue<DateTime>("Datum"));
        foreach (var match in nextMatches)
        {
            <p>match@match.GetPropertyValue("Gegner")@match.GetPropertyValue("Datum")</p>

        }    
    }

    I don't understand 'x.GetPropertyValue<DateTime>'

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 11, 2013 @ 12:21
    Jeavon Leopold
    0

    Can you post your entire view code, everything in the template?

Please Sign in or register to post replies

Write your reply to:

Draft