BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
[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: