bank account refactor

This commit is contained in:
hydrant
2020-03-15 21:33:04 +01:00
parent 75e26b8e8a
commit 92c054c90c
30 changed files with 2088 additions and 300 deletions

View File

@@ -6,7 +6,7 @@ using ReallifeGamemode.Database.Models;
namespace ReallifeGamemode.Database.Entities
{
public partial class Group : IBankAccountOwner
public partial class Group : BankAccountHolder<GroupBankAccount>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
@@ -14,34 +14,6 @@ namespace ReallifeGamemode.Database.Entities
public string Name { get; set; }
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
{
GroupBankAccount bankAccount = null;
if (databaseContext == null)
{
using (databaseContext = new DatabaseContext())
{
bankAccount = databaseContext.GroupBankAccounts.Include(g => g.Group).Where(g => g.Group == this).FirstOrDefault();
}
}
else
{
bankAccount = databaseContext.GroupBankAccounts.Include(g => g.Group).Where(g => g.Group == this).FirstOrDefault();
}
if (bankAccount == null)
{
bankAccount = new GroupBankAccount
{
Group = this,
Balance = 0
};
databaseContext.GroupBankAccounts.Add(bankAccount);
databaseContext.SaveChanges();
}
return bankAccount;
}
public override string BankAccountName => Name;
}
}