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.
This commit is contained in:
2026-01-09 11:54:55 -05:00
parent 99880e78c7
commit b7e812bb63
+19 -78
View File
@@ -1,92 +1,33 @@
using Core.Entities; using Core.Entities;
using Data;
using Microsoft.EntityFrameworkCore;
namespace WebApp.Services; namespace WebApp.Services;
public class EventOccurrenceService : IEventOccurrenceService public class EventOccurrenceService : IEventOccurrenceService
{ {
public Task<IEnumerable<EventOccurrence>> GetEventOccurrencesAsync() private readonly AppDbContext _context;
{
// Mock data for demonstration purposes
// This will be replaced with database-backed implementation later
var mockOccurrences = new List<EventOccurrence>
{
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"
}
};
return Task.FromResult<IEnumerable<EventOccurrence>>(mockOccurrences); public EventOccurrenceService(AppDbContext context)
{
_context = context;
} }
public Task<IEnumerable<EventOccurrence>> GetEventOccurrencesForDateRangeAsync(DateTime start, DateTime end) public async Task<IEnumerable<EventOccurrence>> GetEventOccurrencesAsync()
{ {
return GetEventOccurrencesAsync().ContinueWith(task => return await _context.EventOccurrences
.Include(eo => eo.EventDefinition)
.OrderBy(eo => eo.StartTime)
.ToListAsync();
}
public async Task<IEnumerable<EventOccurrence>> GetEventOccurrencesForDateRangeAsync(DateTime start, DateTime end)
{ {
var allOccurrences = task.Result; return await _context.EventOccurrences
return allOccurrences.Where(eo => .Include(eo => eo.EventDefinition)
eo.StartTime.Date >= start.Date && .Where(eo => eo.StartTime.Date >= start.Date && eo.StartTime.Date <= end.Date)
eo.StartTime.Date <= end.Date); .OrderBy(eo => eo.StartTime)
}); .ToListAsync();
} }
} }