66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using Oqtane.Modules;
|
|
|
|
namespace SZUAbsolventenverein.Module.EventRegistration.Repository
|
|
{
|
|
public class EventRegistrationRepository : IEventRegistrationRepository, ITransientService
|
|
{
|
|
private readonly IDbContextFactory<EventRegistrationContext> _factory;
|
|
|
|
public EventRegistrationRepository(IDbContextFactory<EventRegistrationContext> factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
|
|
public IEnumerable<Models.Event> GetEventRegistrations(int ModuleId)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
return db.Event.Where(item => item.ModuleId == ModuleId).ToList();
|
|
}
|
|
|
|
public Models.Event GetEventRegistration(int EventRegistrationId)
|
|
{
|
|
return GetEventRegistration(EventRegistrationId, true);
|
|
}
|
|
|
|
public Models.Event GetEventRegistration(int EventRegistrationId, bool tracking)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
if (tracking)
|
|
{
|
|
return db.Event.Find(EventRegistrationId);
|
|
}
|
|
else
|
|
{
|
|
return db.Event.AsNoTracking().FirstOrDefault(item => item.EventRegistrationId == EventRegistrationId);
|
|
}
|
|
}
|
|
|
|
public Models.Event AddEventRegistration(Models.Event EventRegistration)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
db.Event.Add(EventRegistration);
|
|
db.SaveChanges();
|
|
return EventRegistration;
|
|
}
|
|
|
|
public Models.Event UpdateEventRegistration(Models.Event EventRegistration)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
db.Entry(EventRegistration).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return EventRegistration;
|
|
}
|
|
|
|
public void DeleteEventRegistration(int EventRegistrationId)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
Models.Event EventRegistration = db.Event.Find(EventRegistrationId);
|
|
db.Event.Remove(EventRegistration);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|