Files
2026-10-16 23:33:13 -07:00

30 lines
776 B
C#

using Microsoft.EntityFrameworkCore;
using RadicadeServer.DB;
using RadicadeServer.RecNet.Config;
namespace RadicadeServer.Utils
{
public static class GameConfigSeeder
{
public static async Task<ConfigVal?> FindAsync(RecDBContext db, string key)
=> db.GameConfig.Local.FirstOrDefault(row => row.Key == key)
?? await db.GameConfig.FirstOrDefaultAsync(row => row.Key == key);
public static async Task<ConfigVal> UpsertAsync(RecDBContext db, string key, string value)
{
var existing = await FindAsync(db, key);
if (existing == null)
{
var added = new ConfigVal(key, value);
await db.GameConfig.AddAsync(added);
return added;
}
if (string.IsNullOrWhiteSpace(existing.Value))
existing.Value = value;
return existing;
}
}
}