Konstantin Hintermayer 38c5bef225 Bulk-Commit: Darft: Anmeldetool.
Interface Definition: done
Server-Side-Implementation: partly done (CR missing, potential Refactor, ...)
Client-Side-Implementation: started: (UI: done, Service: started, but works with SSR)
Missing: Permissions / Roles to restrict access to an event.
Missing: Fields on Event.
Missing: Good Styling
Time-Took: about 12 Hours.
Learning: Commit in smaller packets, rest will be discussed at CR
2025-05-14 20:40:10 +02:00

66 lines
2.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Collections.Generic;
using Oqtane.Modules;
namespace SZUAbsolventenverein.Module.EventRegistration.Repository
{
public class EventRepository : IEventRepository, ITransientService
{
private readonly IDbContextFactory<EventRegistrationContext> _factory;
public EventRepository(IDbContextFactory<EventRegistrationContext> factory)
{
_factory = factory;
}
public IEnumerable<Models.Event> GetEvents(int ModuleId)
{
using var db = _factory.CreateDbContext();
return db.Event.Where(item => item.ModuleId == ModuleId).ToList();
}
public Models.Event GetEvent(int EventRegistrationId)
{
return GetEvent(EventRegistrationId, true);
}
public Models.Event GetEvent(int EventRegistrationId, bool tracking)
{
using var db = _factory.CreateDbContext();
if (tracking)
{
return db.Event.Find(EventRegistrationId);
}
else
{
return db.Event.AsNoTracking().FirstOrDefault(item => item.EventId == EventRegistrationId);
}
}
public Models.Event AddEvent(Models.Event EventRegistration)
{
using var db = _factory.CreateDbContext();
db.Event.Add(EventRegistration);
db.SaveChanges();
return EventRegistration;
}
public Models.Event UpdateEvent(Models.Event EventRegistration)
{
using var db = _factory.CreateDbContext();
db.Entry(EventRegistration).State = EntityState.Modified;
db.SaveChanges();
return EventRegistration;
}
public void DeleteEvent(int EventRegistrationId)
{
using var db = _factory.CreateDbContext();
Models.Event EventRegistration = db.Event.Find(EventRegistrationId);
db.Event.Remove(EventRegistration);
db.SaveChanges();
}
}
}