Added constructors and base classses to Models

This commit is contained in:
batgo6o
2021-03-14 10:17:13 +02:00
parent b45909ab63
commit 8578b62989
16 changed files with 376 additions and 236 deletions

View File

@@ -10,7 +10,7 @@ using Models;
namespace Data.Migrations
{
[DbContext(typeof(LuminousContext))]
[Migration("20210310234527_IntialMigration")]
[Migration("20210314081427_IntialMigration")]
partial class IntialMigration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -28,19 +28,17 @@ namespace Data.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Deal");
@@ -54,10 +52,19 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("RoleId");
b.ToTable("Permission");
});
@@ -71,14 +78,28 @@ namespace Data.Migrations
b.Property<double>("AmountInStock")
.HasColumnType("float");
b.Property<int?>("DealId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("StockId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DealId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("StockId");
b.ToTable("Product");
});
@@ -90,14 +111,13 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("PermissionId")
.HasColumnType("int");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("PermissionId");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Role");
});
@@ -109,19 +129,17 @@ namespace Data.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Stock");
@@ -135,55 +153,69 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Passcode")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("UsersRolesId")
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UsersRolesId");
b.HasIndex("RoleId");
b.HasIndex("Name", "Password")
.IsUnique();
b.ToTable("User");
});
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.HasOne("Models.Models.Product", null)
.WithMany("Deals")
.HasForeignKey("ProductId");
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.Role", b =>
modelBuilder.Entity("Models.Models.Permission", b =>
{
b.HasOne("Models.Models.Permission", null)
.WithMany("Role")
.HasForeignKey("PermissionId");
b.HasOne("Models.Models.Role", null)
.WithMany("Permissions")
.HasForeignKey("RoleId");
});
modelBuilder.Entity("Models.Models.Product", b =>
{
b.HasOne("Models.Models.Deal", null)
.WithMany("Products")
.HasForeignKey("DealId");
b.HasOne("Models.Models.Stock", null)
.WithMany("Products")
.HasForeignKey("StockId");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.HasOne("Models.Models.Product", null)
.WithMany("Stocks")
.HasForeignKey("ProductId");
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "UsersRoles")
b.HasOne("Models.Models.Role", "Role")
.WithMany()
.HasForeignKey("UsersRolesId");
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations
{
@@ -6,50 +7,35 @@ namespace Data.Migrations
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Permission",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Permission", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: true),
Price = table.Column<double>(nullable: false),
AmountInStock = table.Column<double>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: true),
PermissionId = table.Column<int>(nullable: true)
Name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Permission",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
RoleId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Permission", x => x.Id);
table.ForeignKey(
name: "FK_Role_Permission_PermissionId",
column: x => x.PermissionId,
principalTable: "Permission",
name: "FK_Permission_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@@ -60,19 +46,19 @@ namespace Data.Migrations
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: true),
Passcode = table.Column<string>(nullable: true),
UsersRolesId = table.Column<int>(nullable: true)
Name = table.Column<string>(nullable: false),
Password = table.Column<string>(nullable: false),
RoleId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
table.ForeignKey(
name: "FK_User_Role_UsersRolesId",
column: x => x.UsersRolesId,
name: "FK_User_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -81,25 +67,18 @@ namespace Data.Migrations
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: true),
Amount = table.Column<double>(nullable: false),
ProductId = table.Column<int>(nullable: true)
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Deal", x => x.Id);
table.ForeignKey(
name: "FK_Deal_Product_ProductId",
column: x => x.ProductId,
principalTable: "Product",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Deal_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -108,31 +87,48 @@ namespace Data.Migrations
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: true),
Amount = table.Column<double>(nullable: false),
ProductId = table.Column<int>(nullable: true)
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stock", x => x.Id);
table.ForeignKey(
name: "FK_Stock_Product_ProductId",
column: x => x.ProductId,
principalTable: "Product",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Stock_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Deal_ProductId",
table: "Deal",
column: "ProductId");
migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
Price = table.Column<double>(nullable: false),
AmountInStock = table.Column<double>(nullable: false),
DealId = table.Column<int>(nullable: true),
StockId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
table.ForeignKey(
name: "FK_Product_Deal_DealId",
column: x => x.DealId,
principalTable: "Deal",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Product_Stock_StockId",
column: x => x.StockId,
principalTable: "Stock",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Deal_UserId",
@@ -140,14 +136,37 @@ namespace Data.Migrations
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Role_PermissionId",
table: "Role",
column: "PermissionId");
name: "IX_Permission_Name",
table: "Permission",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Stock_ProductId",
table: "Stock",
column: "ProductId");
name: "IX_Permission_RoleId",
table: "Permission",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_Product_DealId",
table: "Product",
column: "DealId");
migrationBuilder.CreateIndex(
name: "IX_Product_Name",
table: "Product",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Product_StockId",
table: "Product",
column: "StockId");
migrationBuilder.CreateIndex(
name: "IX_Role_Name",
table: "Role",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Stock_UserId",
@@ -155,30 +174,36 @@ namespace Data.Migrations
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_User_UsersRolesId",
name: "IX_User_RoleId",
table: "User",
column: "UsersRolesId");
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_User_Name_Password",
table: "User",
columns: new[] { "Name", "Password" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Permission");
migrationBuilder.DropTable(
name: "Product");
migrationBuilder.DropTable(
name: "Deal");
migrationBuilder.DropTable(
name: "Stock");
migrationBuilder.DropTable(
name: "Product");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropTable(
name: "Role");
migrationBuilder.DropTable(
name: "Permission");
}
}
}

View File

@@ -26,19 +26,17 @@ namespace Data.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Deal");
@@ -52,10 +50,19 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("RoleId");
b.ToTable("Permission");
});
@@ -69,14 +76,28 @@ namespace Data.Migrations
b.Property<double>("AmountInStock")
.HasColumnType("float");
b.Property<int?>("DealId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("StockId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DealId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("StockId");
b.ToTable("Product");
});
@@ -88,14 +109,13 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("PermissionId")
.HasColumnType("int");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("PermissionId");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Role");
});
@@ -107,19 +127,17 @@ namespace Data.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Stock");
@@ -133,55 +151,69 @@ namespace Data.Migrations
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Passcode")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("UsersRolesId")
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UsersRolesId");
b.HasIndex("RoleId");
b.HasIndex("Name", "Password")
.IsUnique();
b.ToTable("User");
});
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.HasOne("Models.Models.Product", null)
.WithMany("Deals")
.HasForeignKey("ProductId");
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.Role", b =>
modelBuilder.Entity("Models.Models.Permission", b =>
{
b.HasOne("Models.Models.Permission", null)
.WithMany("Role")
.HasForeignKey("PermissionId");
b.HasOne("Models.Models.Role", null)
.WithMany("Permissions")
.HasForeignKey("RoleId");
});
modelBuilder.Entity("Models.Models.Product", b =>
{
b.HasOne("Models.Models.Deal", null)
.WithMany("Products")
.HasForeignKey("DealId");
b.HasOne("Models.Models.Stock", null)
.WithMany("Products")
.HasForeignKey("StockId");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.HasOne("Models.Models.Product", null)
.WithMany("Stocks")
.HasForeignKey("ProductId");
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "UsersRoles")
b.HasOne("Models.Models.Role", "Role")
.WithMany()
.HasForeignKey("UsersRolesId");
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}