mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user