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

5 Replies

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

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 04:32 PM

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 08:40 AM

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 01:23 PM

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 08:02 AM

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

Loader.
Live Chat Icon For mobile
Up arrow icon