Copied to clipboard

Flag this post as spam?

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


  • qrayg 24 posts 92 karma points
    Nov 22, 2016 @ 16:30
    qrayg
    0

    Limit List by Number and Property Value

    I'm trying to make a macro that displays all events/entries using getEvents but limit the results to a number (controlled by a macro parameter) as well as a property value on the actual entry.

    Apparently I can't use .Where() on the collection?

    This is what I have right now and it works:

    var eLimit = Convert.ToInt32((Model.MacroParameters["limit"] != null && Model.MacroParameters["limit"].ToString() != "null" && Model.MacroParameters["limit"].ToString() != "") ? Model.MacroParameters["limit"] : "3");
    List<CalendarEvent> events = Calendar.getEvents(DateTime.Now.Date, DateTime.Now.AddMonths(12), "calDate", "calendarEvent", false);
    foreach(var item in events.Take(eLimit)){
      <p>@item.content.Name</p>
    }
    

    BUT, I want to limit this even more to only events that have the checkbox calFeatured checked. I tried events.Where("calFeatured = true").Take(eLimit) but it errors and says KS.Umbraco7.Calendar.Core.CalendarEvent does not contain a definition for Where. I know this probably wouldn't work anyway as I'd have to do something like item.content.GetPropertyValue("calFeatured") = true or something, but how do I do that in a Where clause and how do I stack that before the Take()?

    Basically, I want all events that have the bool property calFeatured checked but then limited to the latest int controlled via a macro property. I can do one or the other, but not both in the correct order.

    Is there a better way to do what I want? I'm new to razor and C#... I'm learning as I go but my real strength is Frontend so this is all very foreign to me.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies