Added commands to assign business to user
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,6 +11,8 @@ namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
public abstract class BusinessBase : IBankAccountOwner
|
||||
{
|
||||
private TextLabel _informationLabel;
|
||||
|
||||
public abstract int Id { get; }
|
||||
public abstract string Name { get; }
|
||||
|
||||
@@ -21,12 +24,36 @@ namespace reallife_gamemode.Server.Business
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == this.Id);
|
||||
return databaseContext.BusinessBankAccounts.FirstOrDefault(u => u.BusinessId == Id);
|
||||
}
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
_informationLabel = NAPI.TextLabel.CreateTextLabel(Name, Position, 20.0f, 1.3f, 0, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
//NAPI.Util.ConsoleOutput("Updating Business: " + Name);
|
||||
|
||||
User owner = GetOwner();
|
||||
string infoText = Name + "\n" + "Besitzer: " + (owner == null ? "Niemand" : owner.Name) + "\nKasse: " + (GetBankAccount()?.Balance ?? 0);
|
||||
_informationLabel.Text = infoText;
|
||||
}
|
||||
|
||||
public User GetOwner()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = dbContext.Users.FirstOrDefault(u => u.BusinessId == Id);
|
||||
//NAPI.Util.ConsoleOutput("[" + Name + "] GetOwner: " + (user?.Name ?? "null"));
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user