[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; }
} |
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
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
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
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.
Output:
I keep trying. It doesn't always work properly for me
I keep trying. It doesn't always work properly for me
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.
Regards,
Ravikumar Venkatesan
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
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