Copied to clipboard

Flag this post as spam?

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


  • keilo 568 posts 1023 karma points
    Jul 08, 2014 @ 16:12
    keilo
    0

    Few questions

    First of all thank you for the well though package.

    I have few questions which I hope you can shed some light on;

    a) if one is trying to create a Json file with the foreach iterating calendar events, i cant seem to get the isNotLast working for the "last item" in the foreach loop; tried ce.IsNotLast(",") and also ce.content.IsNotLast(",") withtout success. Any ideas how this can be achieved?

    @foreach (CalendarEvent ce in Calendar.getEvents(startDate, endDate, "calendar")){

      @:{

      @:  "title": "@ce.content.Name",

      @:  "start": "@ce.startDate.ToString("yyyy-MM-ddTHH:mm")", 

      @*:  "end":   "@ce.endDate.ToString("yyyy-MM-ddTHH:mm")",*@

      @:  "url":   "@ce.content.Url"

      @:}@ce.content.IsNotLast(",")

    }

     

    b) How one can iterate the "calendar" properties on specific DocumentTypeAlias,. I cant seem to figure that out with the given foreach example;

    @foreach (CalendarEvent ce in Calendar.getEvents(startDate, endDate, "calendar")){

    // I can check for DocumentTypeAlias here via ce.content but is there a more efficient way that one can specify this in the foreach statement?

    }

     

    many thanks in advance!

  • Ole Martin Bakke 112 posts 624 karma points
    Jul 08, 2014 @ 16:35
    Ole Martin Bakke
    100

    Hi!

    I'll try to answer your questions.

    a) As far as I know, the IsNotLast-helper can only be used when you iterate a collection of DynamicNodes, and what you get here is a List<CalendarEvent>. You can make a json containing all the data by doing something like
    var json = Newtonsoft.Json.JsonConvert.SerializeObject(getEvents(startDate, endDate, "calendar"));

    Or you can create your own list like this:

    List<dynamic> events = new List<dynamic>();

    foreach(CalendarEvent ce in Calendar.getEvents(startDate, endDate, "calendar")){

    events.Add(new {

        title = ce.Name,

       start = ce.startDate.ToString("yyyy-MM-ddTHH:mm"),

    url = ce.content.Url

    });

    }

    var json = Newtonsoft.Json.JsonConvert.SerializeObject(events);

     

     

    b)  there are several methods available to you

    The one you use, where you use startdate, enddate and propertytype.

    getEvents(DateTime startDate, DateTime endDate, string propertyType)

    The one you ask for where you enter the documenttype

    getEvents(DateTime startDate, DateTime endDate, string propertyType, string documentType)

    One where you also can provide a startnode as a dynamicpublishedcontent, e.g. CurrentPage

    getEvents(DateTime startDate, DateTime endDate, string propertyType, string documentType, DynamicPublishedContent startNode)

    And one with startNode and not document type

    getEvents(DateTime startDate, DateTime endDate, string propertyType, DynamicPublishedContent startNode)

     

     

    Hope this helps you out.

     

    Best regards Ole Martin

  • keilo 568 posts 1023 karma points
    Jul 08, 2014 @ 17:03
    keilo
    0

    Hi Ole!

    Thank you for the pointers. Your reply really sheds light on the way this datatype can be flexibly used (tried document type and doctype with starting node) - you have thought of all the combinations already... Amazing stuff! 

    Much appreciated. Thanks again!

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft