Scheduler Services

17 Aug 201711 minutes to read

Essential Scheduler makes use of specific service actions which are described below - in order to fetch records from the remote server and bind to it, to export it wholly in a PDF format and also to export/import its appointment content in an ICS format. It makes use of ejDataManager, in order to bind the remote data to it.

Binding Scheduler data

Description

Fetch and bind the records from DefaultSchedules table to the Scheduler.

URL

http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/GetScheduleData/

Parameter

$top 10
CurrentAction Load
CurrentDate Mon May 05 2014 05:00:00 GMT 0530 (India Standard Time)
CurrentView week

Request

  • JS
  • var dataManger = new ej.DataManager(
    {
        url: "http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/GetScheduleData/"
    });

    Action getting invoked in C Sharp

  • C#
  • public IEnumerable<DefaultSchedule> GetScheduleData()
        {
            var data = new ScheduleDataEntities().DefaultSchedules.ToList();
            return data;
        }

    Response

    Status Code: 200 OK

    Content-Type: application/json; charset=utf-8

    Response (JSON):

  • JS
  • [ {"Id":100,"Subject":"Bering Sea Gold","Location":"chennai","StartTime":"2014-05-02T09:00:00","EndTime":"2014-05-02T10
    :30:00","Description":null,"Owner":1,"Priority":null,"Recurrence":1,"RecurrenceType":null,"RecurrenceTypeCount"
    :null,"Reminder":null,"Categorize":"1,2","CustomStyle":null,"AllDay":false,"RecurrenceStartDate":null
    ,"RecurrenceEndDate":null,"RecurrenceRule":"FREQ=DAILY;INTERVAL=2;COUNT=10","StartTimeZone":null,"EndTimeZone"
    :null}, 
      {"Id":101,"Subject":"Bering Sea Gold","Location":"mum","StartTime":"2014-05-02T04:00:00","EndTime"
    :"2014-05-02T05:00:00","Description":null,"Owner":1,"Priority":null,"Recurrence":0,"RecurrenceType":null
    ,"RecurrenceTypeCount":null,"Reminder":null,"Categorize":"2","CustomStyle":null,"AllDay":false,"RecurrenceStartDate"
    :null,"RecurrenceEndDate":null,"RecurrenceRule":null,"StartTimeZone":null,"EndTimeZone":null},
    
    //... 14 more records
    ]

    ICS Export Service

    Description

    To export appointment data from Scheduler into an ICS file format.

    URL

    http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/ICSExport/ - To export Scheduler appointments in ICS format.

    Parameters

    ScheduleApps {"id":"Id","subject":"Subject","description":"Description","startTime":"StartTime","endTime":"EndTime" ,"recurrence":"Recurrence","recurrenceRule":"RecurrenceRule","allDay":"AllDay","categorize":null,"recurrenceId" :"RecurrenceId","recurrenceExDate":"RecurrenceExDate","location":"Location","priority":null,"startTimeZone" :"StartTimeZone","endTimeZone":"EndTimeZone"}
    ScheduleModel {"views":["day","week","workweek","month","agenda"], ...} -- Schedule Model Values

    ICS Export Request

  • JS
  • var obj = $("#Schedule1").data("ejSchedule"); // instance of Scheduler widget after initialization
    obj.exportSchedule("http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/ICSExport", null, null); // client-side method to be made use in order to invoke the service action for exporting.

    Export Action invoked in C Sharp

  • C#
  • public void ICSExport()
        {
            IEnumerable data;
            string JSONModel = HttpContext.Current.Request.Form["ScheduleApps"];
            var model = JsonConvert.DeserializeObject<Dictionary<string, object>>(JSONModel);
            var Id = HttpContext.Current.Request.Form["AppointmentId"];
            var DataSource = new ScheduleDataEntities().DefaultSchedules.ToList();
            if (Id != null)
                data = DataSource.Where(app => app.Id.ToString() == Id.ToString()).ToList();
            else
                data = DataSource.ToList();
            ScheduleExport obj = new ScheduleExport(model, data);
        }

    Response

    Status Code: 200 OK

    Content-Type: text/Calendar

    ICS Import Service

    Description

    To import appointment data generated from external calendar into Scheduler.

    URL

    http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/SaveDefault/ - To import appointments from external ICS files into Scheduler.

    Import Request using Uploadbox externally

  • JS
  • $("#UploadDefault").ejUploadbox({
                saveUrl: "http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/SaveDefault",
                extensionsAllow: ".ics",
                height: "31px", autoUpload: true,
                width: "80px",
                buttonText: {
                    browse: "Import",
                },
                showFileDetails: false,
                success: "onComplete",
                dialogAction: {
                    closeOnComplete: true,
                }
        });

    Import Action invoked in C Sharp

  • C#
  • public IEnumerable SaveDefault()
        {
            var files = HttpContext.Current.Request.Files;
            var destinationPath = "";
            try
            {
                for (int i = 0; i < files.Count; i++)
                {
                    var fileName = Path.GetFileName(files[i].FileName);
                    destinationPath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), fileName);
                    files[i].SaveAs(destinationPath);
                }
            }
            catch (Exception ex) { throw ex; }
            ScheduleImport importApps = new ScheduleImport();
            List<ScheduleImport.ScheduleAppointment> app = importApps.renderingImportAppointments(destinationPath);
            try
            {
                if (File.Exists(destinationPath))
                {
                    File.Delete(destinationPath);
                }
            }
            catch (Exception ex) { throw ex; }
            var dataSource = new ScheduleDataEntities().DefaultSchedules.ToList();
            int intMax = dataSource.Max(a => a.Id);
            for (var i = 0; i < app.Count; i++)
            {
                app[i].Id = intMax + 1;
                DefaultSchedule row = new DefaultSchedule();
                row.Subject = app[i].Subject;
                row.AllDay = app[i].AllDay;
                row.Categorize = app[i].AppointmentCategorize;
                row.Description = app[i].Description;
                row.EndTime = Convert.ToDateTime(app[i].EndTime);
                row.Id = app[i].Id;
                row.Location = app[i].Location;
                row.Owner = app[i].Owner;
                row.Recurrence = (!String.IsNullOrEmpty(app[i].RecurrenceRules)) ? Convert.ToByte("1") : Convert.ToByte("0");
                row.RecurrenceRule = app[i].RecurrenceRules;
                row.Reminder = app[i].Reminder;
                //row.Priority = Convert.ToInt32(app[i].Priority);
                row.StartTime = Convert.ToDateTime(app[i].StartTime);
                dataSource.Add(row);
                intMax = app[i].Id;
            }
            return dataSource;
        }

    Response

    Status Code: 200 OK

    Content-Type: application/xml; charset=utf-8

    PDF Export Service

    Description

    To export the entire Scheduler content in a PDF file format.

    URL

    http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/PDFExport/

    Parameters

    ScheduleApps {"id":"Id","subject":"Subject","description":"Description","startTime":"StartTime","endTime":"EndTime" ,"recurrence":"Recurrence","recurrenceRule":"RecurrenceRule","allDay":"AllDay","categorize":null,"recurrenceId" :"RecurrenceId","recurrenceExDate":"RecurrenceExDate","location":"Location","priority":null,"startTimeZone" :"StartTimeZone","endTimeZone":"EndTimeZone"}
    ScheduleProcessedApps [{"Id":504,"Subject":"Case study","StartTime":"2014-05-01T18:30:00.000Z","EndTime":"2014-05-03T18:29:00.000Z","Description":"","AllDay":true,"Recurrence":false,"AppTaskId":26,"ParentId":26,"Guid":"557984d8-55de-6a63-3868-f236ad1d2d61","RecurrenceId":null,"RecurrenceExDate":null}, ... ] -- Processed Appointment data
    ScheduleModel {"views":["day","week","workweek","month","agenda"], ...} -- Schedule Model Values

    PDF Export Request

  • JS
  • var obj = $("#Schedule1").data("ejSchedule"); // instance of Scheduler widget after initialization
        obj.exportSchedule("http://js.syncfusion.com/demos/ejservices/api/JSScheduleExport/PDFExport", null, null); // client-side method to be made use in order to invoke the service action for exporting.

    Export Action invoked in C Sharp

  • C#
  • public void PDFExport()
        {
    		JavaScriptSerializer serializer = new JavaScriptSerializer();
            SchedulePDFExport convert = new SchedulePDFExport();
            ScheduleProperties scheduleObject = convert.ScheduleSerializeModel(HttpContext.Current.Request.Form["ScheduleModel"]);
            IEnumerable scheduleAppointments = (IEnumerable)serializer.Deserialize(HttpContext.Current.Request.Form["ScheduleProcessedApps"], typeof(IEnumerable));
            PdfExport exp = new PdfExport();
            PdfPageSettings pageSettings = new PdfPageSettings(50f);
            pageSettings.Orientation= PdfPageOrientation.Landscape;
            PdfDocument document = exp.Export(scheduleObject, scheduleAppointments, ExportTheme.FlatAzure, HttpContext.Current.Request.Form["locale"], pageSettings);
    		document.Save("Schedule.pdf", HttpContext.Current.Response, HttpReadType.Save);
        }

    Response

    Status Code: 200 OK

    Content-Type: application/pdf