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

1 Reply

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 


Loader.
Live Chat Icon For mobile
Up arrow icon