COSMETIC: rename EventRepository
This commit is contained in:
65
Server/Repository/EventRepository.cs
Normal file
65
Server/Repository/EventRepository.cs
Normal file
@ -0,0 +1,65 @@
|
||||
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.EventRegistrationId == 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user