New: DB-Migration / Repositories und Models für den Premiumbereich
This commit is contained in:
83
Server/Repository/EngineerApplicationRepository.cs
Normal file
83
Server/Repository/EngineerApplicationRepository.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Modules;
|
||||
using SZUAbsolventenverein.Module.PremiumArea.Models;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||
{
|
||||
public interface IEngineerApplicationRepository
|
||||
{
|
||||
IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId);
|
||||
IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId, string status);
|
||||
EngineerApplication GetEngineerApplication(int ApplicationId);
|
||||
EngineerApplication GetEngineerApplication(int ApplicationId, bool tracking);
|
||||
EngineerApplication AddEngineerApplication(EngineerApplication EngineerApplication);
|
||||
EngineerApplication UpdateEngineerApplication(EngineerApplication EngineerApplication);
|
||||
void DeleteEngineerApplication(int ApplicationId);
|
||||
}
|
||||
|
||||
public class EngineerApplicationRepository : IEngineerApplicationRepository, ITransientService
|
||||
{
|
||||
private readonly IDbContextFactory<PremiumAreaContext> _factory;
|
||||
|
||||
public EngineerApplicationRepository(IDbContextFactory<PremiumAreaContext> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
public IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
return db.EngineerApplication.Where(item => item.ModuleId == ModuleId).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId, string status)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
return db.EngineerApplication.Where(item => item.ModuleId == ModuleId && item.Status == status).ToList();
|
||||
}
|
||||
|
||||
public EngineerApplication GetEngineerApplication(int ApplicationId)
|
||||
{
|
||||
return GetEngineerApplication(ApplicationId, true);
|
||||
}
|
||||
|
||||
public EngineerApplication GetEngineerApplication(int ApplicationId, bool tracking)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
if (tracking)
|
||||
{
|
||||
return db.EngineerApplication.Find(ApplicationId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.EngineerApplication.AsNoTracking().FirstOrDefault(item => item.ApplicationId == ApplicationId);
|
||||
}
|
||||
}
|
||||
|
||||
public EngineerApplication AddEngineerApplication(EngineerApplication EngineerApplication)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.EngineerApplication.Add(EngineerApplication);
|
||||
db.SaveChanges();
|
||||
return EngineerApplication;
|
||||
}
|
||||
|
||||
public EngineerApplication UpdateEngineerApplication(EngineerApplication EngineerApplication)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Entry(EngineerApplication).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return EngineerApplication;
|
||||
}
|
||||
|
||||
public void DeleteEngineerApplication(int ApplicationId)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
EngineerApplication EngineerApplication = db.EngineerApplication.Find(ApplicationId);
|
||||
db.EngineerApplication.Remove(EngineerApplication);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user