Added commands to assign business to user

This commit is contained in:
hydrant
2018-11-19 22:24:06 +01:00
parent 225eb78ced
commit cef42180c9
7 changed files with 130 additions and 9 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
namespace reallife_gamemode.Server.Business
{
public class SmsBusiness : BusinessBase
{
public override int Id => 1;
public override string Name => "SMS Business";
public override Vector3 Position => new Vector3(-423, 1130, 326);
public override void Load()
{
}
}
}

View File

@@ -9,15 +9,15 @@ namespace reallife_gamemode.Server.Business
{
class TestBusiness : BusinessBase
{
public override int Id => 1;
public override int Id => 0;
public override string Name => "Test Business";
public override Vector3 Position => throw new NotImplementedException();
public override Vector3 Position => new Vector3(-443, 1134, 326);
public override void Load()
{
throw new NotImplementedException();
}
}
}