fix house
This commit is contained in:
39
ReallifeGamemode.Server/Entities/BusRoute.cs
Normal file
39
ReallifeGamemode.Server/Entities/BusRoute.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Entities
|
||||
{
|
||||
public class BusRoute
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<BusRoutePoint> RoutePoints { get; set; }
|
||||
}
|
||||
|
||||
public class BusRoutePoint
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public float X { get; set; }
|
||||
|
||||
public float Y { get; set; }
|
||||
|
||||
public float Z { get; set; }
|
||||
|
||||
[ForeignKey("BusRouteId")]
|
||||
public int? BusRouteId { get; set; }
|
||||
|
||||
public BusRoute BusRoute { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -26,18 +26,11 @@ namespace ReallifeGamemode.Server.Entities
|
||||
[NotMapped]
|
||||
public Vector3 Position => new Vector3(X, Y, Z);
|
||||
|
||||
[ForeignKey("User")]
|
||||
public int? UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
[ForeignKey("Owner")]
|
||||
public int? OwnerId { get; set; }
|
||||
public User Owner { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Client Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
return dbContext.Users.Where(u => u.Id == this.UserId).FirstOrDefault()?.Client;
|
||||
}
|
||||
}
|
||||
public Client User => Owner?.Client;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Houses.Where(h => h.Id == house.Id).Include(h => h.User).FirstOrDefault();
|
||||
return dbContext.Houses.Where(h => h.Id == house.Id).Include(h => h.Owner).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (House house in dbContext.Houses.Include(h => h.User))
|
||||
foreach (House house in dbContext.Houses.Include(h => h.Owner))
|
||||
{
|
||||
LoadHouse(house, false);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach(House house in await dbContext.Houses.Include(h => h.User).ToListAsync())
|
||||
foreach(House house in await dbContext.Houses.Include(h => h.Owner).ToListAsync())
|
||||
{
|
||||
RemoveHouse(house);
|
||||
LoadHouse(house, false);
|
||||
|
||||
1202
ReallifeGamemode.Server/Migrations/20190707184050_BusRoutes.Designer.cs
generated
Normal file
1202
ReallifeGamemode.Server/Migrations/20190707184050_BusRoutes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Migrations
|
||||
{
|
||||
public partial class BusRoutes : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BusRoutes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Description = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BusRoutes", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BusRoutesPoints",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Description = table.Column<string>(nullable: true),
|
||||
X = table.Column<float>(nullable: false),
|
||||
Y = table.Column<float>(nullable: false),
|
||||
Z = table.Column<float>(nullable: false),
|
||||
BusRouteId = table.Column<int>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BusRoutesPoints", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BusRoutesPoints_BusRoutes_BusRouteId",
|
||||
column: x => x.BusRouteId,
|
||||
principalTable: "BusRoutes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BusRoutesPoints_BusRouteId",
|
||||
table: "BusRoutesPoints",
|
||||
column: "BusRouteId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BusRoutesPoints");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BusRoutes");
|
||||
}
|
||||
}
|
||||
}
|
||||
1202
ReallifeGamemode.Server/Migrations/20190708161922_UserHouseReferenceFix.Designer.cs
generated
Normal file
1202
ReallifeGamemode.Server/Migrations/20190708161922_UserHouseReferenceFix.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Migrations
|
||||
{
|
||||
public partial class UserHouseReferenceFix : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "OwnerId",
|
||||
table: "Houses",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Houses_OwnerId",
|
||||
table: "Houses",
|
||||
column: "OwnerId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Houses_Users_OwnerId",
|
||||
table: "Houses",
|
||||
column: "OwnerId",
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Houses_Users_OwnerId",
|
||||
table: "Houses");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Houses_OwnerId",
|
||||
table: "Houses");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "OwnerId",
|
||||
table: "Houses");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,40 @@ namespace ReallifeGamemode.Migrations
|
||||
b.ToTable("Bans");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.BusRoute", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BusRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.BusRoutePoint", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("BusRouteId");
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<float>("X");
|
||||
|
||||
b.Property<float>("Y");
|
||||
|
||||
b.Property<float>("Z");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BusRouteId");
|
||||
|
||||
b.ToTable("BusRoutesPoints");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.BusinessBankAccount", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -409,12 +443,12 @@ namespace ReallifeGamemode.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("OwnerId");
|
||||
|
||||
b.Property<int>("Price");
|
||||
|
||||
b.Property<string>("Type");
|
||||
|
||||
b.Property<int?>("UserId");
|
||||
|
||||
b.Property<float>("X");
|
||||
|
||||
b.Property<float>("Y");
|
||||
@@ -423,7 +457,7 @@ namespace ReallifeGamemode.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
b.HasIndex("OwnerId");
|
||||
|
||||
b.ToTable("Houses");
|
||||
});
|
||||
@@ -828,6 +862,8 @@ namespace ReallifeGamemode.Migrations
|
||||
b.Property<string>("SocialClubName")
|
||||
.HasMaxLength(32);
|
||||
|
||||
b.Property<int>("Wage");
|
||||
|
||||
b.Property<int>("Wanteds");
|
||||
|
||||
b.HasKey("Id");
|
||||
@@ -999,6 +1035,13 @@ namespace ReallifeGamemode.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.BusRoutePoint", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.BusRoute", "BusRoute")
|
||||
.WithMany("RoutePoints")
|
||||
.HasForeignKey("BusRouteId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Character", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.User", "User")
|
||||
@@ -1055,9 +1098,9 @@ namespace ReallifeGamemode.Migrations
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.House", b =>
|
||||
{
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.User", "User")
|
||||
b.HasOne("ReallifeGamemode.Server.Entities.User", "Owner")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
.HasForeignKey("OwnerId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Logs.Death", b =>
|
||||
|
||||
@@ -105,5 +105,9 @@ namespace ReallifeGamemode.Server.Models
|
||||
|
||||
// Houses
|
||||
public DbSet<Entities.House> Houses { get; set; }
|
||||
|
||||
// Bus Routes
|
||||
public DbSet<Entities.BusRoute> BusRoutes { get; set; }
|
||||
public DbSet<Entities.BusRoutePoint> BusRoutesPoints { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user