DB Migrtation geändert und PDF upload funktioniert
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -52,23 +53,59 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.EngineerApplication.AsNoTracking().FirstOrDefault(item => item.ApplicationId == ApplicationId);
|
||||
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();
|
||||
try
|
||||
{
|
||||
EngineerApplication.CreatedBy = EngineerApplication.CreatedBy ?? "system";
|
||||
EngineerApplication.CreatedOn = DateTime.UtcNow;
|
||||
EngineerApplication.ModifiedBy = EngineerApplication.ModifiedBy ?? "system";
|
||||
EngineerApplication.ModifiedOn = DateTime.UtcNow;
|
||||
db.EngineerApplication.Add(EngineerApplication);
|
||||
db.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Throwing a new exception with more details so it's visible
|
||||
var msg = $"DB Error: {ex.Message} | Inner: {ex.InnerException?.Message}";
|
||||
Console.WriteLine(msg); // Log to console for dotnet run
|
||||
throw new Exception(msg, ex);
|
||||
}
|
||||
|
||||
return EngineerApplication;
|
||||
}
|
||||
|
||||
public EngineerApplication UpdateEngineerApplication(EngineerApplication EngineerApplication)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Entry(EngineerApplication).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
try
|
||||
{
|
||||
var existing = db.EngineerApplication.Find(EngineerApplication.ApplicationId);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.FileId = EngineerApplication.FileId;
|
||||
existing.Status = EngineerApplication.Status;
|
||||
existing.SubmittedOn = EngineerApplication.SubmittedOn;
|
||||
existing.ApprovedOn = EngineerApplication.ApprovedOn;
|
||||
|
||||
existing.ModifiedBy = EngineerApplication.ModifiedBy ?? "system";
|
||||
existing.ModifiedOn = DateTime.UtcNow;
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = $"DB Error (Update): {ex.Message} | Inner: {ex.InnerException?.Message}";
|
||||
Console.WriteLine(msg);
|
||||
throw new Exception(msg, ex);
|
||||
}
|
||||
|
||||
return EngineerApplication;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -51,6 +52,10 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||
public Models.PremiumArea AddPremiumArea(Models.PremiumArea PremiumArea)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
PremiumArea.CreatedBy = PremiumArea.CreatedBy ?? "system";
|
||||
PremiumArea.CreatedOn = DateTime.UtcNow;
|
||||
PremiumArea.ModifiedBy = PremiumArea.ModifiedBy ?? "system";
|
||||
PremiumArea.ModifiedOn = DateTime.UtcNow;
|
||||
db.PremiumArea.Add(PremiumArea);
|
||||
db.SaveChanges();
|
||||
return PremiumArea;
|
||||
@@ -59,8 +64,14 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||
public Models.PremiumArea UpdatePremiumArea(Models.PremiumArea PremiumArea)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.Entry(PremiumArea).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
var existing = db.PremiumArea.Find(PremiumArea.PremiumAreaId);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.Name = PremiumArea.Name;
|
||||
existing.ModifiedBy = PremiumArea.ModifiedBy ?? "system";
|
||||
existing.ModifiedOn = DateTime.UtcNow;
|
||||
db.SaveChanges();
|
||||
}
|
||||
return PremiumArea;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -34,19 +35,35 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||
using var db = _factory.CreateDbContext();
|
||||
if (UserPremium.Id > 0)
|
||||
{
|
||||
db.Entry(UserPremium).State = EntityState.Modified;
|
||||
var existing = db.UserPremium.Find(UserPremium.Id);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.UserId = UserPremium.UserId;
|
||||
existing.PremiumUntil = UserPremium.PremiumUntil;
|
||||
existing.ModifiedBy = UserPremium.ModifiedBy ?? "system";
|
||||
existing.ModifiedOn = DateTime.UtcNow;
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UserPremium.CreatedBy = UserPremium.CreatedBy ?? "system";
|
||||
UserPremium.CreatedOn = DateTime.UtcNow;
|
||||
UserPremium.ModifiedBy = UserPremium.ModifiedBy ?? "system";
|
||||
UserPremium.ModifiedOn = DateTime.UtcNow;
|
||||
db.UserPremium.Add(UserPremium);
|
||||
db.SaveChanges();
|
||||
}
|
||||
db.SaveChanges();
|
||||
return UserPremium;
|
||||
}
|
||||
|
||||
public void AddPremiumEvent(PremiumEvent premiumEvent)
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
premiumEvent.CreatedBy = premiumEvent.CreatedBy ?? "system";
|
||||
premiumEvent.CreatedOn = DateTime.UtcNow;
|
||||
premiumEvent.ModifiedBy = premiumEvent.ModifiedBy ?? "system";
|
||||
premiumEvent.ModifiedOn = DateTime.UtcNow;
|
||||
db.PremiumEvent.Add(premiumEvent);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user