Files
chapter-organizer/WebApp/Services/EventOccurrenceService.cs
poprhythm a9036d5d04 Add state schedule handout feature and configuration options
This commit introduces a new StateScheduleHandout component for generating printable schedules for students, including a combined master list of events. It adds configuration options in appsettings.json for state abbreviations and special event filters, enhancing the scheduling functionality. The Program.cs file is updated to register the new StateScheduleHandoutOptions, and the Calendar and Teams components are modified to include links to the new handout feature. Additionally, utility methods for filtering event occurrences are implemented to support the new functionality, improving the overall user experience in managing state schedules.
2026-04-06 23:33:57 -04:00

54 lines
1.6 KiB
C#

using Core.Entities;
using Data;
using Microsoft.EntityFrameworkCore;
namespace WebApp.Services;
public class EventOccurrenceService : IEventOccurrenceService
{
private readonly AppDbContext _context;
public EventOccurrenceService(AppDbContext context)
{
_context = context;
}
public async Task<IEnumerable<EventOccurrence>> GetEventOccurrencesAsync()
{
return await _context.EventOccurrences
.Include(eo => eo.EventDefinition)
.OrderBy(eo => eo.StartTime)
.ToListAsync();
}
public async Task<IEnumerable<EventOccurrence>> GetEventOccurrencesForDateRangeAsync(DateTime start, DateTime end)
{
return await _context.EventOccurrences
.Include(eo => eo.EventDefinition)
.Where(eo => eo.StartTime.Date >= start.Date && eo.StartTime.Date <= end.Date)
.OrderBy(eo => eo.StartTime)
.ToListAsync();
}
public async Task<Dictionary<int, List<Team>>> GetTeamsByEventDefinitionIdsAsync(IEnumerable<int> eventDefinitionIds)
{
var ids = eventDefinitionIds.Where(id => id > 0).Distinct().ToList();
if (!ids.Any())
{
return new Dictionary<int, List<Team>>();
}
var teams = await _context.Teams
.Include(t => t.Event)
.Include(t => t.Students)
.Include(t => t.Captain)
.Where(t => t.Event != null && ids.Contains(t.Event.Id))
.ToListAsync();
return teams
.GroupBy(t => t.Event!.Id)
.ToDictionary(g => g.Key, g => g.ToList());
}
}