We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

POST Appointment data to my service.svc

Hi i get the simple ejSchedule from Local Samples .

  var dManager = ej.DataManager({

                url: "http://mvc.syncfusion.com/OdataServices/Northwnd.svc/"

            });
              var queryString = ej.Query().from("Events").take(10);

            $("#Schedule1").ejSchedule({

                width: "100%",

                height: "525px",

                currentDate: new Date(2014, 4, 5),

                appointmentSettings: {

                    // the dManager collections

                    dataSource: dManager,

                    query: queryString,

                    id: "Id",

                    subject: "Subject",

                    startTime: "StartTime",

                    endTime: "EndTime",

                    allDay: "AllDay",

                    recurrence: "Recurrence",

                    recurrenceRule: "RecurrenceRule"

                },
               // appointmentSaved : "onsaved"

            });


And when i add or move the appointment i get : XMLHttpRequest cannot load http://mvc.syncfusion.com/OdataServices/Northwnd.svc(105). Method PUT is not allowed by Access-Control-Allow-Methods. 

I knew what's its mean. I just want to call my service method when save|changes are fired . I will changes  http://mvc.syncfusion.com/OdataServices/Northwnd.svc to my localhost:1234/myservice.svc that will return data (with allow access ) =  its OK . 

BUT where can i CHANGE the URL and SERVICE METHOD to PUT/POST data from ejschedule control to service.svc. 


as example when i will call the data from ajax it will call 

http://localhost/myservice.svc/getdata

and on changes i want to post appointment(S) to http://localhost/mysrevice.svc/postsdata






1 Reply

VS Velmurugan S Syncfusion Team November 21, 2014 01:47 PM UTC

Hi Sergiy,

Thanks for using Syncfusion products.

We have prepared the sample to show your above mentioned requirements, which can be downloaded from the following location.

http://www.syncfusion.com/downloads/support/directtrac/general/ScheduleCRUD1171161275.zip

In the above sample we have bind the data to schedule control through the “url” as mentioned in the below code snippet.

<code>

JavaScript

 

<script type="text/javascript">

 

    $(function () {

 

        var query = ej.Query().from("DefaultSchedules");

 

        var dManager = ej.DataManager({

            url: "/Home/GetData",

            offline: false

        });

        dManager.adaptor = new ej.UrlAdaptor();

           

        $("#Schedule1").ejSchedule({

            width: "100%",

            height: "500px",

            ------------------

            ------------------

           appointmentSettings: {

                dataSource: dManager,query:query,

                id: "Id",

                subject: "Subject",

                startTime: "StartTime",

               endTime: "EndTime",

                allDay: "AllDay",

                recurrence: "Recurrence",

                recurrenceRule: "RecurrenceRule"

            }

        });

 

    });

 

       

</script>

 

Controller

 

       -------------------

       -------------------

       public JsonResult GetData()

        {

            IEnumerable data = new ScheduleDataDataContext().DefaultSchedules.Take(100); // nw.Appointment.Take(100);

            return Json(data, JsonRequestBehavior.AllowGet);

        }

 

</code>

And then declared and defined the “create” event “onCreate” to add/change the appointment into schedule control as mentioned in the below code snippet. When we add the appointment this event will trigger and appointment is adding to the database and displayed in the schedule control, similarly while updating the “appointments” this event will trigger and perform the edit operation and changes reflect in the appointments

<code>

JavaScript:

<script type="text/javascript">

 

    $(function () {

 

        -----------------------

        -----------------------

           

        $("#Schedule1").ejSchedule({

            width: "100%",

            height: "500px",

            currentDate: new Date("2014,6,5"),

            currentView: "month",

            create:"onCreate",

            appointmentSettings: {

                dataSource: dManager,query:query,

                id: "Id",

                subject: "Subject",

                startTime: "StartTime",

               endTime: "EndTime",

                allDay: "AllDay",

                recurrence: "Recurrence",

                recurrenceRule: "RecurrenceRule"

            }

        });

 

    });

 

        function onCreate(args) {

            this._dataManager.dataSource.crudUrl = "/Home/Batch";

        }

</script>

 

Controller

        

         -----------------------

         -----------------------

        public JsonResult Batch(EditParams param)

        {

            if (param.action == "insert" || (param.action == "batch" && param.added != null))          // this block of code will execute while inserting the appointments

            {

                var value = param.action == "insert" ? param.value : param.added[0];

                int intMax = db.DefaultSchedules.ToList().Count > 0 ? db.DefaultSchedules.ToList().Max(p => p.Id) : 1;

                DateTime startTime = Convert.ToDateTime(value.StartTime);

                DateTime endTime = Convert.ToDateTime(value.EndTime);

                var currentTimeZone = TimeZone.CurrentTimeZone;

                DefaultSchedule appoint = new DefaultSchedule()

                {

                    --------------------------

                    --------------------------

                    --------------------------

               };

                db.DefaultSchedules.InsertOnSubmit(appoint);

                db.SubmitChanges();

            }

            else if (param.action == "remove")                                        // this block of code will execute while removing the appointment

            {

                DefaultSchedule app = db.DefaultSchedules.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault();

 

                if (app != null) db.DefaultSchedules.DeleteOnSubmit(app);

                db.SubmitChanges();

            }

            else if ((param.action == "batch" && param.changed != null) || param.action == "update")   // this block of code will execute while updating the appointment

            {

                var value = param.action == "update" ? param.value : param.changed[0];

                var filterData = db.DefaultSchedules.Where(c => c.Id == Convert.ToInt32(value.Id));

 

                if (filterData.Count() > 0)

                {

                    --------------------

                    --------------------

               }

                db.SubmitChanges();

            }

            IEnumerable data = new ScheduleDataDataContext().DefaultSchedules.Take(500); // nw.Appointment.Take(500);

            return Json(data, JsonRequestBehavior.AllowGet);

        }

</code>

Please let us know whether it helps and any further assistance on this.

Regards,

Velmurugan


Loader.
Live Chat Icon For mobile
Up arrow icon