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

Schedule Control Recurring Events and linking them to User List

Hi Team,

Hope I can explain this properly.

I'm having an issue with the Syncfusion Schedule control's recurrence pattern and its storage in our database.

We are creating an events calendar, where events will be created in advance by the system admin and users can book them individually. We have a separate table which stores a list of users and their mapping with an event. Something like:

UserID

EventID
145
254
321
189


All works well when there are individual (single) events since each event has a unique record in the backend. But when we create a recurring event, the control creates only a single record in the database for it with a RecurenceRule. Now when the user books any event from this recurring event, we get the same EventID. Hence we cannot identify event individually falling under a set of recurring events.

Is there a way we can get the Unique ID of each event which fall under a recurrence, so we can take that ID and link it to a list of users to manage their bookings.

or is there any other approach to manage this situation?


6 Replies

AD Amit D March 22, 2023 03:25 AM UTC

Bump ... anyone?



VR Vijay Ravi Syncfusion Team March 22, 2023 11:57 AM UTC

Hi Amit,


It’s not possible to setup a unique Id for each occurrence of the recurrence appointment, So we suggest you to use the RecurrenceHelper class in your project and generate the occurrences falling dates and create an each recurrence occurrences as a normal appointment with unique Id and add it to the Database as shown in the below code snippet. Refer to the below KB to know more about generating occurrences dates using RecurrencceHelper.


KB: https://www.syncfusion.com/kb/13184/how-to-parse-the-recurrence-rule-rrule-in-server-side


[HomeController.cs]

public class HomeController : Controller

    {

        private readonly ILogger<HomeController> _logger;

 

        List<AppointmentData> appData = new List<AppointmentData> {new AppointmentData

            {

                Id = 1,

                Subject = "Paris",

                StartTime = new DateTime(2018, 2, 15, 10, 0, 0),

                EndTime = new DateTime(2018, 2, 15, 12, 30, 0),

                RecurrenceRule = "FREQ=DAILY;INTERVAL=1;COUNT=5"

            }

        };

       

        public HomeController(ILogger<HomeController> logger)

        {

            _logger = logger;

        }

 

        public ActionResult Index()

        {

            List<AppointmentData> appointments = new List<AppointmentData>();

 

            // Generate new appointments with recurrence rule

            if (!string.IsNullOrEmpty(appData[0].RecurrenceRule))

            {

                var dateCollection = RecurrenceHelper.GetRecurrenceDateTimeCollection(appData[0].RecurrenceRule, appData[0].StartTime);

                if (dateCollection != null)

                {

                    foreach (var date in dateCollection)

                    {

                        var newAppointment = new AppointmentData

                        {

                            Id = appointments.Count + 1,

                            Subject = appData[0].Subject,

                            StartTime = date,

                            EndTime = date.Add(appData[0].EndTime - appData[0].StartTime),

                        };

                        appointments.Add(newAppointment);

                    }

                }

            }

 

            ViewBag.Appointments = appointments;

            return View();

        }

 


Regards,

Vijay Ravi


Attachment: Recurrence_Parser_f8696a9.zip


AD Amit D March 22, 2023 12:07 PM UTC

Thanks for your response Vijay. Much Appreciated.

We thought about doing this as per your suggestions, however In this case, the user is still expecting that they have created a series of events, however they are individual appointments. How to deal with edits to the series then? for instance the user wants to change the time of the event for all events in the series? How will the code know which all individual appointments to change?


Regards,

Amit




VR Vijay Ravi Syncfusion Team March 23, 2023 12:45 PM UTC

Hi Amit,


You can achieve your requirement by adding a reference id(id of the parent appointment) for each of the individual appointments generated as highlighted in the below code snippet and while editing an entire series filter all appointments with the same reference id and apply the changes in all individual appointment records. If want to edit an individual record save the changes alone in that record.


[HomeController.cs] 

public ActionResult Index()

        {

            List<AppointmentData> appointments = new List<AppointmentData>();

 

            // Generate new appointments with recurrence rule

            if (!string.IsNullOrEmpty(appData[0].RecurrenceRule))

            {

                var dateCollection = RecurrenceHelper.GetRecurrenceDateTimeCollection(appData[0].RecurrenceRule, appData[0].StartTime);

                if (dateCollection != null)

                {

                    int referenceId = appData[0].Id; // get reference ID from first appointment

                    int Id = appData[0].Id;

                    foreach (var date in dateCollection)

                    {

                        var newAppointment = new AppointmentData

                        {

                            Id = Id,

                            ReferenceId = referenceId, // set same reference ID to all appointments

                            Subject = appData[0].Subject,

                            StartTime = date,

                            EndTime = date.Add(appData[0].EndTime - appData[0].StartTime),

                        };

                        appointments.Add(newAppointment);

                        Id++;

                    }

                }

            }

 

            ViewBag.Appointments = appointments;

            return View();

        }


Regards,

Vijay Ravi


Attachment: RecurrenceParser_2_fe84d19d.zip


AD Amit D March 23, 2023 12:50 PM UTC

Thanks Vijay,


Really appreciate your response. Will pass this to our developers and get back to you in case we need additional support. 


Regards,

Amit



RV Ravikumar Venkatesan Syncfusion Team March 27, 2023 05:42 AM UTC

Amit,


You are welcome. Let us know if you need any further assistance.


Loader.
Up arrow icon