I want to save past occurences in a separate db

Hi,

I wanted to know if it was possible to save past occurences of recurring event in a separate db.

Let me explain further:
If I create a weekly recurring event starting 1/10/2021, I want to make it so when each event time has passed, the event and associated invoice fields are saved in a separate invoice db table. This means for 1/10/2021 until todays date 8 occurrences will be saved in a separate db and then in the future any event will be saved to that separate db on the date of the event date.



12 Replies

PN Praveenkumar Narasimhanaidu Syncfusion Team November 22, 2021 02:52 PM UTC

Hi Abdurrhmanzaki, 

Greetings from Syncfusion support..! 

We have validated your requirement and suggest you use RecurrenceHelper utility to generate dates by passing recurrence rule. We have shared a recurrence helper file to cover all recurrence cases which can be downloaded from the following link.  


Also, we have prepared below sample to show how to generate occurrence from recurrence rule using recurrence helper file using below code for your reference.  


public List<ScheduleEventLoadData([FromBody]Params param)  
{  
    var data = _context.ScheduleEvents.ToList();  
  
    DateTime startdate = DateTime.Today;  
    DateTime enddate = startdate.AddDays(1);  
    List<ScheduleEventappCollection = new List<ScheduleEvent>();  
    for (var i =0idata.Counti++)  
    {  
        var app = data[i];  
        if (data[i].RecurrenceRule !=  null) {    
            TimeSpan diff = app.EndTime.Subtract(app.StartTime);  
            var recurrenceRule = data[i].RecurrenceRule;  
            TimeSpan startDiff;  
            var dateCollection = RecurrenceHelper.GetRecurrenceDateTimeCollection(recurrenceRuleapp.StartTime);  
            foreach (var date in dateCollection)  
            {  
                startDiff = app.StartTime.Subtract(date);  
                break;  
            }  
                foreach (var date in dateCollection)  
            {  
                var start = date.Add(startDiff);  
                var end = start.Add(diff);  
                appCollection.Add(new ScheduleEvent {  Subject=app.SubjectStartTime = startEndTime = endCategoryId=app.CategoryIdDescription = app.DescriptionIsAllDay =app.IsAllDayRecurrenceRule = app.RecurrenceRuleLocation = app.Location,ProjectId = app.ProjectIdStartTimezone = app.StartTimezoneEndTimezone = app.EndTimezone,Id = app.Id });  
            }  
        }  
        else  
        {  
            appCollection.Add(app);  
        }  
    }  
    // Here we fileter the today appointment from the db  
    var todayAppointmentCollection = appCollection.Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate)).ToList();    
    Console.WriteLine(todayAppointmentCollection); // Now the today appointment available in 'todayAppointemntCollection variable.'  
    return data;  
}  


You can have a condition to filter past dates and store them in separate db. Kindly try the above solution and let us know if you need any further assistance. 

Regards, 
Praveenkumar 



AB Abdurrhmanzaki December 21, 2021 05:59 PM UTC

Hi,
I have tried the above sample and one thing that I could not see is the action of saving of parsed occurances or action that helps the binding of parsed occurances to the db. 

In another way, is there a way to send event data/fields to separate db table at event time or when event time has passed.


Thanks





BS Balasubramanian Sattanathan Syncfusion Team December 22, 2021 02:45 PM UTC

Hi Abdurrhmanzaki,

Thanks for the update.

We have validated your required scenario at our end and suspect that your need is to see the action of parsed occurrences saving to the Db and also need to send event details to the separate DB. We have prepared a sample with service for your reference, in this sample, we have maintained the event details in the separate DB like the below screenshot. And also you can see the event processing the LoadData and UpdateData method of the HomeController.cs file. The sample can be viewed from the below attachment.



Kindly refer to the above solution and let us know if you need further assistance.

Regards,
Balasubramanian S


Attachment: Core_sample_with_service_dba97570.zip


AB Abdurrhmanzaki December 22, 2021 03:55 PM UTC

Hi,

Thanks for previous response. 

However, how is the action completed? automatically at the time of the occurrence?

Would you be able to let us know if the scheduler has a feature that generates action at occurrence time.





BS Balasubramanian Sattanathan Syncfusion Team December 23, 2021 02:20 PM UTC

Hi Abdurrhmanzaki,


Thanks for the update.


Can you please check by binding the actionBegin an actionComplete event at your sample and check whether you have enough detail in their arguments?


Code snippet:

@using Syncfusion.EJ2.Schedule

 

<ejs-schedule id="schedule" height="550" actionBegin="onActionBegin" actionComplete="onActionComplete" selectedDate="new DateTime(2018, 1, 28) ">

    <e-schedule-eventsettings dataSource="@ViewBag.datasource">

    </e-schedule-eventsettings>

</ejs-schedule>

 

<script type="text/javascript">

    function onActionBegin(args) {

        console.log(args);

    }

    function onActionComplete(args) {

        console.log(args);

    }

</script>

 


Kindly try the above solution and let us know if you need further assistance.


Regards,

Balasubramanian S



AB Abdurrhmanzaki December 23, 2021 06:23 PM UTC

Thanks  Balasubramanian,

Thanks your previous answer. I am aware of OnAction/actionComplete.

However, I was looking for something similar to what signalr does maybe. or maybe reminders that are auto-triggered and show up at certain time before the appointment.

In my case I wanted to know if you have a trigger that completes my request of saving occurance data to the db in the background. 

Example: Next event is 2021-12-24 11:30. and exactly on the appointment time, occurance data is saved to the db in the background.

Thanks




AB Abdurrhmanzaki December 25, 2021 05:11 PM UTC

Just as a further info see below calendar... I want the occurances in the recurrence to automatically saved to the db...
Example below: 21-Dec @ 1:PM the occurace is triggered and is saved to the db in the background
                            22-Dec @1 PM the second occurance is triggered and saved to a db in the background and so on for all remaining occurances. 

All occurances are saved automatically at the event time. This is similar to reminder but action is different.




BS Balasubramanian Sattanathan Syncfusion Team December 27, 2021 05:17 PM UTC

Hi Abdurrahmanzaki,

Thanks for the details.

Currently, we are checking the possibility to prepare the sample at our end and will update the further details on December 28, 2021. We would appreciate your valuable patience.

Regards,
Balasubramanian S



BS Balasubramanian Sattanathan Syncfusion Team December 28, 2021 07:42 AM UTC

Hi Abdurrahmanzaki,

Thanks for your patience.

We have prepared a sample to save the appointment occurrence in the separate DB when the reminder popped up using the below code snippets.

Index.cshtml:

function refreshEventReminder() {

    var scheduleObj = document.querySelector('.e-schedule').ej2_instances[0];

    var toastObjReminder = document.querySelector('.e-toast').ej2_instances[0];

    var eventCollection = scheduleObj.getCurrentViewEvents();

    eventCollection.forEach(function (event, i) {

        var dateFormat = function (date) {

            return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());

        }

        var startTime = dateFormat(event[scheduleObj.eventFields.startTime]);

        var currentTime = dateFormat(new Date(new Date().toUTCString().slice(0, -3)));

        var difference = currentTime.getTime() - startTime.getTime() ;

        if (difference >= 0 && difference <= 10000) {

            console.log(event);

            // The reminder will be popuped based on the appointment's start time.

            $.ajax({

                url: '/Home/UpdateReminderData',

                data: JSON.stringify(event),

                type: 'POST',

                async: false,

                traditional: true,

                contentType: 'application/json',

                success: function (data) {

                    alert("Success")

                },

                failure: function (data) {

                    alert("Failure occurred")

                },

                error: function (data) {

                    alert("Error Occurred")

                }

            });

            toastObjReminder.show({

                template: (ej.base.compile(document.getElementById("reminder-template").innerHTML.trim())(event)[0]).outerHTML

            });

        }

    });

}


Ho
meController.cs:

[HttpPost]

public List<ScheduleEvent> UpdateReminderData([FromBody] AppointmentData data)

{

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

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

    ScheduleEvent appointment = new ScheduleEvent()

    {

        StartTime = startTime.ToLocalTime(),

        EndTime = endTime.ToLocalTime(),

        Subject = data.Subject,

        StartTimezone = data.StartTimezone,

        EndTimezone = data.EndTimezone,

        RecurrenceRule = data.RecurrenceRule

    };

    // The occurrences of the 'Daily recurrence event' will be stored to the DB when the reminder is popup.

    _context.ScheduleEvents.Add(appointment);

    _context.SaveChanges();

    return _context.ScheduleEvents.ToList();

}


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Schedule_with_ajax1743896789.zip

Kindly try the above solution and let us know if this is helpful.


Regards,
Balasubramanian S



AB Abdurrhmanzaki December 29, 2021 10:38 AM UTC

Hi,
Thanks for the latest response. It is by far the closest i could get and it works with calendar page open. 

I wanted to check with you oe thing. As you can see from the attached image, the notification works and it will generate the db. However, it will ONLY be done if you are on the calendar page or when you return to the page. It will not work otherwise. Is that the best option or there could be an option to make this work without having the calendar page open.




AB Abdurrhmanzaki December 29, 2021 11:46 AM UTC

Hi,

Furthermore, further tests showed that if calendar page is not open, this action will not work and I will not get a reminder and hence nothing will be triggrered to update the db. I would greatly appreciate if we could work around to allow this fuction to work even when the calendar/scheduler is not running.


Thanks




BS Balasubramanian Sattanathan Syncfusion Team December 30, 2021 08:53 AM UTC

Hi Abdurrhmanzaki,

We provided a solution that depends on the Scheduler and if you want to get reminders over even if you didn't on the scheduler page, we suggest you to change the same functionality to a global page based on the application. 

Regards,
Balasubramanian S

Loader.
Up arrow icon