EF Models created

This commit is contained in:
batgo6o
2021-03-11 01:47:22 +02:00
parent f8ee73f50b
commit b45909ab63
45 changed files with 704 additions and 519 deletions

View File

@@ -1,7 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Data.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class DealsBusiness
{
private DealContext dealContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class PermissionsBusiness
{
private PermissionContext permissionContext;
}
}

View File

@@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuminousSales.Data;
using LuminousSales.Data.Model;
namespace LuminousSales.Business
{
public class ProductBusiness
{
private ProductContext productContext;
public List<Product> GetAll()
{
using (productContext = new ProductContext())
{
return productContext.Products.ToList();
}
}
public Product Get(int id)
{
using (productContext = new ProductContext())
{
return productContext.Products.Find(id);
}
}
public void Buy(Product product)
{
using (productContext = new ProductContext())
{
productContext.Products.Add(product);
productContext.SaveChanges();
}
}
public void Update(Product product)
{
using (productContext = new ProductContext())
{
var item = productContext.Products.Find(product.Id);
if (item != null)
{
productContext.Entry(item).CurrentValues.SetValues(product);
productContext.SaveChanges();
}
}
}
public void Sell(int id)
{
using (productContext = new ProductContext())
{
var product = productContext.Products.Find(id);
if (product != null)
{
productContext.Products.Remove(product);
productContext.SaveChanges();
}
}
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class RolesBusiness
{
private RoleContext roleContext;
}
}

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class RolesToPermissionBusiness
{
private RolesToPermissionContext rolesToPermissionContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class StocksBusiness
{
private StockContext stockContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class UsersBusiness
{
private UserContext userContext;
}
}

View File

@@ -0,0 +1,14 @@
using Models;
namespace LuminousSales.Business
{
public class UsersController
{
private LuminousContext userContext;
public UsersController()
{
this.userContext = new LuminousContext();
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class UsersToRolesBusiness
{
private UsersToRolesContext usersToRolesContext;
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Business\Business.csproj" />
<ProjectReference Include="..\Models\Data.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,12 @@
using System;
namespace Display
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View File

@@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31019.35
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LuminousSales", "LuminousSales\LuminousSales.csproj", "{0B102226-3EAB-4DA3-9C1F-4053E4FA2232}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Models\Data.csproj", "{40C482BF-B9C4-4460-BB1C-5A90959D1838}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{40C482BF-B9C4-4460-BB1C-5A90959D1838}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{E1661853-3081-4C40-8E68-C063B3BC88A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{E1661853-3081-4C40-8E68-C063B3BC88A4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Display", "Display\Display.csproj", "{61E060C5-4360-4880-9ED7-6A139C988F0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,10 +15,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0B102226-3EAB-4DA3-9C1F-4053E4FA2232}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B102226-3EAB-4DA3-9C1F-4053E4FA2232}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B102226-3EAB-4DA3-9C1F-4053E4FA2232}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B102226-3EAB-4DA3-9C1F-4053E4FA2232}.Release|Any CPU.Build.0 = Release|Any CPU
{40C482BF-B9C4-4460-BB1C-5A90959D1838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40C482BF-B9C4-4460-BB1C-5A90959D1838}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40C482BF-B9C4-4460-BB1C-5A90959D1838}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -27,6 +23,10 @@ Global
{E1661853-3081-4C40-8E68-C063B3BC88A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1661853-3081-4C40-8E68-C063B3BC88A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1661853-3081-4C40-8E68-C063B3BC88A4}.Release|Any CPU.Build.0 = Release|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class DealsBusiness
{
private DealContext dealContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class PermissionsBusiness
{
private PermissionContext permissionContext;
}
}

View File

@@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuminousSales.Data;
using LuminousSales.Data.Model;
namespace LuminousSales.Business
{
public class ProductBusiness
{
private ProductContext productContext;
public List<Product> GetAll()
{
using (productContext = new ProductContext())
{
return productContext.Products.ToList();
}
}
public Product Get(int id)
{
using (productContext = new ProductContext())
{
return productContext.Products.Find(id);
}
}
public void Buy(Product product)
{
using (productContext = new ProductContext())
{
productContext.Products.Add(product);
productContext.SaveChanges();
}
}
public void Update(Product product)
{
using (productContext = new ProductContext())
{
var item = productContext.Products.Find(product.Id);
if (item != null)
{
productContext.Entry(item).CurrentValues.SetValues(product);
productContext.SaveChanges();
}
}
}
public void Sell(int id)
{
using (productContext = new ProductContext())
{
var product = productContext.Products.Find(id);
if (product != null)
{
productContext.Products.Remove(product);
productContext.SaveChanges();
}
}
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class RolesBusiness
{
private RoleContext roleContext;
}
}

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class RolesToPermissionBusiness
{
private RolesToPermissionContext rolesToPermissionContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class StocksBusiness
{
private StockContext stockContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class UsersBusiness
{
private UserContext userContext;
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using LuminousSales.Data;
namespace LuminousSales.Business
{
public class UsersToRolesBusiness
{
private UsersToRolesContext usersToRolesContext;
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class DealContext : DbContext
{
public DealContext()
{
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class PermissionContext: DbContext
{
public PermissionContext()
{
}
}
}

View File

@@ -1,14 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class ProductContext : DbContext
{
public ProductContext():base()
{
}
}
}

View File

@@ -1,14 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class RoleContext : DbContext
{
public RoleContext():base()
{
}
}
}

View File

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class RolesToPermissionContext:DbContext
{
public RolesToPermissionContext():base()
{
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class StockContext:DbContext
{
public StockContext()
{
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class UserContext:DbContext
{
public UserContext():base()
{
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace LuminousSales.Data
{
public class UsersToRolesContext:DbContext
{
public UsersToRolesContext():base()
{
}
}
}

View File

@@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,15 +0,0 @@
using System;
namespace LuminousSales
{
public class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
Console.WriteLine(a);
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Data
{
public static class Configuration
{
public const string ConnectionString = "Data Source=CYNTHIA-PC;Initial Catalog=LuminousSales;Integrated Security=True";
}
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -1,23 +1,38 @@
using Microsoft.EntityFrameworkCore;
using Data;
using Microsoft.EntityFrameworkCore;
using Models.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Models
{
public class LuminousContext : DbContext
public class LuminousContext : DbContext
{
public LuminousContext()
{
}
public LuminousContext(DbContextOptions options) : base(options)
{
}
public DbSet<User> User { get; set; }
public DbSet<Role> Role { get; set; }
public DbSet<Permission> Permission { get; set; }
public DbSet<Product> Product { get; set; }
public DbSet<Deal> Deal{ get; set; }
public DbSet<Deal> Deal { get; set; }
public DbSet<Stock> Stock { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Server=(localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security=True");
optionsBuilder
.UseLazyLoadingProxies()
.UseSqlServer(Configuration.ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}

View File

@@ -0,0 +1,191 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Models;
namespace Data.Migrations
{
[DbContext(typeof(LuminousContext))]
[Migration("20210310234527_IntialMigration")]
partial class IntialMigration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.12")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Deal");
});
modelBuilder.Entity("Models.Models.Permission", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Permission");
});
modelBuilder.Entity("Models.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("AmountInStock")
.HasColumnType("float");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Product");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("PermissionId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PermissionId");
b.ToTable("Role");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Stock");
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<string>("Passcode")
.HasColumnType("nvarchar(max)");
b.Property<int?>("UsersRolesId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UsersRolesId");
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");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.HasOne("Models.Models.Permission", null)
.WithMany("Role")
.HasForeignKey("PermissionId");
});
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");
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "UsersRoles")
.WithMany()
.HasForeignKey("UsersRolesId");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,184 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations
{
public partial class IntialMigration : Migration
{
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)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
table.ForeignKey(
name: "FK_Role_Permission_PermissionId",
column: x => x.PermissionId,
principalTable: "Permission",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
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)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
table.ForeignKey(
name: "FK_User_Role_UsersRolesId",
column: x => x.UsersRolesId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Deal",
columns: table => new
{
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)
},
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);
});
migrationBuilder.CreateTable(
name: "Stock",
columns: table => new
{
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)
},
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);
});
migrationBuilder.CreateIndex(
name: "IX_Deal_ProductId",
table: "Deal",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Deal_UserId",
table: "Deal",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Role_PermissionId",
table: "Role",
column: "PermissionId");
migrationBuilder.CreateIndex(
name: "IX_Stock_ProductId",
table: "Stock",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Stock_UserId",
table: "Stock",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_User_UsersRolesId",
table: "User",
column: "UsersRolesId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
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

@@ -0,0 +1,189 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Models;
namespace Data.Migrations
{
[DbContext(typeof(LuminousContext))]
partial class LuminousContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.12")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Deal");
});
modelBuilder.Entity("Models.Models.Permission", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Permission");
});
modelBuilder.Entity("Models.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("AmountInStock")
.HasColumnType("float");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Product");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("PermissionId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PermissionId");
b.ToTable("Role");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<double>("Amount")
.HasColumnType("float");
b.Property<int?>("ProductId")
.HasColumnType("int");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("UserId");
b.ToTable("Stock");
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<string>("Passcode")
.HasColumnType("nvarchar(max)");
b.Property<int?>("UsersRolesId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UsersRolesId");
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");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.HasOne("Models.Models.Permission", null)
.WithMany("Role")
.HasForeignKey("PermissionId");
});
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");
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "UsersRoles")
.WithMany()
.HasForeignKey("UsersRolesId");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />
</ItemGroup>
</Project>

View File

@@ -1,25 +1,17 @@
using Models.Models.Interfaces;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Models.Models
{
public class Deal : IBaseSalesProperties
{
[Key]
public int Id { get; set; }
public User User { get; set; }
public ICollection<Product> ProductsADeal { get; set; }
public double Amount { get; set; }
private byte[] time;
public byte[] GetTime()
{
return time;
}
public void SetTime(byte[] value)
{
time = value;
}
[Timestamp]
public byte[] time;
}
}

View File

@@ -8,10 +8,6 @@ namespace Models.Models.Interfaces
interface IBaseSalesProperties
{
User User { get; set; }
ICollection<Product> ProductsADeal { get; set;}
double Amount { get; set; }
byte[] GetTime();
void SetTime(byte[] value);
}
}

View File

@@ -1,11 +1,14 @@
using Models.Models.Interfaces;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Models.Models
{
public class Permission : IBaseProperties
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Role> Role { get; set; }
}
}

View File

@@ -1,12 +1,17 @@
using Models.Models.Interfaces;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Models.Models
{
public class Product : IBaseProperties
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public double AvailableInStock { get; set; }
public double AmountInStock { get; set; }
public virtual ICollection<Deal> Deals { get; set; }
public virtual ICollection<Stock> Stocks { get; set; }
}
}

View File

@@ -6,9 +6,8 @@ namespace Models.Models
{
public class Role : IBaseProperties
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public ICollection<User> UsersWithTheRole { get; set; }
public ICollection<Permission> RolesPermissions{ get; set; }
}
}

View File

@@ -8,20 +8,11 @@ namespace Models.Models
{
public class Stock : IBaseSalesProperties
{
[Key]
public int Id { get; set; }
public User User { get; set; }
public ICollection<Product> ProductsADeal { get; set; }
public double Amount { get; set; }
private byte[] time;
public byte[] GetTime()
{
return time;
}
public void SetTime(byte[] value)
{
time = value;
}
[Timestamp]
public byte[] time;
}
}

View File

@@ -1,17 +1,17 @@
using Models.Models.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Models.Models
{
public class User : IBaseProperties
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string Passcode { get; set; }
public Role Role { get; set; }
public ICollection<Deal> ItemsSoldByUser{ get; set; }
public ICollection<Product> ItemsStockedByUser { get; set; }
public virtual Role UsersRoles { get; set; }
}
}