Mapping fields from REST webapi?

Is there a way to specify how fields returned from a webapi map to a schedule entry?

My webapi is using CamelCasePropertyNamesContractResolver and I have tons of angular code relaying on it. Removing it is not an option.

Because of this resolver, my webapi returns schedule fields with a casing mismatch ("id" instead of the expected "Id", "subject" instead of "Subject", etc) which seems to be the reason the schedule control to show no appointments.

I am looking for the syntax, if any, I could use when defining the DataSource (or datamanager?) object in Razor so I can "map" the fields returned by my api to the schedule so I can tell it to use "id" as "Id", "subject" as "Subject", etc

I have looked at the documentation to not avail. The closest I have gotten is https://help.syncfusion.com/aspnetmvc/schedule/data-binding but it seems to apply to an older version of syncfusion and that api syntax doesn't seem to apply.


3 Replies

VS Velmurugan S Syncfusion Team June 11, 2018 01:02 PM UTC

Hi Victor, 
Thanks for Contacting Syncfusion support. 
We are sorry for the delay and we have analyzed your mentioned scenario and this reported issue can be resolved by mapping the Schedule event settings fields within the ActionBegin event. Please refer to the following code example to map the fields with the Schedule control event settings fields. 
@(Html.EJS() 
              .Schedule("schedule") 
              .EventSettings(es => es.DataSource(dataManger => 
              { 
                  dataManger.Url("/api/districts/" + Model.DistrictId + "/calendar") 
                      .Adaptor("WebApiAdaptor"); 
              })) 
              .StartHour("06:00") 
              .EndHour("19:00") 
              .ActionBegin("onActionBegin") 
              .Render() 
) 
 
<script type="text/javascript"> 
    function onActionBegin() { 
        var scheduleObj = document.getElementById('schedule').ej2_instances[0]; 
        scheduleObj.eventSettings.fields = { 
            id: { name: 'id' }, 
            subject: { name: 'subject' }, 
            location: { name: 'location' }, 
            description: { name: 'description' }, 
            startTime: { name: 'startTime' }, 
            endTime: { name: 'endTime' }, 
            isAllDay: { name: 'isAllDay' }, 
            recurrenceID: { name: 'recurrenceID' }, 
            recurrenceRule: { name: 'recurrenceRule' }, 
            recurrenceException: { name: 'recurrenceException' } 
        }; 
    } 
</script> 
 
Also, we request you look into our below UG link to know about the JS2 Schedule control events. 
Kindly try with the above suggestion and let us know if you need any further assistance on this. 
Regards, 
Velmurugan


VP Victor Perez June 11, 2018 06:15 PM UTC

Thank you, this worked and was able to remove the "hack" I had to put in my api controller to render the field names in the way this control was expecting.

One side note: some of your old documentation refers to "AllDay" instead of "IsAllDay". Also, I can't find any documentation detailing all the fields that need to be defined for a schedule object: so far I have had to reverse-engineer them from trying different combination of appointments and looking at the post data.



VS Velmurugan S Syncfusion Team June 12, 2018 09:37 AM UTC

Hi Victor,   
  
Most welcome.   
  
We are glad that our provided solution helped you to resolve your problem.   
Also, we regret for the inconvenience, currently we are drafting complete UG documentation on how to use the scheduler in combination with various other features and will publish it soon in this Volume-2 2018 release. Until then, we kindly request you to have a look at our below UG link to know about the Schedule API and event fields.   
  
  
Kindly look at our above UG links and let us know if you need any further assistance on this.   
  
Regards,   
Velmurugan   


Loader.
Up arrow icon