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

Ajax Delete for recurring appointments

Hi,

I'm using the schedule event to capture the appointment id and execute an ajax call to pass the id and delete it from the db. Then the schedule will be refreshed to retrieve the updated dataSource. This works fine in case of normal appointments. In case of recurring appointments, it works fine for 'deleting the entire series' option but for 'delete individual occurrence' it deletes the entire series since there is only one record mapped with the appointment id.

Please guide me on this scenario -> how do i delete an individual occurrence without affecting the appointment series?

Thanks,
Ajay 

7 Replies

KK Karthigeyan Krishnamurthi Syncfusion Team June 14, 2016 09:57 AM UTC

Hi Ajay,   
   
Thank you for contacting Syncfusion support.   
   
We have prepared the sample for your requirement “Need to update the database through ajax after deleting single recurrence appointment” which can be download from the following location:   
 
When the recurrence appointment is created in the Scheduler, only the parent appointment record will be stored in the database (not all of its instances). If the single occurrence of a recurrence appointment is deleted, recurrence rule of the parent recurrence appointment should be updated in database instead of deleting the appointment. In the above sample, when the appointment is deleted BeforeAppointmentRemove event will be triggered. In that event function, controller function is called via ajax post with two parameters (one with appointment Id and other with appointment start date). In controller function, recurrence rule for the parent recurrence appointment and database is updated. Kindly refer to the following code example used in the above sample. 
<Code> 
function OnBeforeAppointmentRemove(args) {// this function will be called when the appointment is deleted  
        var appDate = ej.format(args.appointment.StartTime, this._pattern.d); // here we are getting app date 
        var appId = args.appointment.Id; // here we are getting app id 
        $.ajax({// here we are using ajax post when the appointment is clicked 
            url: "/Home/DeleteApp", type: 'POST', data: { id: appId, date: appDate }, success: function (result) { 
                alert("Database is updated"); 
            }, 
        }); 
    } 
Controller: 
public void DeleteApp(int id, string date) 
        { 
            ScheduleData appoint = db.ScheduleDatas.Single(A => A.Id == Convert.ToInt32(id)); // here we are filtering the parent recurrence app 
            appoint.RecurrenceRule = appoint.RecurrenceRule + ";EXDATE=" + date; // here we are updating the recurrence rule 
            db.SubmitChanges(); // updating the data base 
        } 
</Code> 
 
Kindly check with the above sample and let us know, if you need any further assistance on this.   
   
Regards,   
Karthigeyan   
 



AJ Ajay June 14, 2016 06:32 PM UTC

Hi,

Thank you for the solution. I've few more qns.
  1. When i delete an additional appointment part of the recurrence series after deleting a individual appointment should i include the date as comma separated such as EXDATE= + date1 + "," + date2 ?
  2. How do i differentiate between individual recurrence click vs series recurrence click?
Thanks,
Ajay


KK Karthigeyan Krishnamurthi Syncfusion Team June 15, 2016 11:25 AM UTC

Hi Ajay, 
 
Thanks for your update.  
  
Kindly find the following responses for your queries.   
 
We have prepared the sample for your requirements which can be download from the following    location:   
 
Query1: When I delete an additional appointment part of the recurrence series after deleting an individual appointment should I include the date as comma separated such as EXDATE= + date1 + "," + date2?   
 
Whenever the single occurrence of the recurrence appointment is deleted, particular appointment start date is passed to controller function using ajax post. Since dynamic values is stored in date variable it is enough to use as EXDATE= + date.    
 
Query2: How do I differentiate between individual recurrence click vs series recurrence click?   
 
In BeforeAppointmentRemove we can’t differentiate the single occurrence or series appointment click. While deleting the entire series of an appointment there is no need to update the recurrence rule as we are going to remove the appointment from database. Therefore, we request you to follow the above suggestion while deleting the single occurrence of an appointment and you can use your method (deleting the appointment from database with the help of Id) as mentioned in the previous update for deleting the entire series of an appointment. Kindly refer to the following code example used in the above sample.   
<Code>   
public void DeleteApp(int id, string date) 
        { 
            ScheduleData appoint = db.ScheduleDatas.Single(A => A.Id == Convert.ToInt32(id)); // here we are filtering the parent recurrence app 
            if (!appoint.RecurrenceRule.Contains("EXDATE")) 
                appoint.RecurrenceRule = appoint.RecurrenceRule + ";EXDATE=" + date; // here we are updating the recurrence rule 
            else 
            { // this loop will excute when we delete the another instance of the recurrence appointment 
                var recurRule = appoint.RecurrenceRule.Split(';'); // we are splitting the rule here  
                string splitRule = ""; 
                for (var i = 0; i < recurRule.Count(); i++) 
                { 
                    if (splitRule != "") 
                        splitRule += ";"; 
                    if (recurRule[i].Contains("EXDATE")) 
                    { // here we are updating the EXDATE 
                        var recurExdate = recurRule[3].Split('='); 
                        var recurAdd = recurExdate[1] + "," + date; 
                        recurRule[3] = recurExdate[0] + "=" + recurAdd; 
                    } 
                    splitRule += recurRule[i]; // here we are forming the recurrence rule with the updated EXDATE 
                } 
                appoint.RecurrenceRule = splitRule; 
            } 
            db.SubmitChanges(); // updating the data base 
        } 
</Code>   
   
Regards,   
Karthigeyan   
 
 



AJ Ajay June 15, 2016 12:24 PM UTC

Hi Karthigeyan,

Thank you for your support. 

My understanding is that,

1. To delete an entire series, we need to remove the record from the database using id
2, To delete an individual appointment, we need to use 'EXDATE' in the recurrence rule and append the dates to it for each individual recurrence deletion.

Now, i'm confused on the query to identify if i should follow the step 1 or step 2. I couldn't differentiate if the user is trying to delete an entire series or if he is deleting the individual appointment.

The args variable in the event (javascript) contains only the data items related to the appointment but not the type of deletion the user has performed.

Thanks,
Ajay.


KK Karthigeyan Krishnamurthi Syncfusion Team June 16, 2016 11:58 AM UTC

   
Thanks for your update.   
   
In BeforeAppointmentRemove event we can’t find whether user is deleting the single occurrence or whole series of an appointment. We recommend you to perform CRUD operation for updating the database. We have prepared the sample for performing CRUD operation in Scheduler which can be download from the following location:   
 
In the above sample when the single occurrence of the recurrence appointment is deleted, update code block will be executed in the controller page to update the recurrence rule. If an entire series of the recurrence appointment is deleted, remove code block will be executed in the controller page to remove the appointment from database. Kindly refer to the following code example used in the above sample.   
<Code> 
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.ScheduleDatas.Where(c => c.Id == Convert.ToInt32(value.Id)); 
                --------- 
                --------- 
                db.SubmitChanges(); 
            }  
if (param.action == "remove" || param.deleted != null)  // this block of code will execute while removing the appointment 
            { 
                if (param.action == "remove") 
                { 
                    int key = Convert.ToInt32(param.key); 
                    ScheduleData app = db.ScheduleDatas.Where(c => c.Id == key).FirstOrDefault(); 
                    if (app != null) db.ScheduleDatas.DeleteOnSubmit(app); 
                } 
                ---------- 
                ---------- 
                db.SubmitChanges(); 
            } 
</Code> 
 
Regards, 
Karthigeyan 



AJ Ajay June 18, 2016 08:41 PM UTC

Thanks for the sample solution. It works perfectly :)


SE Sellakumar Syncfusion Team June 20, 2016 08:30 AM UTC

Hi Ajay, 
 
Thanks for your update. 
 
We are glad to hear that our solution works on your application. Please let us know, if you need any further assistance. 

Regards, 
Sellakumar K

Loader.
Live Chat Icon For mobile
Up arrow icon