start group system

This commit is contained in:
Lennart Kampshoff
2019-05-05 17:07:29 +02:00
parent e1dd54b7c5
commit a34c03eae9
9 changed files with 1382 additions and 3 deletions

View File

@@ -20,4 +20,5 @@
"watch": "webpack --watch --config webpack.config.development.js",
"build:server": "webpack --config webpack.config.build.js"
}
, "-vs-binding":{"ProjectOpened":["watch"]}
}

View File

@@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore;
using ReallifeGamemode.Server.Models;
using ReallifeGamemode.Server.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
namespace ReallifeGamemode.Server.Entities
{
public class Group : IBankAccountOwner
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
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;
}
}
}

View File

@@ -0,0 +1,20 @@
using ReallifeGamemode.Server.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace ReallifeGamemode.Server.Entities
{
public class GroupBankAccount : IBankAccount
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public Group Group { get; set; }
public int Balance { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ReallifeGamemode.Server.Entities
{
public class GroupVehicle : ServerVehicle
{
public Group Group { get; set; }
public override string ToString()
{
return "Gruppen Fahrzeug | Gruppe: " + Group.Name;
}
}
}

View File

@@ -58,6 +58,8 @@ namespace ReallifeGamemode.Server.Entities
public int? FactionRankId { get; set; }
public FactionRank FactionRank { get; set; }
public Group Group { get; set; }
public FactionRank GetFactionRank()
{
using (var dbContext = new DatabaseContext())

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ReallifeGamemode.Migrations
{
public partial class Groups : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "GroupId",
table: "Users",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "GroupId",
table: "ServerVehicles",
nullable: true);
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "GroupBankAccounts",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
GroupId = table.Column<int>(nullable: true),
Balance = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupBankAccounts", x => x.Id);
table.ForeignKey(
name: "FK_GroupBankAccounts_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Users_GroupId",
table: "Users",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_ServerVehicles_GroupId",
table: "ServerVehicles",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_GroupBankAccounts_GroupId",
table: "GroupBankAccounts",
column: "GroupId");
migrationBuilder.AddForeignKey(
name: "FK_ServerVehicles_Groups_GroupId",
table: "ServerVehicles",
column: "GroupId",
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Users_Groups_GroupId",
table: "Users",
column: "GroupId",
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ServerVehicles_Groups_GroupId",
table: "ServerVehicles");
migrationBuilder.DropForeignKey(
name: "FK_Users_Groups_GroupId",
table: "Users");
migrationBuilder.DropTable(
name: "GroupBankAccounts");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropIndex(
name: "IX_Users_GroupId",
table: "Users");
migrationBuilder.DropIndex(
name: "IX_ServerVehicles_GroupId",
table: "ServerVehicles");
migrationBuilder.DropColumn(
name: "GroupId",
table: "Users");
migrationBuilder.DropColumn(
name: "GroupId",
table: "ServerVehicles");
}
}
}

View File

@@ -374,6 +374,34 @@ namespace ReallifeGamemode.Migrations
b.ToTable("GotoPoints");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Group", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GroupBankAccount", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Balance");
b.Property<int?>("GroupId");
b.HasKey("Id");
b.HasIndex("GroupId");
b.ToTable("GroupBankAccounts");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Interior", b =>
{
b.Property<int>("Id")
@@ -744,6 +772,8 @@ namespace ReallifeGamemode.Migrations
b.Property<int?>("FactionRankId");
b.Property<int?>("GroupId");
b.Property<int>("Handmoney");
b.Property<int>("LogUserId");
@@ -779,6 +809,8 @@ namespace ReallifeGamemode.Migrations
b.HasIndex("FactionRankId");
b.HasIndex("GroupId");
b.ToTable("Users");
});
@@ -870,6 +902,17 @@ namespace ReallifeGamemode.Migrations
b.HasDiscriminator().HasValue("FactionVehicle");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GroupVehicle", b =>
{
b.HasBaseType("ReallifeGamemode.Server.Entities.ServerVehicle");
b.Property<int?>("GroupId");
b.HasIndex("GroupId");
b.HasDiscriminator().HasValue("GroupVehicle");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Saves.SavedVehicle", b =>
{
b.HasBaseType("ReallifeGamemode.Server.Entities.ServerVehicle");
@@ -960,6 +1003,13 @@ namespace ReallifeGamemode.Migrations
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GroupBankAccount", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.Group", "Group")
.WithMany()
.HasForeignKey("GroupId");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Logs.Death", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.User", "Killer")
@@ -996,6 +1046,10 @@ namespace ReallifeGamemode.Migrations
b.HasOne("ReallifeGamemode.Server.Entities.FactionRank", "FactionRank")
.WithMany()
.HasForeignKey("FactionRankId");
b.HasOne("ReallifeGamemode.Server.Entities.Group", "Group")
.WithMany()
.HasForeignKey("GroupId");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.UserBankAccount", b =>
@@ -1029,6 +1083,13 @@ namespace ReallifeGamemode.Migrations
.HasForeignKey("FactionId");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.GroupVehicle", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.Group", "Group")
.WithMany()
.HasForeignKey("GroupId");
});
modelBuilder.Entity("ReallifeGamemode.Server.Entities.UserVehicle", b =>
{
b.HasOne("ReallifeGamemode.Server.Entities.User", "User")

View File

@@ -94,5 +94,10 @@ namespace ReallifeGamemode.Server.Models
// Tuning Garages
public DbSet<Entities.TuningGarage> TuningGarages { get; set; }
// Gruppen
public DbSet<Entities.Group> Groups { get; set; }
public DbSet<Entities.GroupBankAccount> GroupBankAccounts { get; set; }
public DbSet<Entities.GroupVehicle> GroupVehicles { get; set; }
}
}