dotnet-presentations/aspnetcore-app-workshop

Home and My Agenda pages show day buttons for days that don't include any sessions

DamianEdwards opened this issue · 0 comments

Updated IndexModel code from OnGetAsync follows. Key was removing the use of Enumerable.Range to generate the day offsets based on the start and end time the first and last sessions in the entire conference, but rather looking at the distinct dates in the actual set of sessions being displayed.

var sessions = await GetSessionsAsync();

var startDate = sessions.Min(s => s.StartTime?.Date);

DayOffsets = sessions.Select(s => s.StartTime?.Date)
                                 .Distinct()
                                 .OrderBy(d => d)
                                 .Select(day => ((int)Math.Floor((day.Value - startDate)?.TotalDays ?? 0),
                                                day?.DayOfWeek))
                                 .ToList();

var filterDate = startDate?.AddDays(day);

Sessions = sessions.Where(s => s.StartTime?.Date == filterDate)
                   .OrderBy(s => s.TrackId)
                   .GroupBy(s => s.StartTime)
                   .OrderBy(g => g.Key);