From b7e812bb639604d032d353893649a72be0aee310 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Fri, 9 Jan 2026 11:54:55 -0500 Subject: [PATCH] Refactor EventOccurrenceService to implement database-backed event occurrence retrieval This commit updates the EventOccurrenceService to replace mock data with a database-backed implementation for retrieving event occurrences. The GetEventOccurrencesAsync and GetEventOccurrencesForDateRangeAsync methods now utilize Entity Framework to fetch data from the AppDbContext, enhancing the service's functionality and ensuring accurate event management. --- WebApp/Services/EventOccurrenceService.cs | 99 +++++------------------ 1 file changed, 20 insertions(+), 79 deletions(-) diff --git a/WebApp/Services/EventOccurrenceService.cs b/WebApp/Services/EventOccurrenceService.cs index 16d3c6f..cdbf9ba 100644 --- a/WebApp/Services/EventOccurrenceService.cs +++ b/WebApp/Services/EventOccurrenceService.cs @@ -1,92 +1,33 @@ using Core.Entities; +using Data; +using Microsoft.EntityFrameworkCore; namespace WebApp.Services; public class EventOccurrenceService : IEventOccurrenceService { - public Task> GetEventOccurrencesAsync() - { - // Mock data for demonstration purposes - // This will be replaced with database-backed implementation later - var mockOccurrences = new List - { - new EventOccurrence - { - Name = "Opening Ceremony", - Date = "March 15", - Time = "8:00 a.m.", - StartTime = new DateTime(2026, 3, 15, 8, 0, 0), - EndTime = new DateTime(2026, 3, 15, 9, 0, 0), - Location = "Main Auditorium" - }, - new EventOccurrence - { - Name = "Sign-up", - Date = "March 15", - Time = "9:30 a.m.", - StartTime = new DateTime(2026, 3, 15, 9, 30, 0), - EndTime = new DateTime(2026, 3, 15, 11, 0, 0), - Location = "Registration Hall" - }, - new EventOccurrence - { - Name = "Judging", - Date = "March 15", - Time = "1:00 p.m.", - StartTime = new DateTime(2026, 3, 15, 13, 0, 0), - EndTime = new DateTime(2026, 3, 15, 17, 0, 0), - Location = "Exhibition Hall" - }, - new EventOccurrence - { - Name = "Submit", - Date = "March 16", - Time = "8:00 a.m.", - StartTime = new DateTime(2026, 3, 16, 8, 0, 0), - EndTime = new DateTime(2026, 3, 16, 10, 0, 0), - Location = "Submission Desk" - }, - new EventOccurrence - { - Name = "Competition 1", - Date = "March 16", - Time = "10:30 a.m.", - StartTime = new DateTime(2026, 3, 16, 10, 30, 0), - EndTime = new DateTime(2026, 3, 16, 12, 0, 0), - Location = "Competition Hall" - }, - new EventOccurrence - { - Name = "Competition 2", - Date = "March 16", - Time = "10:30 a.m.", - StartTime = new DateTime(2026, 3, 16, 11, 30, 0), - EndTime = new DateTime(2026, 3, 16, 13, 0, 0), - Location = "Competition Hall" - }, - new EventOccurrence - { - Name = "Awards Ceremony", - Date = "March 17", - Time = "2:00 p.m.", - StartTime = new DateTime(2026, 3, 17, 14, 0, 0), - EndTime = new DateTime(2026, 3, 17, 16, 0, 0), - Location = "Main Auditorium" - } - }; + private readonly AppDbContext _context; - return Task.FromResult>(mockOccurrences); + public EventOccurrenceService(AppDbContext context) + { + _context = context; } - public Task> GetEventOccurrencesForDateRangeAsync(DateTime start, DateTime end) + public async Task> GetEventOccurrencesAsync() { - return GetEventOccurrencesAsync().ContinueWith(task => - { - var allOccurrences = task.Result; - return allOccurrences.Where(eo => - eo.StartTime.Date >= start.Date && - eo.StartTime.Date <= end.Date); - }); + 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(); } }