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

Get the events for today scheduler control

Hi,

I want to create a service to trigger notifications that are scheduled from scheduler events and stored in the database. Is there any way to get the events of the day on server side? My question is more about recursive events.

Thank you

10 Replies

NR Nevitha Ravi Syncfusion Team April 24, 2019 06:31 AM UTC

Hi Marco, 

Greetings from Syncfusion Support. 

Yes we can get the events of a particular day on server side and we have prepared sample for your reference which can be downloaded from the following link. To get the recursive events of  a date, we need to parse the recurrence rule for that please refer this kb. 

        [HttpPost] 
        public List<ScheduleEvent> LoadData([FromBody]Params param) 
        { 
            var data = _context.ScheduleEvents.ToList(); 
 
            DateTime startdate = DateTime.Today; 
            DateTime enddate = startdate.AddDays(1); 
            List<ScheduleEvent> appCollection = new List<ScheduleEvent>(); 
            for (var i = 0; i < data.Count; i++) 
            { 
                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(recurrenceRule, DateTime.Now); 
                    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.Subject, StartTime = start, EndTime = end, CategoryId = app.CategoryId, Description = app.Description, IsAllDay = app.IsAllDay, RecurrenceRule = app.RecurrenceRule, Location = app.Location, ProjectId = app.ProjectId, StartTimezone = app.StartTimezone, EndTimezone = app.EndTimezone, Id = app.Id }); 
                    } 
                } 
                else 
                { 
                    appCollection.Add(app); 
                } 
            } 
            // Here we filter the today appointment from the db 
            var todayAppointmentCollection = appCollection.Where(app => (app.StartTime >= startdate && app.StartTime <= enddate)).ToList(); 
            Console.WriteLine(todayAppointmentCollection); // Now the today appointment available in todayAppointemntCollection variable. 
            return data; 
        } 
 
 
        public class Params 
        { 
            public string StartDate { get; set; } 
            public string EndDate { get; set; } 
        } 

Please try the sample and revert us back if you need any further assistance. 

Regards, 
Nevitha 



MA Makela May 25, 2022 09:32 PM UTC

I have the code tested multiple times but it doesn't work properly. I always come today's and tomorrow's appointments. I actually only wanted to have the appointments from today



RV Ravikumar Venkatesan Syncfusion Team May 26, 2022 01:40 PM UTC

Hi Makela,


We have validated your requirement “I only wanted to have the appointments from today” at our end. We suggest you use the highlighted code to get the appointments from today.


[HomeController.cs] 

        [HttpPost]

        public List<ScheduleEvent> LoadData([FromBody]Params param)

        {

            var data = _context.ScheduleEvents.ToList();

 

            DateTime startdate = DateTime.Today;

            List<ScheduleEvent> appCollection = new List<ScheduleEvent>();

            for (var i =0; i< data.Count; i++)

            {

                    appCollection.Add(app);

            }

            // Here we filtering the appointments from today

            var fromTodayAppointmentCollection = appCollection.Where(app => (app.StartTime >= startdate)).ToList(); 

            Console.WriteLine(fromTodayAppointmentCollection); // Now the appointment from today available in 'fromTodayAppointmentCollection variable.'

            return fromTodayAppointmentCollection;

        }


Kindly try the shared sample and let us know if you need any further assistance.

  

Regards,

Ravikumar Venkatesan


Attachment: ej2coreschedule_b1562c74.zip


MA Makela replied to Ravikumar Venkatesan November 3, 2022 06:23 PM UTC

ich habe bis jetzt der obige Code ausprobiert aber es ignoriert immer wieder der heutige Termin. Die heutige  Termine werden einfach nicht ausgegeben. Ich habe eine Blazor Application



RM Ruksar Moosa Sait Syncfusion Team replied to Makela November 7, 2022 01:02 PM UTC

I've tried the above code so far but it keeps ignoring today's appointment. Today's appointments are simply not issued. I have a Blazor application


We have checked your query in our sample and it works as expected. Try the attached sample and if the issue persists, share the below details to check further.

  • The video demo illustrating the issue.
  • Replicate the issue in the attached sample or
  • Sample demonstrating the issue


Output:

A screenshot of a computer

Description automatically generated


Attachment: ej2corescheduleWorking_442095fe.zip


MA Makela replied to Ruksar Moosa Sait April 27, 2023 03:08 PM UTC


I keep trying. It doesn't always work properly for me



MA Makela April 27, 2023 03:09 PM UTC


I keep trying. It doesn't always work properly for me


Attachment: Aufzeichnung_20230427_165837_efe4be14.zip


RV Ravikumar Venkatesan Syncfusion Team May 3, 2023 07:54 PM UTC

Hi Makela,


Based on your shared video demo we suspect that the appointments after today are also rendered in the Schedule, and you only want appointments for today. To achieve your requirement, we suggest you add the below-highlighted changes to your application. You can see in the below snip there are 15 appointments and only today’s appointment alone was filtered and returned.



[HomeController.cs]

        [HttpPost]

        public List<ScheduleEvent> LoadData([FromBody] Params param)

        {

            var data = _context.ScheduleEvents.ToList();

 

            DateTime startdate = DateTime.Today;

            DateTime enddate = startdate.AddDays(1);

            List<ScheduleEvent> appCollection = new List<ScheduleEvent>();

            for (var i = 0; i < data.Count; i++)

            {

                var app = data[i];

                if (data[i].RecurrenceRule != null && data[i].RecurrenceID == null)

                {

                    TimeSpan diff = app.EndTime.Subtract(app.StartTime);

                    var recurrenceRule = data[i].RecurrenceRule;

                    var recurrenceException = data[i].RecurrenceException;

                    TimeSpan startDiff;

                    var dateCollection = RecurrenceHelper.GetRecurrenceDateTimeCollection(recurrenceRule, DateTime.Now, recurrenceException);

                    foreach (var date in dateCollection)

                    {

                        DateTime dateTime = new DateTime(date.Year, date.Month, date.Day, app.StartTime.Hour, app.StartTime.Minute, 0, 0);

                        startDiff = dateTime.Subtract(date);

                        break;

                    }

                    foreach (var date in dateCollection)

                    {

                        var start = date.Add(startDiff);

                        var end = start.Add(diff);

                        appCollection.Add(

                            new ScheduleEvent

                            {

                                Subject = app.Subject,

                                StartTime = start,

                                EndTime = end,

                                CategoryId = app.CategoryId,

                                Description = app.Description,

                                IsAllDay = app.IsAllDay,

                                RecurrenceRule = app.RecurrenceRule,

                                RecurrenceID = app.RecurrenceID,

                                RecurrenceException = app.RecurrenceException,

                                Location = app.Location,

                                ProjectId = app.ProjectId,

                                StartTimezone = app.StartTimezone,

                                EndTimezone = app.EndTimezone,

                                Id = app.Id

                            }

                        );

                    }

                }

                else

                {

                    appCollection.Add(app);

                }

            }

            // Here we filtering the appointments from today

            var fromTodayAppointmentCollection = appCollection.Where(app => (app.StartTime >= startdate && app.StartTime < enddate)).ToList();

            return fromTodayAppointmentCollection;

        }


If you are still facing the same problem, share the below details to proceed further.

  • Share the issue reproducing code snippets with an example appointment data source.
  • Reproduce the issue in our shared sample.
  • Simple issue reproducing sample.


Regards,

Ravikumar Venkatesan


Attachment: ej2_core_schedule_load_today_appointments_alone_99ff2547.zip


MA Makela May 4, 2023 08:55 PM UTC

Damen und Herren,

Vielen Dank für Ihr schnelles Feedback. Die jetzige Lösung scheint zu funktionieren, werde ich nochmal testen. Aber ist vorübergehend funktionsfähig. Vielen Dank



VD Vinitha Devi Murugan Syncfusion Team May 5, 2023 07:59 AM UTC

Hi Makela,


Thanks for your update. We are happy that our solution resolved your reported issue. Please get back to us if you need any further assistance.


Regards,

Vinitha


Loader.
Live Chat Icon For mobile
Up arrow icon