outsourced database initialization, faction bank accounts get added if none exist

This commit is contained in:
hydrant
2018-11-22 18:41:40 +01:00
parent 334a043cfe
commit ad6e5a13f5
3 changed files with 62 additions and 7 deletions

View File

@@ -0,0 +1,37 @@
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Util
{
class FactionHelper
{
public static void CheckFactionBankAccounts()
{
NAPI.Util.ConsoleOutput("Checking faction bank accounts...");
using(var dbContext = new DatabaseContext())
{
foreach(Faction faction in dbContext.Factions)
{
if(faction.GetBankAccount(dbContext) == null)
{
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
FactionBankAccount factionBankAccount = new FactionBankAccount()
{
Balance = 0,
Bic = "",
Iban = "",
FactionId = faction.Id,
Active = true
};
dbContext.FactionBankAccounts.Add(factionBankAccount);
}
}
dbContext.SaveChanges();
}
}
}
}