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

@@ -59,62 +59,70 @@ namespace ReallifeGamemode.Server.Managers
[RemoteEvent("Business_DepositMoney")]
public void BusinessDepositMoney(Player player, int amount)
{
User user = player.GetUser();
if (user == null)
using (var dbContext = new DatabaseContext())
{
return;
}
User user = player.GetUser(dbContext);
if (user == null)
{
return;
}
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung");
TransactionResult result = BankManager.TransferMoney(user, playerBusiness, amount, "Überweisung", dbContext);
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
{
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
return;
}
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Du hast nicht genug Geld");
return;
}
else if (result == TransactionResult.SUCCESS)
{
playerBusiness.SendBusinessDataToPlayer(player);
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
return;
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
{
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
return;
}
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Du hast nicht genug Geld");
return;
}
else if (result == TransactionResult.SUCCESS)
{
playerBusiness.SendBusinessDataToPlayer(player);
playerBusiness.Update();
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
return;
}
}
}
[RemoteEvent("Business_WithdrawMoney")]
public void BusinessWithdrawMoney(Player player, int amount)
{
User user = player.GetUser();
if (user == null)
using (var dbContext = new DatabaseContext())
{
return;
}
User user = player.GetUser(dbContext);
if (user == null)
{
return;
}
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
BusinessBase playerBusiness = GetBusiness(user.BusinessId);
TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung");
TransactionResult result = BankManager.TransferMoney(playerBusiness, user, amount, "Überweisung", dbContext);
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
{
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
return;
}
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Es ist nicht genug Geld auf der Businesskasse vorhanden");
return;
}
else if (result == TransactionResult.SUCCESS)
{
playerBusiness.SendBusinessDataToPlayer(player);
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
return;
if (result == TransactionResult.NEGATIVE_MONEY_SENT)
{
player.SendNotification("~r~Es können nur positive Beträge überwiesen werden");
return;
}
else if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Es ist nicht genug Geld auf der Businesskasse vorhanden");
return;
}
else if (result == TransactionResult.SUCCESS)
{
playerBusiness.SendBusinessDataToPlayer(player);
playerBusiness.Update();
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
return;
}
}
}
@@ -140,81 +148,80 @@ namespace ReallifeGamemode.Server.Managers
[RemoteEvent("VehShop_BuyVehicle")]
public void CarDealerBusiness_BuyVehicle(Player player, string target)
{
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
if (sVeh == null) return;
if (!(sVeh is ShopVehicle)) return;
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
int price = shopVehicle.Price;
CarDealerBusinessBase business = GetBusiness(shopVehicle.BusinessId) as CarDealerBusinessBase;
TransactionResult result = BankManager.TransferMoney(player.GetUser(), business, price, "Auto gekauft");
if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Du hast nicht genug Geld: " + price.ToMoneyString());
return;
}
Vector3 spawnPos = business.CarSpawnPositon.Around(3);
player.TriggerEvent("SERVER:Util_setWaypoint", spawnPos.X, spawnPos.Y);
ServerVehicle newVeh = null;
if (target == "Spieler")
{
newVeh = new UserVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
UserId = player.GetUser().Id,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
else if (target == "Fraktion")
{
newVeh = new FactionVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
FactionId = player.GetUser().FactionId,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
else if (target == "Gruppe")
{
newVeh = new GroupVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
GroupId = player.GetUser().Group.Id,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
using (var dbContext = new DatabaseContext())
{
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
if (sVeh == null) return;
if (!(sVeh is ShopVehicle)) return;
ShopVehicle shopVehicle = (ShopVehicle)sVeh;
int price = shopVehicle.Price;
CarDealerBusinessBase business = GetBusiness(shopVehicle.BusinessId) as CarDealerBusinessBase;
TransactionResult result = BankManager.TransferMoney(player.GetUser(dbContext), business, price, "Auto gekauft", dbContext);
if (result == TransactionResult.SENDER_NOT_ENOUGH_MONEY)
{
player.SendNotification("~r~Du hast nicht genug Geld: " + price.ToMoneyString());
return;
}
Vector3 spawnPos = business.CarSpawnPositon.Around(3);
player.TriggerEvent("SERVER:Util_setWaypoint", spawnPos.X, spawnPos.Y);
ServerVehicle newVeh = null;
if (target == "Spieler")
{
newVeh = new UserVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
UserId = player.GetUser().Id,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
else if (target == "Fraktion")
{
newVeh = new FactionVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
FactionId = player.GetUser().FactionId,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
else if (target == "Gruppe")
{
newVeh = new GroupVehicle
{
Heading = business.CarSpawnHeading,
PositionX = spawnPos.X,
PositionY = spawnPos.Y,
PositionZ = spawnPos.Z,
Locked = false,
GroupId = player.GetUser().Group.Id,
Model = shopVehicle.Model,
PrimaryColor = 111,
SecondaryColor = 111,
Active = true,
};
}
dbContext.ServerVehicles.Add(newVeh);
dbContext.SaveChanges();
}
newVeh.Spawn();
newVeh.Spawn();
}
}
[RemoteEvent("CLIENT:Business_BuyBusiness")]
@@ -239,7 +246,7 @@ namespace ReallifeGamemode.Server.Managers
ChatService.ErrorMessage(player, "Du kannst nicht mehrere Businesse besitzen");
}
IBankAccount bankAccount = user.GetBankAccount(dbContext);
IBankAccount bankAccount = user.BankAccount;
if (price > bankAccount.Balance)
{