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> GetEventOccurrencesAsync() { return await _context.EventOccurrences .Include(eo => eo.EventDefinition) .OrderBy(eo => eo.StartTime) .ToListAsync(); } public async Task> 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>> GetTeamsByEventDefinitionIdsAsync(IEnumerable eventDefinitionIds) { var ids = eventDefinitionIds.Where(id => id > 0).Distinct().ToList(); if (!ids.Any()) { return new Dictionary>(); } 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()); } }