
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
90 lines
3.0 KiB
C#
90 lines
3.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using Oqtane.Modules;
|
|
using SZUAbsolventenverein.Module.EventRegistration.Models;
|
|
|
|
namespace SZUAbsolventenverein.Module.EventRegistration.Repository
|
|
{
|
|
public class ResponseRepository : IResponseRepository, ITransientService
|
|
{
|
|
private readonly IDbContextFactory<EventRegistrationContext> _factory;
|
|
|
|
public ResponseRepository(IDbContextFactory<EventRegistrationContext> factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
public IEnumerable<Response> GetResponses(int ModuleId)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
return db.Response.Where(item => item.ModuleId == ModuleId).ToList();
|
|
}
|
|
|
|
public IEnumerable<Response> GetResponses(int EventId, int ModuleId)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
return db.Response.Where(item => item.ModuleId == ModuleId && item.EventRegistrationId == EventId).ToList();
|
|
}
|
|
|
|
public Response GetResponse(int EventRegistrationId)
|
|
{
|
|
return GetResponse(EventRegistrationId, true);
|
|
}
|
|
|
|
public Response GetResponse(int EventRegistrationId, bool tracking)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
if (tracking)
|
|
{
|
|
return db.Response.Find(EventRegistrationId);
|
|
}
|
|
else
|
|
{
|
|
return db.Response.AsNoTracking().FirstOrDefault(item => item.EventRegistrationId == EventRegistrationId);
|
|
}
|
|
}
|
|
|
|
public Response GetResponse(int EventId, int OwnerId)
|
|
{
|
|
return GetResponse(EventId, OwnerId, true);
|
|
}
|
|
|
|
public Response GetResponse(int EventId, int OwnerId, bool tracking)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
if (tracking)
|
|
{
|
|
return db.Response.FirstOrDefault(item => item.EventRegistrationId == EventId && item.OwnerId == OwnerId);
|
|
}
|
|
else
|
|
{
|
|
return db.Response.AsNoTracking().FirstOrDefault(item => item.EventRegistrationId == EventId && item.OwnerId == OwnerId);
|
|
}
|
|
}
|
|
|
|
public Response AddResponse(Response EventResponse)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
db.Response.Add(EventResponse);
|
|
db.SaveChanges();
|
|
return EventResponse;
|
|
}
|
|
|
|
public Response UpdateResponse(Response EventResponse)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
db.Entry(EventResponse).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return EventResponse;
|
|
}
|
|
|
|
public void DeleteResponse(int EventRegistrationId)
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
Response EventResponse = db.Response.Find(EventRegistrationId);
|
|
db.Response.Remove(EventResponse);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|