bank account refactor
This commit is contained in:
@@ -32,7 +32,12 @@ namespace ReallifeGamemode.DataService.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult<GetUserDataResponse> Data()
|
||||
{
|
||||
User user = dbContext.Users.Include(u => u.Faction).Include(u => u.FactionRank).Where(u => u.Id == UserId).FirstOrDefault();
|
||||
User user = dbContext.Users
|
||||
.Include(u => u.Faction)
|
||||
.Include(u => u.FactionRank)
|
||||
.Include(u => u.BankAccount)
|
||||
.Where(u => u.Id == UserId)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -44,7 +49,7 @@ namespace ReallifeGamemode.DataService.Controllers
|
||||
Name = user.Name,
|
||||
AdminLevel = user.AdminLevel,
|
||||
RegistrationDate = user.RegistrationDate,
|
||||
BankMoney = user.GetBankAccount().Balance,
|
||||
BankMoney = user.BankAccount.Balance,
|
||||
HandMoney = user.Handmoney,
|
||||
FactionName = user.Faction?.Name,
|
||||
FactionRankName = user.FactionRank?.RankName,
|
||||
|
||||
17
ReallifeGamemode.Database/BankAccountHolder.cs
Normal file
17
ReallifeGamemode.Database/BankAccountHolder.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Database
|
||||
{
|
||||
public abstract class BankAccountHolder<T> where T : class, IBankAccount, new()
|
||||
{
|
||||
public abstract string BankAccountName { get; }
|
||||
|
||||
[ForeignKey(nameof(BankAccountId))]
|
||||
public virtual T BankAccount { get; set; }
|
||||
|
||||
public virtual int? BankAccountId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ using ReallifeGamemode.Database.Models;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public partial class Faction : IBankAccountOwner
|
||||
public partial class Faction : BankAccountHolder<FactionBankAccount>
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
@@ -21,19 +21,6 @@ namespace ReallifeGamemode.Database.Entities
|
||||
public bool StateOwned { get; set; }
|
||||
public int WeaponDealTime { get; set; } = 60;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||
}
|
||||
}
|
||||
public override string BankAccountName => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,16 @@ namespace ReallifeGamemode.Database.Entities
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("Faction")]
|
||||
public int FactionId { get; set; }
|
||||
public Faction Faction { get; set; }
|
||||
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public string Iban { get; set; }
|
||||
|
||||
public int Balance { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ namespace ReallifeGamemode.Database.Entities
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public Group Group { get; set; }
|
||||
|
||||
public int Balance { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public partial class User : IBankAccountOwner
|
||||
public partial class User : BankAccountHolder<UserBankAccount>
|
||||
{
|
||||
[NotMapped]
|
||||
private int _wanteds;
|
||||
@@ -98,27 +98,12 @@ namespace ReallifeGamemode.Database.Entities
|
||||
|
||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
{
|
||||
using (databaseContext = new DatabaseContext())
|
||||
{
|
||||
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Player Player
|
||||
{
|
||||
get => NAPI.Pools.GetAllPlayers().Where(c => c.Name.ToLower() == this.Name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
public override string BankAccountName => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,28 +17,30 @@ namespace ReallifeGamemode.Database.Entities
|
||||
[NotMapped]
|
||||
private int _balance;
|
||||
|
||||
public delegate void BankAccountBalanceChangedEvent(UserBankAccount account);
|
||||
public static event BankAccountBalanceChangedEvent BalanceChanged;
|
||||
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("User")]
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
[StringLength(12)]
|
||||
public string Bic { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public string Iban { get; set; }
|
||||
|
||||
public int Balance
|
||||
{
|
||||
get => _balance;
|
||||
|
||||
set
|
||||
{
|
||||
_balance = value;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
PlayerService.GetPlayerByNameOrId(dbContext.Users.First(u => u.Id == UserId).Name).TriggerEvent("updateMoney", value);
|
||||
}
|
||||
BalanceChanged?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
95
ReallifeGamemode.Database/HeidiSQL_Export.txt
Normal file
95
ReallifeGamemode.Database/HeidiSQL_Export.txt
Normal file
@@ -0,0 +1,95 @@
|
||||
SessionManager_WindowLeft<|||>3<|||>432
|
||||
SessionManager_WindowTop<|||>3<|||>375
|
||||
ColWidths_connform.ListSessions<|||>1<|||>163,50,50,50,50,50,53
|
||||
ColsVisible_connform.ListSessions<|||>1<|||>0
|
||||
ColPositions_connform.ListSessions<|||>1<|||>0,1,2,3,4,5,6
|
||||
ColSort_connform.ListSessions<|||>1<|||>0,1
|
||||
MainWinOnMonitor<|||>3<|||>0
|
||||
ColWidths_MainForm.ListDatabases<|||>1<|||>150,80,50,50,50,50,50,50,50,50,120
|
||||
ColsVisible_MainForm.ListDatabases<|||>1<|||>0,1,2,3,4,5,6,7,8,9,10
|
||||
ColPositions_MainForm.ListDatabases<|||>1<|||>0,1,2,3,4,5,6,7,8,9,10
|
||||
ColSort_MainForm.ListDatabases<|||>1<|||>0,0
|
||||
ColWidths_MainForm.ListVariables<|||>1<|||>160,200,275
|
||||
ColsVisible_MainForm.ListVariables<|||>1<|||>0,1,2
|
||||
ColPositions_MainForm.ListVariables<|||>1<|||>0,1,2
|
||||
ColSort_MainForm.ListVariables<|||>1<|||>0,0
|
||||
ColWidths_MainForm.ListStatus<|||>1<|||>160,275,100,100
|
||||
ColsVisible_MainForm.ListStatus<|||>1<|||>0,1,2,3
|
||||
ColPositions_MainForm.ListStatus<|||>1<|||>0,1,2,3
|
||||
ColSort_MainForm.ListStatus<|||>1<|||>0,0
|
||||
ColWidths_MainForm.ListProcesses<|||>1<|||>70,80,80,80,80,50,50,44
|
||||
ColsVisible_MainForm.ListProcesses<|||>1<|||>0,1,2,3,4,5,6,7
|
||||
ColPositions_MainForm.ListProcesses<|||>1<|||>0,1,2,3,4,5,6,7
|
||||
ColSort_MainForm.ListProcesses<|||>1<|||>0,1
|
||||
ColWidths_MainForm.ListCommandStats<|||>1<|||>120,100,100,100,215
|
||||
ColsVisible_MainForm.ListCommandStats<|||>1<|||>0,1,2,3,4
|
||||
ColPositions_MainForm.ListCommandStats<|||>1<|||>0,1,2,3,4
|
||||
ColSort_MainForm.ListCommandStats<|||>1<|||>1,1
|
||||
ColWidths_MainForm.ListTables<|||>1<|||>120,70,70,120,120,70,100,50,70,70,70,70,70,90,120,70,70,70,50
|
||||
ColsVisible_MainForm.ListTables<|||>1<|||>0,1,2,3,4,5,6,18
|
||||
ColPositions_MainForm.ListTables<|||>1<|||>0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
|
||||
ColSort_MainForm.ListTables<|||>1<|||>0,0
|
||||
LastSessions<|||>1<|||>Unnamed
|
||||
LastActiveSession<|||>1<|||>Unnamed
|
||||
CoolBand0Index<|||>3<|||>0
|
||||
CoolBand0Break<|||>3<|||>1
|
||||
CoolBand0Width<|||>3<|||>818
|
||||
CoolBand1Index<|||>3<|||>1
|
||||
CoolBand1Break<|||>3<|||>1
|
||||
CoolBand1Width<|||>3<|||>818
|
||||
FileDialogEncoding_MainForm<|||>3<|||>0
|
||||
ColWidths_frmTableEditor.listColumns<|||>1<|||>38,100,156,90,60,65,50,119,130,140,100,100
|
||||
ColsVisible_frmTableEditor.listColumns<|||>1<|||>0,1,2,3,4,5,6,7,8,9,10,11
|
||||
ColPositions_frmTableEditor.listColumns<|||>1<|||>0,1,2,3,4,5,6,7,8,9,10,11
|
||||
ColSort_frmTableEditor.listColumns<|||>1<|||>-1,0
|
||||
ColWidths_frmTableEditor.treeIndexes<|||>1<|||>329,100,80
|
||||
ColsVisible_frmTableEditor.treeIndexes<|||>1<|||>0,1,2
|
||||
ColPositions_frmTableEditor.treeIndexes<|||>1<|||>0,1,2
|
||||
ColSort_frmTableEditor.treeIndexes<|||>1<|||>-1,0
|
||||
ColWidths_frmTableEditor.listForeignKeys<|||>1<|||>87,80,100,80,80,80
|
||||
ColsVisible_frmTableEditor.listForeignKeys<|||>1<|||>0,1,2,3,4,5
|
||||
ColPositions_frmTableEditor.listForeignKeys<|||>1<|||>0,1,2,3,4,5
|
||||
ColSort_frmTableEditor.listForeignKeys<|||>1<|||>-1,0
|
||||
MainWinLeft<|||>3<|||>410
|
||||
MainWinTop<|||>3<|||>294
|
||||
SQLFile0<|||>1<|||>C:\Users\michaplays27\Desktop\SQL\sql.sql
|
||||
MainWinMaximized<|||>3<|||>0
|
||||
ExportSQL_DataHow<|||>3<|||>2
|
||||
ExportSQL_Filenames<|||>1<|||>dutycloth<{{{><}}}>
|
||||
MainWinWidth<|||>3<|||>840
|
||||
MainWinHeight<|||>3<|||>525
|
||||
Servers\Unnamed\SessionCreated<|||>1<|||>2020-02-27 20:38:48
|
||||
Servers\Unnamed\Host<|||>1<|||>127.0.0.1
|
||||
Servers\Unnamed\WindowsAuth<|||>3<|||>0
|
||||
Servers\Unnamed\User<|||>1<|||>gtav-dev
|
||||
Servers\Unnamed\Password<|||>1<|||>783E394C767A3A3E587C3D575B7B7B3A5E5A50273D3670374E5A5A3D38394E576
|
||||
Servers\Unnamed\LoginPrompt<|||>3<|||>0
|
||||
Servers\Unnamed\Port<|||>1<|||>3306
|
||||
Servers\Unnamed\NetType<|||>3<|||>0
|
||||
Servers\Unnamed\Compressed<|||>3<|||>0
|
||||
Servers\Unnamed\LocalTimeZone<|||>3<|||>0
|
||||
Servers\Unnamed\QueryTimeout<|||>3<|||>0
|
||||
Servers\Unnamed\KeepAlive<|||>3<|||>0
|
||||
Servers\Unnamed\FullTableStatus<|||>3<|||>1
|
||||
Servers\Unnamed\Databases<|||>1<|||>
|
||||
Servers\Unnamed\Comment<|||>1<|||>
|
||||
Servers\Unnamed\StartupScriptFilename<|||>1<|||>
|
||||
Servers\Unnamed\SSHtunnelHost<|||>1<|||>
|
||||
Servers\Unnamed\SSHtunnelHostPort<|||>3<|||>0
|
||||
Servers\Unnamed\SSHtunnelUser<|||>1<|||>
|
||||
Servers\Unnamed\SSHtunnelPassword<|||>1<|||>6
|
||||
Servers\Unnamed\SSHtunnelTimeout<|||>3<|||>4
|
||||
Servers\Unnamed\SSHtunnelPrivateKey<|||>1<|||>
|
||||
Servers\Unnamed\SSHtunnelPort<|||>3<|||>3307
|
||||
Servers\Unnamed\SSL_Active<|||>3<|||>0
|
||||
Servers\Unnamed\SSL_Key<|||>1<|||>
|
||||
Servers\Unnamed\SSL_Cert<|||>1<|||>
|
||||
Servers\Unnamed\SSL_CA<|||>1<|||>
|
||||
Servers\Unnamed\SSL_Cipher<|||>1<|||>
|
||||
Servers\Unnamed\ServerVersionFull<|||>1<|||>10.3.9-MariaDB - mariadb.org binary distribution
|
||||
Servers\Unnamed\ConnectCount<|||>3<|||>10
|
||||
Servers\Unnamed\ServerVersion<|||>3<|||>100309
|
||||
Servers\Unnamed\LastConnect<|||>1<|||>2020-03-15 16:29:18
|
||||
Servers\Unnamed\lastUsedDB<|||>1<|||>gtav-devdb
|
||||
Servers\Unnamed\RefusedCount<|||>3<|||>44
|
||||
Servers\Unnamed\gtav-devdb|users\Sort<|||>1<|||>0_AdminLevel|
|
||||
1423
ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.Designer.cs
generated
Normal file
1423
ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,210 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
public partial class BankAccountRefactor : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_FactionBankAccounts_Factions_FactionId",
|
||||
table: "FactionBankAccounts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_GroupBankAccounts_Groups_GroupId",
|
||||
table: "GroupBankAccounts");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_UserBankAccounts_Users_UserId",
|
||||
table: "UserBankAccounts");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_UserBankAccounts_UserId",
|
||||
table: "UserBankAccounts");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_GroupBankAccounts_GroupId",
|
||||
table: "GroupBankAccounts");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_FactionBankAccounts_FactionId",
|
||||
table: "FactionBankAccounts");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BankAccountId",
|
||||
table: "Users",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BankAccountId",
|
||||
table: "Groups",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BankAccountId",
|
||||
table: "Factions",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE users u
|
||||
INNER JOIN userbankaccounts ub ON ub.userid = u.id
|
||||
SET u.bankaccountid = ub.id");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE factions f
|
||||
INNER JOIN factionbankaccounts fb ON fb.factionid = f.id
|
||||
SET f.bankaccountid = fb.id");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE groups g
|
||||
INNER JOIN groupbankaccounts gb ON gb.groupid = g.id
|
||||
SET g.bankaccountid = gb.id");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "UserId",
|
||||
table: "UserBankAccounts");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "GroupId",
|
||||
table: "GroupBankAccounts");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FactionId",
|
||||
table: "FactionBankAccounts");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_BankAccountId",
|
||||
table: "Users",
|
||||
column: "BankAccountId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Groups_BankAccountId",
|
||||
table: "Groups",
|
||||
column: "BankAccountId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Factions_BankAccountId",
|
||||
table: "Factions",
|
||||
column: "BankAccountId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Factions_FactionBankAccounts_BankAccountId",
|
||||
table: "Factions",
|
||||
column: "BankAccountId",
|
||||
principalTable: "FactionBankAccounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Groups_GroupBankAccounts_BankAccountId",
|
||||
table: "Groups",
|
||||
column: "BankAccountId",
|
||||
principalTable: "GroupBankAccounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Users_UserBankAccounts_BankAccountId",
|
||||
table: "Users",
|
||||
column: "BankAccountId",
|
||||
principalTable: "UserBankAccounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Factions_FactionBankAccounts_BankAccountId",
|
||||
table: "Factions");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Groups_GroupBankAccounts_BankAccountId",
|
||||
table: "Groups");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Users_UserBankAccounts_BankAccountId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Users_BankAccountId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Groups_BankAccountId",
|
||||
table: "Groups");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Factions_BankAccountId",
|
||||
table: "Factions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BankAccountId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BankAccountId",
|
||||
table: "Groups");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BankAccountId",
|
||||
table: "Factions");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "UserId",
|
||||
table: "UserBankAccounts",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "GroupId",
|
||||
table: "GroupBankAccounts",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "FactionId",
|
||||
table: "FactionBankAccounts",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserBankAccounts_UserId",
|
||||
table: "UserBankAccounts",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GroupBankAccounts_GroupId",
|
||||
table: "GroupBankAccounts",
|
||||
column: "GroupId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FactionBankAccounts_FactionId",
|
||||
table: "FactionBankAccounts",
|
||||
column: "FactionId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_FactionBankAccounts_Factions_FactionId",
|
||||
table: "FactionBankAccounts",
|
||||
column: "FactionId",
|
||||
principalTable: "Factions",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_GroupBankAccounts_Groups_GroupId",
|
||||
table: "GroupBankAccounts",
|
||||
column: "GroupId",
|
||||
principalTable: "Groups",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_UserBankAccounts_Users_UserId",
|
||||
table: "UserBankAccounts",
|
||||
column: "UserId",
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,6 +351,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("BankAccountId");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(32);
|
||||
|
||||
@@ -360,6 +362,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BankAccountId");
|
||||
|
||||
b.ToTable("Factions");
|
||||
});
|
||||
|
||||
@@ -375,15 +379,11 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<string>("Bic")
|
||||
.HasMaxLength(12);
|
||||
|
||||
b.Property<int>("FactionId");
|
||||
|
||||
b.Property<string>("Iban")
|
||||
.HasMaxLength(32);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FactionId");
|
||||
|
||||
b.ToTable("FactionBankAccounts");
|
||||
});
|
||||
|
||||
@@ -453,10 +453,14 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("BankAccountId");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BankAccountId");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
@@ -467,12 +471,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.Property<int>("Balance");
|
||||
|
||||
b.Property<int?>("GroupId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("GroupBankAccounts");
|
||||
});
|
||||
|
||||
@@ -967,6 +967,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.Property<int?>("BanId");
|
||||
|
||||
b.Property<int?>("BankAccountId");
|
||||
|
||||
b.Property<int?>("BusinessId");
|
||||
|
||||
b.Property<int?>("CharacterId");
|
||||
@@ -1032,6 +1034,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.HasIndex("BanId");
|
||||
|
||||
b.HasIndex("BankAccountId");
|
||||
|
||||
b.HasIndex("BusinessId")
|
||||
.IsUnique();
|
||||
|
||||
@@ -1063,12 +1067,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<string>("Iban")
|
||||
.HasMaxLength(32);
|
||||
|
||||
b.Property<int>("UserId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserBankAccounts");
|
||||
});
|
||||
|
||||
@@ -1273,12 +1273,11 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionBankAccount", b =>
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Faction", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction")
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.FactionBankAccount", "BankAccount")
|
||||
.WithMany()
|
||||
.HasForeignKey("FactionId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.HasForeignKey("BankAccountId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionRank", b =>
|
||||
@@ -1296,11 +1295,11 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
.HasForeignKey("FactionId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.GroupBankAccount", b =>
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Group", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.Group", "Group")
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.GroupBankAccount", "BankAccount")
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupId");
|
||||
.HasForeignKey("BankAccountId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.House", b =>
|
||||
@@ -1346,6 +1345,10 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
.WithMany()
|
||||
.HasForeignKey("BanId");
|
||||
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.UserBankAccount", "BankAccount")
|
||||
.WithMany()
|
||||
.HasForeignKey("BankAccountId");
|
||||
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.Character", "Character")
|
||||
.WithMany()
|
||||
.HasForeignKey("CharacterId");
|
||||
@@ -1367,14 +1370,6 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
.HasForeignKey("HouseId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserBankAccount", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserItem", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")
|
||||
|
||||
@@ -34,5 +34,10 @@ namespace ReallifeGamemode.Server.Core.Extensions
|
||||
|
||||
return dbContext.Users.Where(u => u.Name == player.Name).Select(data).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static bool IsAdmin(this IPlayer player, AdminLevel level, DatabaseContext dbContext)
|
||||
{
|
||||
return player.GetAdminLevel(dbContext) >= level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Core.Commands.User;
|
||||
using ReallifeGamemode.Server.Core.Extensions;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.Commands.Admin
|
||||
{
|
||||
abstract class AdminCommand : Command
|
||||
abstract class AdminCommand : UserCommand
|
||||
{
|
||||
protected abstract AdminLevel AdminLevel { get; }
|
||||
|
||||
public override bool CanExecute(IPlayer player)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return base.CanExecute(player) && player.IsAdmin(AdminLevel, GetDbContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
using ReallifeGamemode.Server.Log;
|
||||
|
||||
@@ -11,8 +12,9 @@ namespace ReallifeGamemode.Server.Core.Commands
|
||||
{
|
||||
public abstract bool CanExecute(IPlayer player);
|
||||
|
||||
protected abstract IAPI Api { get; }
|
||||
protected IAPI Api => Main.API;
|
||||
protected ILogger Log { get; set; }
|
||||
|
||||
public abstract string CommandName { get; }
|
||||
public virtual string HelpText { get; } = null;
|
||||
|
||||
@@ -20,5 +22,7 @@ namespace ReallifeGamemode.Server.Core.Commands
|
||||
{
|
||||
Log = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
|
||||
protected DatabaseContext GetDbContext() => Main.GetDbContext();
|
||||
}
|
||||
}
|
||||
|
||||
15
ReallifeGamemode.Server.Core/Commands/User/UserCommand.cs
Normal file
15
ReallifeGamemode.Server.Core/Commands/User/UserCommand.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.Commands.User
|
||||
{
|
||||
public abstract class UserCommand : Command
|
||||
{
|
||||
public override bool CanExecute(IPlayer player)
|
||||
{
|
||||
return player.GetSharedData("loggedIn", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace ReallifeGamemode.Server.Core.Menus
|
||||
return;
|
||||
}
|
||||
|
||||
var account = user.GetBankAccount(dbContext);
|
||||
var account = user.BankAccount;
|
||||
|
||||
if (account.Balance < 5000)
|
||||
{
|
||||
|
||||
@@ -24,5 +24,7 @@ namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string BankAccountName => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
public abstract class BusinessBase : IBankAccountOwner
|
||||
public abstract class BusinessBase : BankAccountHolder<BusinessBankAccount>, IBankAccountOwner
|
||||
{
|
||||
private TextLabel _informationLabel;
|
||||
private ColShape _colShape;
|
||||
@@ -23,6 +24,34 @@ namespace ReallifeGamemode.Server.Business
|
||||
|
||||
public abstract Vector3 Position { get; }
|
||||
|
||||
public override BusinessBankAccount BankAccount
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.BusinessBankAccounts.Where(b => b.BusinessId == this.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int? BankAccountId
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.BusinessBankAccounts.Where(b => b.BusinessId == this.Id).Select(b => b.Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string BankAccountName => Name;
|
||||
|
||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||
{
|
||||
if (databaseContext == null)
|
||||
@@ -110,8 +139,8 @@ namespace ReallifeGamemode.Server.Business
|
||||
{
|
||||
if (client.IsInVehicle || !client.IsLoggedIn()) return;
|
||||
|
||||
client.TriggerEvent("SERVER:Business_ShowMenuHelp");
|
||||
SendBusinessDataToPlayer(client);
|
||||
client.TriggerEvent("SERVER:Business_ShowMenuHelp");
|
||||
}
|
||||
|
||||
public void SendBusinessDataToPlayer(Player player)
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
using (var getFaction = new DatabaseContext())
|
||||
{
|
||||
Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);
|
||||
Faction receiverUser = getFaction.Factions.Include(u => u.BankAccount).FirstOrDefault(u => u.Name == receiver);
|
||||
|
||||
if (receiverUser == null)
|
||||
{
|
||||
@@ -108,7 +108,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY");
|
||||
BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY", getFaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2536,7 +2536,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
target.GetUser().GetBankAccount(dbContext).Balance = amount;
|
||||
target.GetUser().BankAccount.Balance = amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast das Geld von " + target.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
|
||||
@@ -2561,7 +2561,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
target.GetUser().GetBankAccount(dbContext).Balance += amount;
|
||||
target.GetUser(dbContext).BankAccount.Balance += amount;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
|
||||
|
||||
@@ -9,6 +9,7 @@ using ReallifeGamemode.Server.Util;
|
||||
using ReallifeGamemode.Server.Wanted;
|
||||
using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Login (Login.cs)
|
||||
@@ -27,6 +28,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
var user = dbContext.Users
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.BankAccount)
|
||||
.SingleOrDefault(b => b.Name == username);
|
||||
|
||||
if (user == null)
|
||||
@@ -54,17 +56,17 @@ namespace ReallifeGamemode.Server.Events
|
||||
player.SetData("duty", false);
|
||||
player.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney, 0);
|
||||
Gangwar.Gangwar.loadPlayer(player);
|
||||
if (player.GetUser().FactionLeader)
|
||||
if (user.FactionLeader)
|
||||
{
|
||||
player.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
|
||||
}
|
||||
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
|
||||
if (user.IsAdmin(AdminLevel.HEADADMIN))
|
||||
{
|
||||
player.SetData("editmode", false);
|
||||
player.SetData("quicksavemode", "none");
|
||||
}
|
||||
|
||||
var userBankAccount = user.GetBankAccount();
|
||||
var userBankAccount = user.BankAccount;
|
||||
userBankAccount.Balance = userBankAccount.Balance;
|
||||
|
||||
user.Wanteds = user.Wanteds;
|
||||
|
||||
@@ -18,29 +18,29 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
if (!dbContext.Users.Any(u => u.Name.ToLower() == username.ToLower().Trim()))
|
||||
if (dbContext.Users.Where(u => u.SocialClubName == player.SocialClubName).Count() >= 3)
|
||||
{
|
||||
var user = new Database.Entities.User
|
||||
player.TriggerEvent("SERVER:Login_Error", "Es sind schon 3 Konten mit dieser Socialclub-ID registriert.");
|
||||
}
|
||||
else if (!dbContext.Users.Any(u => u.Name.ToLower() == username.ToLower().Trim()))
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
Name = player.Name,
|
||||
SocialClubName = player.SocialClubName,
|
||||
Password = NAPI.Util.GetHashSha256(password),
|
||||
PositionX = Main.DEFAULT_SPAWN_POSITION.X,
|
||||
PositionY = Main.DEFAULT_SPAWN_POSITION.Y,
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z,
|
||||
BankAccount = new UserBankAccount
|
||||
{
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
}
|
||||
};
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
dbContext.SaveChanges();
|
||||
var userBankAccount = new Database.Entities.UserBankAccount
|
||||
{
|
||||
UserId = user.Id,
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
};
|
||||
|
||||
dbContext.UserBankAccounts.Add(userBankAccount);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.TriggerEvent("SERVER:Login_Success");
|
||||
player.SetData("isLoggedIn", true);
|
||||
@@ -54,10 +54,6 @@ namespace ReallifeGamemode.Server.Events
|
||||
player.Position = new Vector3(402.8664, -996.4108, -99.00027);
|
||||
//player.Position = new Vector3(user.PositionX, user.PositionY, user.PositionZ);
|
||||
}
|
||||
else if (dbContext.Users.Where(u => u.SocialClubName == player.SocialClubName).Count() >= 3)
|
||||
{
|
||||
player.TriggerEvent("SERVER:Login_Error", "Es sind schon 3 Konten mit dieser Socialclub-ID registriert.");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.TriggerEvent("SERVER:Login_Error", "Dieser Benutzername kann nicht registriert werden.");
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
.Include(u => u.FactionRank)
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.House)
|
||||
.Include(u => u.BankAccount)
|
||||
.Where(u => u.Name == client.Name)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
|
||||
public static (int, float, float) GetEconomyClass(Player client, int wage)
|
||||
{
|
||||
int bankAccount = client.GetUser().GetBankAccount().Balance;
|
||||
int bankAccount = client.GetUser().BankAccount.Balance;
|
||||
float financialHelp = -(float)Math.Pow(1.0005, -bankAccount) * -1000;
|
||||
float financialInterest = 1 - (float)Math.Pow(1.00006, -wage) * 1;
|
||||
if (financialInterest >= 0.7)
|
||||
@@ -182,7 +182,7 @@ namespace ReallifeGamemode.Server.Finance
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
client.GetUser().GetBankAccount(dbContext).Balance += paycheck.Amount;
|
||||
client.GetUser(dbContext).BankAccount.Balance += paycheck.Amount;
|
||||
client.GetUser(dbContext).Wage = 0;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ using ReallifeGamemode.Server.Common;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using ReallifeGamemode.Server.Job;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Services;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Main Class (Main.cs)
|
||||
@@ -105,6 +111,16 @@ namespace ReallifeGamemode.Server
|
||||
Jail.JailTimer();
|
||||
Economy.PaydayTimer();
|
||||
WeaponDealManager.WeaponDealTimer();
|
||||
|
||||
UserBankAccount.BalanceChanged += (account) =>
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var user = dbContext.Users.Where(u => u.BankAccountId == account.Id).Select(u => u.Name).FirstOrDefault();
|
||||
if (user == null) return;
|
||||
PlayerService.GetPlayerByNameOrId(user).TriggerEvent("updateMoney", account.Balance);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Event")]
|
||||
|
||||
@@ -89,18 +89,17 @@ namespace ReallifeGamemode.Server.Managers
|
||||
[RemoteEvent("CLIENT:ATM_MANAGER:ATM_ACTION")]
|
||||
public void AtmAction(Player client, int site, int inputField1, int inputField2)
|
||||
{
|
||||
var user = client.GetUser();
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var user = client.GetUser(dbContext);
|
||||
int nearATM = client.GetData<int>("nearATM");
|
||||
//SITE //0 Geld einzahlen //1 Geld auszahlen //2 Geld überweisen
|
||||
switch (site)
|
||||
{
|
||||
//GELD EINZAHLEN in1
|
||||
case 0:
|
||||
var checkPlayer = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
|
||||
if (checkPlayer.Handmoney < inputField1)
|
||||
if (user.Handmoney < inputField1)
|
||||
{
|
||||
//TODO im CEFBrowser anzeigen
|
||||
//client.TriggerEvent("SERVER:WORLD_INTERACTION:ATM_ERROR", 0, checkATM.Balance);
|
||||
@@ -108,22 +107,20 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
else
|
||||
{
|
||||
var updateHandMoneyIn = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
var updateBankMoneyIn = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
|
||||
var updateBankMoneyIn = user.BankAccount;
|
||||
var updateATMBalanceIn = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
|
||||
updateHandMoneyIn.Handmoney -= inputField1;
|
||||
user.Handmoney -= inputField1;
|
||||
updateBankMoneyIn.Balance += inputField1;
|
||||
updateATMBalanceIn.Balance += inputField1;
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", updateHandMoneyIn.Handmoney);
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
|
||||
}
|
||||
break;
|
||||
|
||||
//GELD AUSZAHLEN in1
|
||||
case 1:
|
||||
var checkATM = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
|
||||
var checkBankAccount = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
|
||||
|
||||
if (checkBankAccount.Balance < inputField1)
|
||||
if (user.BankAccount.Balance < inputField1)
|
||||
{
|
||||
client.SendNotification("~r~Nicht genügend Geld auf dem Bankkonto!"); //TODO Im Automaten anzeigen lassen
|
||||
}
|
||||
@@ -134,10 +131,9 @@ namespace ReallifeGamemode.Server.Managers
|
||||
else
|
||||
{
|
||||
var updateHandMoneyOut = dbContext.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
var updateBankMoneyOut = dbContext.UserBankAccounts.FirstOrDefault(b => b.UserId == user.Id);
|
||||
var updateATMBalanceOut = dbContext.ATMs.FirstOrDefault(a => a.Id == nearATM);
|
||||
updateHandMoneyOut.Handmoney += inputField1;
|
||||
updateBankMoneyOut.Balance -= inputField1;
|
||||
user.BankAccount.Balance -= inputField1;
|
||||
updateATMBalanceOut.Balance -= inputField1;
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", updateHandMoneyOut.Handmoney);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using ReallifeGamemode.Server.Util;
|
||||
using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Database.Entities.Logs;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||
@@ -54,14 +55,35 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
||||
{
|
||||
using (var transferMoney = new DatabaseContext())
|
||||
public static TransactionResult TransferMoney<TSender, TReceiver>(
|
||||
BankAccountHolder<TSender> sender,
|
||||
BankAccountHolder<TReceiver> receiver,
|
||||
int amount,
|
||||
string origin,
|
||||
DatabaseContext dbContext) where TSender : class, IBankAccount, new() where TReceiver : class, IBankAccount, new()
|
||||
{
|
||||
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||
|
||||
IBankAccount senderAccount = sender.GetBankAccount(transferMoney);
|
||||
IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney);
|
||||
IBankAccount senderAccount;
|
||||
IBankAccount receiverAccount;
|
||||
|
||||
if (sender is BankAccountHolder<BusinessBankAccount> businessSender)
|
||||
{
|
||||
senderAccount = dbContext.BusinessBankAccounts.Where(b => b.Id == businessSender.BankAccountId).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
senderAccount = sender.BankAccount;
|
||||
}
|
||||
|
||||
if (receiver is BankAccountHolder<BusinessBankAccount> businessReceiver)
|
||||
{
|
||||
receiverAccount = dbContext.BusinessBankAccounts.Where(b => b.Id == businessReceiver.BankAccountId).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
receiverAccount = receiver.BankAccount;
|
||||
}
|
||||
|
||||
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
|
||||
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||
@@ -70,9 +92,9 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
var transactionLog = new BankAccountTransactionHistory
|
||||
{
|
||||
Sender = sender.Name,
|
||||
Sender = sender.BankAccountName,
|
||||
SenderBalance = senderAccount.Balance,
|
||||
Receiver = receiver.Name,
|
||||
Receiver = receiver.BankAccountName,
|
||||
ReceiverBalance = receiverAccount.Balance,
|
||||
NewReceiverBalance = receiverAccount.Balance + amount,
|
||||
NewSenderBalance = senderAccount.Balance - amount,
|
||||
@@ -82,15 +104,14 @@ namespace ReallifeGamemode.Server.Managers
|
||||
};
|
||||
|
||||
// add log
|
||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||
dbContext.BankAccountTransactionLogs.Add(transactionLog);
|
||||
|
||||
senderAccount.Balance -= amount;
|
||||
receiverAccount.Balance += amount;
|
||||
|
||||
transferMoney.SaveChanges();
|
||||
dbContext.SaveChanges();
|
||||
|
||||
return TransactionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,9 @@ namespace ReallifeGamemode.Server.Managers
|
||||
[RemoteEvent("Business_DepositMoney")]
|
||||
public void BusinessDepositMoney(Player player, int amount)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
@@ -67,7 +69,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -82,15 +84,19 @@ namespace ReallifeGamemode.Server.Managers
|
||||
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();
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
@@ -98,7 +104,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -113,10 +119,12 @@ namespace ReallifeGamemode.Server.Managers
|
||||
else if (result == TransactionResult.SUCCESS)
|
||||
{
|
||||
playerBusiness.SendBusinessDataToPlayer(player);
|
||||
playerBusiness.Update();
|
||||
player.SendNotification("~g~Du hast erfolgreich ~s~" + amount.ToMoneyString() + " ~g~ überwiesen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
||||
public void CarDealerBusiness_PlayerEnterVehicle(Player player, Vehicle veh, int seat)
|
||||
@@ -139,6 +147,8 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
[RemoteEvent("VehShop_BuyVehicle")]
|
||||
public void CarDealerBusiness_BuyVehicle(Player player, string target)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
ServerVehicle sVeh = player.Vehicle?.GetServerVehicle();
|
||||
if (sVeh == null) return;
|
||||
@@ -146,7 +156,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
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");
|
||||
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());
|
||||
@@ -207,15 +217,12 @@ namespace ReallifeGamemode.Server.Managers
|
||||
Active = true,
|
||||
};
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
dbContext.ServerVehicles.Add(newVeh);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
newVeh.Spawn();
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Business_BuyBusiness")]
|
||||
public void BusinessEventBuyBusiness(Player player)
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
House house = GetNearHouse(player.Position, dbContext);
|
||||
|
||||
var userBank = user.GetBankAccount(dbContext);
|
||||
var userBank = user.BankAccount;
|
||||
|
||||
if (userBank.Balance < house.Price)
|
||||
{
|
||||
@@ -400,7 +400,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
|
||||
ChatService.SendMessage(player, "Du bekommst vom Hausverkauf ~g~" + backMoney.ToMoneyString() + "~s~ zurück.");
|
||||
|
||||
user.GetBankAccount(dbContext).Balance += backMoney;
|
||||
user.BankAccount.Balance += backMoney;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
|
||||
@@ -11,20 +12,18 @@ namespace ReallifeGamemode.Server.Util
|
||||
NAPI.Util.ConsoleOutput("Checking faction bank accounts...");
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (Faction faction in dbContext.Factions)
|
||||
foreach (Faction faction in dbContext.Factions.Include(f => f.BankAccount))
|
||||
{
|
||||
if (faction.GetBankAccount(dbContext) == null)
|
||||
if (faction.BankAccount == null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
|
||||
FactionBankAccount factionBankAccount = new FactionBankAccount()
|
||||
faction.BankAccount = new FactionBankAccount()
|
||||
{
|
||||
Balance = 0,
|
||||
Bic = "",
|
||||
Iban = "",
|
||||
FactionId = faction.Id,
|
||||
Active = true
|
||||
};
|
||||
dbContext.FactionBankAccounts.Add(factionBankAccount);
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
|
||||
Reference in New Issue
Block a user