diff --git a/ReallifeGamemode.DataService/Controllers/UserController.cs b/ReallifeGamemode.DataService/Controllers/UserController.cs index 4197d3a9..aead763e 100644 --- a/ReallifeGamemode.DataService/Controllers/UserController.cs +++ b/ReallifeGamemode.DataService/Controllers/UserController.cs @@ -32,7 +32,12 @@ namespace ReallifeGamemode.DataService.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult 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, diff --git a/ReallifeGamemode.Database/BankAccountHolder.cs b/ReallifeGamemode.Database/BankAccountHolder.cs new file mode 100644 index 00000000..091ae689 --- /dev/null +++ b/ReallifeGamemode.Database/BankAccountHolder.cs @@ -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 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; } + } +} diff --git a/ReallifeGamemode.Database/Entities/Faction.cs b/ReallifeGamemode.Database/Entities/Faction.cs index 253f1285..a0291a0f 100644 --- a/ReallifeGamemode.Database/Entities/Faction.cs +++ b/ReallifeGamemode.Database/Entities/Faction.cs @@ -11,7 +11,7 @@ using ReallifeGamemode.Database.Models; namespace ReallifeGamemode.Database.Entities { - public partial class Faction : IBankAccountOwner + public partial class Faction : BankAccountHolder { [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; } } diff --git a/ReallifeGamemode.Database/Entities/FactionBankAccount.cs b/ReallifeGamemode.Database/Entities/FactionBankAccount.cs index 064afb56..fa7d2842 100644 --- a/ReallifeGamemode.Database/Entities/FactionBankAccount.cs +++ b/ReallifeGamemode.Database/Entities/FactionBankAccount.cs @@ -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; } + } } diff --git a/ReallifeGamemode.Database/Entities/Group.cs b/ReallifeGamemode.Database/Entities/Group.cs index 1c49d4ab..d401a279 100644 --- a/ReallifeGamemode.Database/Entities/Group.cs +++ b/ReallifeGamemode.Database/Entities/Group.cs @@ -6,7 +6,7 @@ using ReallifeGamemode.Database.Models; namespace ReallifeGamemode.Database.Entities { - public partial class Group : IBankAccountOwner + public partial class Group : BankAccountHolder { [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; } } diff --git a/ReallifeGamemode.Database/Entities/GroupBankAccount.cs b/ReallifeGamemode.Database/Entities/GroupBankAccount.cs index 57effd5f..227528a6 100644 --- a/ReallifeGamemode.Database/Entities/GroupBankAccount.cs +++ b/ReallifeGamemode.Database/Entities/GroupBankAccount.cs @@ -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; } } } diff --git a/ReallifeGamemode.Database/Entities/User.cs b/ReallifeGamemode.Database/Entities/User.cs index 6a2ae0de..a0767d65 100644 --- a/ReallifeGamemode.Database/Entities/User.cs +++ b/ReallifeGamemode.Database/Entities/User.cs @@ -14,7 +14,7 @@ using ReallifeGamemode.Server.Types; namespace ReallifeGamemode.Database.Entities { - public partial class User : IBankAccountOwner + public partial class User : BankAccountHolder { [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; } } diff --git a/ReallifeGamemode.Database/Entities/UserBankAccount.cs b/ReallifeGamemode.Database/Entities/UserBankAccount.cs index c07c1a92..a34f5108 100644 --- a/ReallifeGamemode.Database/Entities/UserBankAccount.cs +++ b/ReallifeGamemode.Database/Entities/UserBankAccount.cs @@ -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; } } } diff --git a/ReallifeGamemode.Database/HeidiSQL_Export.txt b/ReallifeGamemode.Database/HeidiSQL_Export.txt new file mode 100644 index 00000000..e09b8e1b --- /dev/null +++ b/ReallifeGamemode.Database/HeidiSQL_Export.txt @@ -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| diff --git a/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.Designer.cs b/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.Designer.cs new file mode 100644 index 00000000..9d023a9d --- /dev/null +++ b/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.Designer.cs @@ -0,0 +1,1423 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ReallifeGamemode.Database.Models; + +namespace ReallifeGamemode.Database.Migrations +{ + [DbContext(typeof(DatabaseContext))] + [Migration("20200315113621_BankAccountRefactor")] + partial class BankAccountRefactor + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.1.11-servicing-32099") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ATM", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Balance"); + + b.Property("Faulty"); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.ToTable("ATMs"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Ban", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Applied"); + + b.Property("BannedBy"); + + b.Property("Reason"); + + b.Property("UntilDateTime"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Bans"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessBankAccount", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Balance"); + + b.Property("BusinessId"); + + b.HasKey("Id"); + + b.HasIndex("BusinessId") + .IsUnique(); + + b.ToTable("BusinessBankAccounts"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BusinessId"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.ToTable("BusinessData"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusRoute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.HasKey("Id"); + + b.ToTable("BusRoutes"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusRoutePoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BusRouteId"); + + b.Property("Description"); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.HasIndex("BusRouteId"); + + b.ToTable("BusRoutesPoints"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Ageing"); + + b.Property("AgeingOpacity"); + + b.Property("BeardColor"); + + b.Property("Blemishes"); + + b.Property("BlemishesOpacity"); + + b.Property("Blush"); + + b.Property("BlushColor"); + + b.Property("BlushOpacity"); + + b.Property("BrowDepth"); + + b.Property("BrowHeight"); + + b.Property("CheekDepth"); + + b.Property("CheekboneHeight"); + + b.Property("CheekboneWidth"); + + b.Property("ChestHair"); + + b.Property("ChestHairColor"); + + b.Property("ChestHairOpacity"); + + b.Property("ChinDepth"); + + b.Property("ChinHeight"); + + b.Property("ChinIndent"); + + b.Property("ChinWidth"); + + b.Property("Complexion"); + + b.Property("ComplexionOpacity"); + + b.Property("EyeColor"); + + b.Property("EyeSize"); + + b.Property("EyebrowColor"); + + b.Property("Eyebrows"); + + b.Property("EyebrowsOpacity"); + + b.Property("FacialHair"); + + b.Property("FacialHairOpacity"); + + b.Property("Father"); + + b.Property("Freckles"); + + b.Property("FrecklesOpacity"); + + b.Property("Gender"); + + b.Property("Hair"); + + b.Property("HairColor"); + + b.Property("HairHighlightColor"); + + b.Property("JawShape"); + + b.Property("JawWidth"); + + b.Property("LipThickness"); + + b.Property("Lipstick"); + + b.Property("LipstickColor"); + + b.Property("LipstickOpacity"); + + b.Property("Makeup"); + + b.Property("MakeupOpacity"); + + b.Property("Mother"); + + b.Property("NeckWidth"); + + b.Property("NoseBottomHeight"); + + b.Property("NoseBridgeDepth"); + + b.Property("NoseBroken"); + + b.Property("NoseTipHeight"); + + b.Property("NoseTipLength"); + + b.Property("NoseWidth"); + + b.Property("Similarity"); + + b.Property("SkinSimilarity"); + + b.Property("SunDamage"); + + b.Property("SunDamageOpacity"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.CharacterCloth", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClothId"); + + b.Property("Duty"); + + b.Property("SlotId"); + + b.Property("SlotType"); + + b.Property("Texture"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("CharacterClothes"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ClothCombination", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Gender"); + + b.Property("Top"); + + b.Property("Torso"); + + b.Property("Undershirt"); + + b.HasKey("Id"); + + b.ToTable("ClothCombinations"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Door", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Category"); + + b.Property("FactionId"); + + b.Property("Locked"); + + b.Property("Model"); + + b.Property("Name"); + + b.Property("Radius"); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.HasIndex("FactionId"); + + b.ToTable("Doors"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.DutyCloth", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClothId"); + + b.Property("FactionId"); + + b.Property("Gender"); + + b.Property("SlotId"); + + b.Property("SlotType"); + + b.HasKey("Id"); + + b.HasIndex("FactionId"); + + b.ToTable("DutyClothes"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Faction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BankAccountId"); + + b.Property("Name") + .HasMaxLength(32); + + b.Property("StateOwned"); + + b.Property("WeaponDealTime"); + + b.HasKey("Id"); + + b.HasIndex("BankAccountId"); + + b.ToTable("Factions"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionBankAccount", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Balance"); + + b.Property("Bic") + .HasMaxLength(12); + + b.Property("Iban") + .HasMaxLength(32); + + b.HasKey("Id"); + + b.ToTable("FactionBankAccounts"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionRank", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("FactionId"); + + b.Property("Order"); + + b.Property("RankName"); + + b.HasKey("Id"); + + b.HasIndex("FactionId"); + + b.ToTable("FactionRanks"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionWeapon", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Ammount"); + + b.Property("FactionId"); + + b.Property("Rank"); + + b.Property("SlotID"); + + b.Property("WeaponModel"); + + b.HasKey("Id"); + + b.HasIndex("FactionId"); + + b.ToTable("FactionWeapons"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.GotoPoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Description") + .HasMaxLength(32); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.ToTable("GotoPoints"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BankAccountId"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("BankAccountId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.GroupBankAccount", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Balance"); + + b.HasKey("Id"); + + b.ToTable("GroupBankAccounts"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.House", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CanRentIn"); + + b.Property("OwnerId"); + + b.Property("Price"); + + b.Property("RentalFee"); + + b.Property("Type"); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Houses"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.HouseRental", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HouseId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("HouseId"); + + b.HasIndex("UserId"); + + b.ToTable("HouseRentals"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Interior", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EnterPositionStr") + .HasColumnName("EnterPosition"); + + b.Property("ExitPositionStr") + .HasColumnName("ExitPosition"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("Interiors"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Heading"); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.ToTable("Locations"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.BankAccountTransactionHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Fee"); + + b.Property("MoneySent"); + + b.Property("NewReceiverBalance"); + + b.Property("NewSenderBalance"); + + b.Property("Origin") + .HasMaxLength(32); + + b.Property("Receiver") + .HasMaxLength(32); + + b.Property("ReceiverBalance"); + + b.Property("Sender") + .HasMaxLength(32); + + b.Property("SenderBalance"); + + b.Property("Timestamp") + .ValueGeneratedOnAdd(); + + b.HasKey("Id"); + + b.ToTable("BankAccountTransactionLogs"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CauseOfDeath") + .HasMaxLength(64); + + b.Property("KillerHeading"); + + b.Property("KillerId"); + + b.Property("KillerPositionX"); + + b.Property("KillerPositionY"); + + b.Property("KillerPositionZ"); + + b.Property("Timestamp") + .ValueGeneratedOnAdd(); + + b.Property("VictimHeading"); + + b.Property("VictimId"); + + b.Property("VictimPositionX"); + + b.Property("VictimPositionY"); + + b.Property("VictimPositionZ"); + + b.HasKey("Id"); + + b.HasIndex("KillerId"); + + b.HasIndex("VictimId"); + + b.ToTable("DeathLogs"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.News", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Caption"); + + b.Property("Content"); + + b.Property("Timestamp"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("News"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedBlip", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Alpha"); + + b.Property("Color"); + + b.Property("Dimension"); + + b.Property("DrawDistance"); + + b.Property("Name"); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("Rotation"); + + b.Property("Scale"); + + b.Property("ShortRange"); + + b.Property("Sprite"); + + b.HasKey("Id"); + + b.ToTable("Blips"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedMarker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("ColorA"); + + b.Property("ColorB"); + + b.Property("ColorG"); + + b.Property("ColorR"); + + b.Property("Dimension"); + + b.Property("DirectionX"); + + b.Property("DirectionY"); + + b.Property("DirectionZ"); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("RotationX"); + + b.Property("RotationY"); + + b.Property("RotationZ"); + + b.Property("Scale"); + + b.Property("Type"); + + b.Property("Visible"); + + b.HasKey("Id"); + + b.ToTable("Markers"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedPed", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Dimension"); + + b.Property("HashModel"); + + b.Property("Heading"); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.HasKey("Id"); + + b.ToTable("Peds"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedPickup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Dimension"); + + b.Property("PositionX") + .HasMaxLength(128); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("RespawnTime"); + + b.Property("RotationX"); + + b.Property("RotationY"); + + b.Property("RotationZ"); + + b.Property("Vehicle"); + + b.HasKey("Id"); + + b.ToTable("Pickups"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedTextLabel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("ColorA"); + + b.Property("ColorB"); + + b.Property("ColorG"); + + b.Property("ColorR"); + + b.Property("Dimension"); + + b.Property("DrawDistance"); + + b.Property("Font"); + + b.Property("LOS"); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("Text") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("TextLabels"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ServerVehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("Discriminator") + .IsRequired(); + + b.Property("DistanceDriven"); + + b.Property("Heading"); + + b.Property("Livery"); + + b.Property("Locked"); + + b.Property("Model"); + + b.Property("NumberPlate") + .HasMaxLength(8); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("PrimaryColor"); + + b.Property("SecondaryColor"); + + b.Property("TankAmount"); + + b.HasKey("Id"); + + b.ToTable("ServerVehicles"); + + b.HasDiscriminator("Discriminator").HasValue("ServerVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ShopClothe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Category"); + + b.Property("ClotheId"); + + b.Property("ComponentId"); + + b.Property("Gender"); + + b.Property("Price"); + + b.Property("TypeId"); + + b.HasKey("Id"); + + b.ToTable("ShopClothes"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ShopItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("ItemId"); + + b.Property("Price"); + + b.Property("ShopId"); + + b.HasKey("Id"); + + b.ToTable("ShopItems"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.TuningGarage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("X"); + + b.Property("Y"); + + b.Property("Z"); + + b.HasKey("Id"); + + b.ToTable("TuningGarages"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Turfs", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Color"); + + b.Property("FactionId"); + + b.Property("Name"); + + b.Property("Owner"); + + b.Property("Range"); + + b.Property("Rotation"); + + b.Property("Vector"); + + b.Property("X"); + + b.Property("Y"); + + b.HasKey("Id"); + + b.ToTable("Turfs"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AdminLevel"); + + b.Property("BanId"); + + b.Property("BankAccountId"); + + b.Property("BusinessId"); + + b.Property("CharacterId"); + + b.Property("Dead"); + + b.Property("DriverLicenseBike"); + + b.Property("DriverLicenseVehicle"); + + b.Property("Email") + .HasMaxLength(64); + + b.Property("FactionId"); + + b.Property("FactionLeader"); + + b.Property("FactionRankId"); + + b.Property("FlyingLicensePlane"); + + b.Property("GroupId"); + + b.Property("GroupRank"); + + b.Property("Handmoney"); + + b.Property("HouseId"); + + b.Property("JailTime"); + + b.Property("JobId"); + + b.Property("LogUserId"); + + b.Property("Name") + .HasMaxLength(32); + + b.Property("Password") + .HasMaxLength(64); + + b.Property("PaydayTimer"); + + b.Property("PositionX"); + + b.Property("PositionY"); + + b.Property("PositionZ"); + + b.Property("RegistrationDate") + .ValueGeneratedOnAdd(); + + b.Property("SocialClubName") + .HasMaxLength(32); + + b.Property("Wage"); + + b.Property("Wanteds"); + + b.Property("WeaponLicense"); + + b.HasKey("Id"); + + b.HasIndex("BanId"); + + b.HasIndex("BankAccountId"); + + b.HasIndex("BusinessId") + .IsUnique(); + + b.HasIndex("CharacterId"); + + b.HasIndex("FactionId"); + + b.HasIndex("FactionRankId"); + + b.HasIndex("GroupId"); + + b.HasIndex("HouseId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserBankAccount", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Active"); + + b.Property("Balance"); + + b.Property("Bic") + .HasMaxLength(12); + + b.Property("Iban") + .HasMaxLength(32); + + b.HasKey("Id"); + + b.ToTable("UserBankAccounts"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("ItemId"); + + b.Property("Slot"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserItems"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.VehicleItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("ItemId"); + + b.Property("Slot"); + + b.Property("VehicleId"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleItems"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.VehicleMod", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ModId"); + + b.Property("ServerVehicleId"); + + b.Property("Slot"); + + b.HasKey("Id"); + + b.HasIndex("ServerVehicleId", "Slot") + .IsUnique(); + + b.ToTable("VehicleMods"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Whitelist", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("SocialClubName"); + + b.HasKey("Id"); + + b.ToTable("WhitelistEntries"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("FactionId"); + + b.HasIndex("FactionId"); + + b.ToTable("FactionVehicles"); + + b.HasDiscriminator().HasValue("FactionVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.GroupVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("GroupId"); + + b.HasIndex("GroupId"); + + b.ToTable("GroupVehicle"); + + b.HasDiscriminator().HasValue("GroupVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.JobVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("JobId"); + + b.ToTable("JobVehicle"); + + b.HasDiscriminator().HasValue("JobVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Saves.SavedVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + + b.ToTable("SavedVehicle"); + + b.HasDiscriminator().HasValue("SavedVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.SchoolVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("SchoolId"); + + b.ToTable("SchoolVehicle"); + + b.HasDiscriminator().HasValue("SchoolVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.ShopVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("BusinessId"); + + b.Property("Price"); + + b.ToTable("ShopVehicles"); + + b.HasDiscriminator().HasValue("ShopVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserVehicle", b => + { + b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle"); + + b.Property("UserId"); + + b.HasIndex("UserId"); + + b.ToTable("UserVehicles"); + + b.HasDiscriminator().HasValue("UserVehicle"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Ban", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusRoutePoint", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.BusRoute", "BusRoute") + .WithMany("RoutePoints") + .HasForeignKey("BusRouteId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Character", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.CharacterCloth", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Door", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.DutyCloth", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Faction", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.FactionBankAccount", "BankAccount") + .WithMany() + .HasForeignKey("BankAccountId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionRank", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionWeapon", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Group", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.GroupBankAccount", "BankAccount") + .WithMany() + .HasForeignKey("BankAccountId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.House", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.HouseRental", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.House", "House") + .WithMany() + .HasForeignKey("HouseId"); + + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "Killer") + .WithMany() + .HasForeignKey("KillerId"); + + b.HasOne("ReallifeGamemode.Database.Entities.User", "Victim") + .WithMany() + .HasForeignKey("VictimId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.News", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.User", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Ban", "Ban") + .WithMany() + .HasForeignKey("BanId"); + + b.HasOne("ReallifeGamemode.Database.Entities.UserBankAccount", "BankAccount") + .WithMany() + .HasForeignKey("BankAccountId"); + + b.HasOne("ReallifeGamemode.Database.Entities.Character", "Character") + .WithMany() + .HasForeignKey("CharacterId"); + + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId"); + + b.HasOne("ReallifeGamemode.Database.Entities.FactionRank", "FactionRank") + .WithMany() + .HasForeignKey("FactionRankId"); + + b.HasOne("ReallifeGamemode.Database.Entities.Group", "Group") + .WithMany() + .HasForeignKey("GroupId"); + + b.HasOne("ReallifeGamemode.Database.Entities.House", "House") + .WithMany() + .HasForeignKey("HouseId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserItem", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.VehicleItem", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.ServerVehicle", "Vehicle") + .WithMany() + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.VehicleMod", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.ServerVehicle", "Vehicle") + .WithMany() + .HasForeignKey("ServerVehicleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.FactionVehicle", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Faction", "Faction") + .WithMany() + .HasForeignKey("FactionId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.GroupVehicle", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.Group", "Group") + .WithMany() + .HasForeignKey("GroupId"); + }); + + modelBuilder.Entity("ReallifeGamemode.Database.Entities.UserVehicle", b => + { + b.HasOne("ReallifeGamemode.Database.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.cs b/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.cs new file mode 100644 index 00000000..3be60acd --- /dev/null +++ b/ReallifeGamemode.Database/Migrations/20200315113621_BankAccountRefactor.cs @@ -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( + name: "BankAccountId", + table: "Users", + nullable: true); + + migrationBuilder.AddColumn( + name: "BankAccountId", + table: "Groups", + nullable: true); + + migrationBuilder.AddColumn( + 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( + name: "UserId", + table: "UserBankAccounts", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "GroupId", + table: "GroupBankAccounts", + nullable: true); + + migrationBuilder.AddColumn( + 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); + } + } +} diff --git a/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs b/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs index 4159255c..d7c3e765 100644 --- a/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs +++ b/ReallifeGamemode.Database/Migrations/DatabaseContextModelSnapshot.cs @@ -351,6 +351,8 @@ namespace ReallifeGamemode.Database.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("BankAccountId"); + b.Property("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("Bic") .HasMaxLength(12); - b.Property("FactionId"); - b.Property("Iban") .HasMaxLength(32); b.HasKey("Id"); - b.HasIndex("FactionId"); - b.ToTable("FactionBankAccounts"); }); @@ -453,10 +453,14 @@ namespace ReallifeGamemode.Database.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("BankAccountId"); + b.Property("Name"); b.HasKey("Id"); + b.HasIndex("BankAccountId"); + b.ToTable("Groups"); }); @@ -467,12 +471,8 @@ namespace ReallifeGamemode.Database.Migrations b.Property("Balance"); - b.Property("GroupId"); - b.HasKey("Id"); - b.HasIndex("GroupId"); - b.ToTable("GroupBankAccounts"); }); @@ -967,6 +967,8 @@ namespace ReallifeGamemode.Database.Migrations b.Property("BanId"); + b.Property("BankAccountId"); + b.Property("BusinessId"); b.Property("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("Iban") .HasMaxLength(32); - b.Property("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") diff --git a/ReallifeGamemode.Server.Core.Extensions/PlayerExtensions.cs b/ReallifeGamemode.Server.Core.Extensions/PlayerExtensions.cs index a3b8d524..60e094b5 100644 --- a/ReallifeGamemode.Server.Core.Extensions/PlayerExtensions.cs +++ b/ReallifeGamemode.Server.Core.Extensions/PlayerExtensions.cs @@ -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; + } } } diff --git a/ReallifeGamemode.Server.Core/Commands/Admin/AdminCommand.cs b/ReallifeGamemode.Server.Core/Commands/Admin/AdminCommand.cs index 23eb9c9c..de8a0113 100644 --- a/ReallifeGamemode.Server.Core/Commands/Admin/AdminCommand.cs +++ b/ReallifeGamemode.Server.Core/Commands/Admin/AdminCommand.cs @@ -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()); } } } diff --git a/ReallifeGamemode.Server.Core/Commands/Command.cs b/ReallifeGamemode.Server.Core/Commands/Command.cs index 3e75ed92..546f09f9 100644 --- a/ReallifeGamemode.Server.Core/Commands/Command.cs +++ b/ReallifeGamemode.Server.Core/Commands/Command.cs @@ -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(); } } diff --git a/ReallifeGamemode.Server.Core/Commands/User/UserCommand.cs b/ReallifeGamemode.Server.Core/Commands/User/UserCommand.cs new file mode 100644 index 00000000..ef928fc4 --- /dev/null +++ b/ReallifeGamemode.Server.Core/Commands/User/UserCommand.cs @@ -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); + } + } +} diff --git a/ReallifeGamemode.Server.Core/Menus/PoliceDepartment.cs b/ReallifeGamemode.Server.Core/Menus/PoliceDepartment.cs index 0dd8b9e8..88cf63dd 100644 --- a/ReallifeGamemode.Server.Core/Menus/PoliceDepartment.cs +++ b/ReallifeGamemode.Server.Core/Menus/PoliceDepartment.cs @@ -36,7 +36,7 @@ namespace ReallifeGamemode.Server.Core.Menus return; } - var account = user.GetBankAccount(dbContext); + var account = user.BankAccount; if (account.Balance < 5000) { diff --git a/ReallifeGamemode.Server/Business/AirplaneDealerBusiness.cs b/ReallifeGamemode.Server/Business/AirplaneDealerBusiness.cs index 42fa8d8b..c19a02fc 100644 --- a/ReallifeGamemode.Server/Business/AirplaneDealerBusiness.cs +++ b/ReallifeGamemode.Server/Business/AirplaneDealerBusiness.cs @@ -24,5 +24,7 @@ namespace ReallifeGamemode.Server.Business { } + + public override string BankAccountName => Name; } } diff --git a/ReallifeGamemode.Server/Business/BusinessBase.cs b/ReallifeGamemode.Server/Business/BusinessBase.cs index 7febf83d..48970ddd 100644 --- a/ReallifeGamemode.Server/Business/BusinessBase.cs +++ b/ReallifeGamemode.Server/Business/BusinessBase.cs @@ -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, 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) diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 8c134ee7..0697b99a 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -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."); diff --git a/ReallifeGamemode.Server/Events/Login.cs b/ReallifeGamemode.Server/Events/Login.cs index e5ce0d93..19f9e61c 100644 --- a/ReallifeGamemode.Server/Events/Login.cs +++ b/ReallifeGamemode.Server/Events/Login.cs @@ -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; @@ -110,7 +112,7 @@ namespace ReallifeGamemode.Server.Events NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension); player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension"); player.Position = new Vector3(402.8664, -996.4108, -99.00027); - player.Rotation = new Vector3(0,0,180); + player.Rotation = new Vector3(0, 0, 180); player.TriggerEvent("toggleCreator"); } else diff --git a/ReallifeGamemode.Server/Events/Register.cs b/ReallifeGamemode.Server/Events/Register.cs index 6a5acae9..d696c087 100644 --- a/ReallifeGamemode.Server/Events/Register.cs +++ b/ReallifeGamemode.Server/Events/Register.cs @@ -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."); diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index 553085d9..095ac260 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -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(); } diff --git a/ReallifeGamemode.Server/Finance/Economy.cs b/ReallifeGamemode.Server/Finance/Economy.cs index 95b6ba27..e0265646 100644 --- a/ReallifeGamemode.Server/Finance/Economy.cs +++ b/ReallifeGamemode.Server/Finance/Economy.cs @@ -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(); } diff --git a/ReallifeGamemode.Server/Main.cs b/ReallifeGamemode.Server/Main.cs index f26c6e99..051044d5 100644 --- a/ReallifeGamemode.Server/Main.cs +++ b/ReallifeGamemode.Server/Main.cs @@ -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")] diff --git a/ReallifeGamemode.Server/Managers/ATMManager.cs b/ReallifeGamemode.Server/Managers/ATMManager.cs index 96cdc027..84c77b17 100644 --- a/ReallifeGamemode.Server/Managers/ATMManager.cs +++ b/ReallifeGamemode.Server/Managers/ATMManager.cs @@ -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("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); } diff --git a/ReallifeGamemode.Server/Managers/BankManager.cs b/ReallifeGamemode.Server/Managers/BankManager.cs index 3a48b02a..81c37466 100644 --- a/ReallifeGamemode.Server/Managers/BankManager.cs +++ b/ReallifeGamemode.Server/Managers/BankManager.cs @@ -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,43 +55,63 @@ namespace ReallifeGamemode.Server.Managers } } - public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin) + public static TransactionResult TransferMoney( + BankAccountHolder sender, + BankAccountHolder receiver, + int amount, + string origin, + DatabaseContext dbContext) where TSender : class, IBankAccount, new() where TReceiver : class, IBankAccount, new() { - using (var transferMoney = new DatabaseContext()) + if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT; + + IBankAccount senderAccount; + IBankAccount receiverAccount; + + if (sender is BankAccountHolder businessSender) { - if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT; - - IBankAccount senderAccount = sender.GetBankAccount(transferMoney); - IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney); - - if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT; - if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT; - - if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY; - - var transactionLog = new BankAccountTransactionHistory - { - Sender = sender.Name, - SenderBalance = senderAccount.Balance, - Receiver = receiver.Name, - ReceiverBalance = receiverAccount.Balance, - NewReceiverBalance = receiverAccount.Balance + amount, - NewSenderBalance = senderAccount.Balance - amount, - MoneySent = amount, - Fee = 0, - Origin = origin - }; - - // add log - transferMoney.BankAccountTransactionLogs.Add(transactionLog); - - senderAccount.Balance -= amount; - receiverAccount.Balance += amount; - - transferMoney.SaveChanges(); - - return TransactionResult.SUCCESS; + senderAccount = dbContext.BusinessBankAccounts.Where(b => b.Id == businessSender.BankAccountId).First(); } + else + { + senderAccount = sender.BankAccount; + } + + if (receiver is BankAccountHolder 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; + + if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY; + + var transactionLog = new BankAccountTransactionHistory + { + Sender = sender.BankAccountName, + SenderBalance = senderAccount.Balance, + Receiver = receiver.BankAccountName, + ReceiverBalance = receiverAccount.Balance, + NewReceiverBalance = receiverAccount.Balance + amount, + NewSenderBalance = senderAccount.Balance - amount, + MoneySent = amount, + Fee = 0, + Origin = origin + }; + + // add log + dbContext.BankAccountTransactionLogs.Add(transactionLog); + + senderAccount.Balance -= amount; + receiverAccount.Balance += amount; + + dbContext.SaveChanges(); + + return TransactionResult.SUCCESS; } } } diff --git a/ReallifeGamemode.Server/Managers/BusinessManager.cs b/ReallifeGamemode.Server/Managers/BusinessManager.cs index 378cc3d2..da72bb91 100644 --- a/ReallifeGamemode.Server/Managers/BusinessManager.cs +++ b/ReallifeGamemode.Server/Managers/BusinessManager.cs @@ -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) { diff --git a/ReallifeGamemode.Server/Managers/HouseManager.cs b/ReallifeGamemode.Server/Managers/HouseManager.cs index 6f0c860b..df82c8e4 100644 --- a/ReallifeGamemode.Server/Managers/HouseManager.cs +++ b/ReallifeGamemode.Server/Managers/HouseManager.cs @@ -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(); diff --git a/ReallifeGamemode.Server/Util/FactionHelper.cs b/ReallifeGamemode.Server/Util/FactionHelper.cs index 1d8571af..1cc33969 100644 --- a/ReallifeGamemode.Server/Util/FactionHelper.cs +++ b/ReallifeGamemode.Server/Util/FactionHelper.cs @@ -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();