Add project files.
This commit is contained in:
28
Server/Repository/EventRegistrationContext.cs
Normal file
28
Server/Repository/EventRegistrationContext.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.EventRegistration.Repository
|
||||
{
|
||||
public class EventRegistrationContext : DBContextBase, ITransientService, IMultiDatabase
|
||||
{
|
||||
public virtual DbSet<Models.Event> Event { get; set; }
|
||||
public virtual DbSet<Models.Response> Response { get; set; }
|
||||
|
||||
public EventRegistrationContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
|
||||
{
|
||||
// ContextBase handles multi-tenant database connections
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<Models.Event>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinEvent"));
|
||||
builder.Entity<Models.Response>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinEventResponse"));
|
||||
}
|
||||
}
|
||||
}
|
65
Server/Repository/EventRegistrationRepository.cs
Normal file
65
Server/Repository/EventRegistrationRepository.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 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();
|
||||
}
|
||||
}
|
||||
}
|
15
Server/Repository/IEventRegistrationRepository.cs
Normal file
15
Server/Repository/IEventRegistrationRepository.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.EventRegistration.Repository
|
||||
{
|
||||
public interface IEventRegistrationRepository
|
||||
{
|
||||
IEnumerable<Models.Event> GetEventRegistrations(int ModuleId);
|
||||
Models.Event GetEventRegistration(int EventRegistrationId);
|
||||
Models.Event GetEventRegistration(int EventRegistrationId, bool tracking);
|
||||
Models.Event AddEventRegistration(Models.Event EventRegistration);
|
||||
Models.Event UpdateEventRegistration(Models.Event EventRegistration);
|
||||
void DeleteEventRegistration(int EventRegistrationId);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user