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

Schedule Appointment mismatch with database

Hi,

I am currently using a Syncfusion Schedule to add events to a database. 

When I create a new appointment the Schedule sends an CRUD request to an MVC Controller on my sever.

The Schedule includes a "dId" field, which is used as an identifier for the appointment

The MVC Controller then creates an "appointment" and adds it to the database, however because the dId field is not necessarily unique (multiple users could be sending requests at any given time) the server chooses a new, unique, ID for the appointment.

On the client-end the scheduler then adds an appointment, however it uses the dId that it initially sent to the server.

If the user then deletes or edits this appointment (without refreshing the page) the server will be unable to find the dId, as the appointment in the database has a completely different ID.

What is the recommended method for resolving this?

I have tried to send the database ID back to the scheduler (as a response to the CRUD request), however I cannot find a way to do anything with this information client-side.

Also the scheduler doesn't wait for this response before creating the client-side appointment, so even if I was able to add a custom response handler it would be too late, as the event would have already been added.

Thanks,
Campbell

5 Replies

VD Vinitha Devi Murugan Syncfusion Team April 1, 2019 12:27 PM UTC

Hi Campbell, 
 
Thanks for your patience. 
 
In Scheduler, Id field is mandatory and should be unique. We request you to follow any one of the below methods to perform CRUD actions correctly. 
 
  1. In the below sample, Id field is used as auto increment.
 
 
 
Controller.cs 
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]; 
                DateTime startTime = Convert.ToDateTime(value.StartTime); 
                DateTime endTime = Convert.ToDateTime(value.EndTime); 
                var currentTimeZone = TimeZone.CurrentTimeZone; 
                Appointment appoint = new Appointment() 
                { 
                    StartTime = startTime, 
                    EndTime = endTime, 
                    Subject = value.Subject, 
                    Description = value.Description, 
                    Recurrence = value.Recurrence, 
                    AllDay = value.AllDay, 
                    RecurrenceRule = value.RecurrenceRule, 
                }; 
                db.Appointments.InsertOnSubmit(appoint); 
                db.SubmitChanges(); 
            } 
 
 
  1. In the below sample, Id field is used as normal field and only unique value is assigned.
Controller.cs 
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.Appointments.ToList().Count > 0 ? db.Appointments.ToList().Max(p => p.Id) : 1; 
                DateTime startTime = Convert.ToDateTime(value.StartTime); 
                DateTime endTime = Convert.ToDateTime(value.EndTime); 
                var currentTimeZone = TimeZone.CurrentTimeZone; 
                Appointment appoint = new Appointment() 
                { 
                    Id = value.Id, 
                    StartTime = startTime, 
                    EndTime = endTime, 
                    Subject = value.Subject, 
                    Description = value.Description, 
                    Recurrence = value.Recurrence, 
                    AllDay = value.AllDay, 
                    RecurrenceRule = value.RecurrenceRule, 
                }; 
                db.Appointments.InsertOnSubmit(appoint); 
                db.SubmitChanges(); 
            } 
 
 
 
Regards, 
M.Vinitha devi. 
 



CW Campbell Wray April 1, 2019 04:06 PM UTC

Hi Vinitha,

Number 1 is exactly how I am doing it now, however the JSON returned by: 

return Json(data, JsonRequestBehavior.AllowGet);

Doesn't actually get handled by the Schedule, in my application it just ignores the response.

Is there some sort of configuration needed to make this happen?

Here is my code:

    @(Html.EJ().Schedule("Schedule1")
                                    .Width("100%")
                                    .Height("525px")
                                    .CurrentDate(DateTime.Today)
                                    .EnableLoadOnDemand(true)
                                    .ShowTimeZoneFields(false)
                                    .CurrentView(CurrentView.Agenda)
                                    .AgendaViewSettings(a => a.DaysInAgenda(365))
                                    .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Calendar/GetCalendar").CrudURL("/Calendar/CrudResult").Adaptor(AdaptorType.UrlAdaptor))
                                            .Id("dId")
                                            .Subject("dName")
                                            .StartTime("startTime")
                                            .EndTime("endTime")
                                            .Description("descr")
                                            .AllDay("isAllDay")
                                            .Recurrence("recurs")
                                            .RecurrenceRule("recurrenceRule")
                                            .ApplyTimeOffset(false)
                                            .Categorize("categorize")
                                        )
                                    

    )

Thanks,
Campbell





KK Karthigeyan Krishnamurthi Syncfusion Team April 2, 2019 05:14 AM UTC

Hi Campbell,  
 
Thanks for your update. 
 
In our previous auto id increment sample, appointments are shown both at initial load and after the CRUD action. We suspect that field mapping mismatch could be the cause for the issue, kindly share the below details to proceed further. 
 
  1. DB fields information.
  2. The data collection information.
  3. Controller code example.
 
Note: There is no specific configuration, to display the appointments in Scheduler for auto id increment sample
 
Regards, 
Karthi 



CW Campbell Wray April 5, 2019 05:29 PM UTC

Hi Vinitha,

Thanks for the last message, just letting you know that I did eventually manage to solve this. I am not sure exactly what the cause was but I ended up stripping out all of the extra client-side events and re-added them until things started to break.

Thanks,
Campbell


KK Karthigeyan Krishnamurthi Syncfusion Team April 8, 2019 04:36 AM UTC

Hi Campbell, 
 
We are happy to hear that issue has been resolved at your end. 
 
Regards, 
Karthi 


Loader.
Live Chat Icon For mobile
Up arrow icon