1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-23 19:42:51 +01:00
Minecraft-Phantom-Panel/Controller/Phantom.Controller.Database/Factories/AbstractUpsertHelper.cs

31 lines
614 B
C#

using Microsoft.EntityFrameworkCore;
namespace Phantom.Controller.Database.Factories;
public abstract class AbstractUpsertHelper<T> where T : class {
private protected readonly ApplicationDbContext Ctx;
internal AbstractUpsertHelper(ApplicationDbContext ctx) {
this.Ctx = ctx;
}
private protected abstract DbSet<T> Set { get; }
private protected abstract T Construct(Guid guid);
public T Fetch(Guid guid) {
DbSet<T> set = Set;
T? entity = set.Find(guid);
if (entity == null) {
entity = Construct(guid);
set.Add(entity);
}
else {
set.Update(entity);
}
return entity;
}
}