diff --git a/LuminousSales/Business/Business/UsersController.cs b/LuminousSales/Business/Business/UsersController.cs index 7312096..554a9b4 100644 --- a/LuminousSales/Business/Business/UsersController.cs +++ b/LuminousSales/Business/Business/UsersController.cs @@ -1,14 +1,17 @@ using Models; +using Models.Models; +using System.Linq; namespace LuminousSales.Business { public class UsersController { - private LuminousContext userContext; + + private LuminousContext contex; public UsersController() { - this.userContext = new LuminousContext(); + this.contex = new LuminousContext(); } } } diff --git a/LuminousSales/Display/Program.cs b/LuminousSales/Display/Program.cs index 3d0306f..90071d5 100644 --- a/LuminousSales/Display/Program.cs +++ b/LuminousSales/Display/Program.cs @@ -1,4 +1,5 @@ -using System; +using LuminousSales.Business; +using System; namespace Display { @@ -6,7 +7,6 @@ namespace Display { static void Main(string[] args) { - Console.WriteLine("Hello World!"); } } } diff --git a/LuminousSales/Models/LuminousContext.cs b/LuminousSales/Models/LuminousContext.cs index 8e00dbd..27ee9dd 100644 --- a/LuminousSales/Models/LuminousContext.cs +++ b/LuminousSales/Models/LuminousContext.cs @@ -32,7 +32,18 @@ namespace Models protected override void OnModelCreating(ModelBuilder modelBuilder) { - base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .HasIndex(user => new { user.Name, user.Password }) + .IsUnique(true); + modelBuilder.Entity() + .HasIndex(role => new { role.Name }) + .IsUnique(true); + modelBuilder.Entity() + .HasIndex(permission => new { permission.Name }) + .IsUnique(true); + modelBuilder.Entity() + .HasIndex(product => new { product.Name }) + .IsUnique(true); } } } diff --git a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs b/LuminousSales/Models/Migrations/20210314081427_IntialMigration.Designer.cs similarity index 62% rename from LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs rename to LuminousSales/Models/Migrations/20210314081427_IntialMigration.Designer.cs index 06b57e4..29cd63a 100644 --- a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs +++ b/LuminousSales/Models/Migrations/20210314081427_IntialMigration.Designer.cs @@ -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("Amount") - .HasColumnType("float"); + b.Property("Time") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("UserId") + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("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("AmountInStock") .HasColumnType("float"); + b.Property("DealId") + .HasColumnType("int"); + b.Property("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); b.Property("Price") .HasColumnType("float"); + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("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("Amount") - .HasColumnType("float"); + b.Property("Time") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("UserId") + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); - b.Property("Passcode") - .HasColumnType("nvarchar(max)"); + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(450)"); - b.Property("UsersRolesId") + b.Property("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 } diff --git a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs b/LuminousSales/Models/Migrations/20210314081427_IntialMigration.cs similarity index 63% rename from LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs rename to LuminousSales/Models/Migrations/20210314081427_IntialMigration.cs index 9757514..914cb86 100644 --- a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs +++ b/LuminousSales/Models/Migrations/20210314081427_IntialMigration.cs @@ -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(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Permission", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Product", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true), - Price = table.Column(nullable: false), - AmountInStock = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Product", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Role", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true), - PermissionId = table.Column(nullable: true) + Name = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Permission", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + RoleId = table.Column(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(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true), - Passcode = table.Column(nullable: true), - UsersRolesId = table.Column(nullable: true) + Name = table.Column(nullable: false), + Password = table.Column(nullable: false), + RoleId = table.Column(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(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(nullable: true), - Amount = table.Column(nullable: false), - ProductId = table.Column(nullable: true) + UserId = table.Column(nullable: false), + Time = table.Column(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(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(nullable: true), - Amount = table.Column(nullable: false), - ProductId = table.Column(nullable: true) + UserId = table.Column(nullable: false), + Time = table.Column(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(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: false), + Price = table.Column(nullable: false), + AmountInStock = table.Column(nullable: false), + DealId = table.Column(nullable: true), + StockId = table.Column(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"); } } } diff --git a/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs index 712dd6d..b8dc697 100644 --- a/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs +++ b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs @@ -26,19 +26,17 @@ namespace Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("Amount") - .HasColumnType("float"); + b.Property("Time") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("UserId") + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("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("AmountInStock") .HasColumnType("float"); + b.Property("DealId") + .HasColumnType("int"); + b.Property("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); b.Property("Price") .HasColumnType("float"); + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("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("Amount") - .HasColumnType("float"); + b.Property("Time") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("UserId") + b.Property("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("Name") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(450)"); - b.Property("Passcode") - .HasColumnType("nvarchar(max)"); + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(450)"); - b.Property("UsersRolesId") + b.Property("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 } diff --git a/LuminousSales/Models/Models/Base/BaseSales.cs b/LuminousSales/Models/Models/Base/BaseSales.cs new file mode 100644 index 0000000..10b1b36 --- /dev/null +++ b/LuminousSales/Models/Models/Base/BaseSales.cs @@ -0,0 +1,30 @@ +using Models.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Data.Base +{ + public abstract class BaseSales + { + protected BaseSales() + { + + } + protected BaseSales(User User, ICollection Products) + { + this.User = User; + this.Products = Products; + } + [Key] + public int Id { get; set; } + [Required] + public virtual User User { get; set; } + [Required] + public virtual ICollection Products { get; set; } + [Timestamp] + [Required] + public byte[] Time { get; set; } + } +} diff --git a/LuminousSales/Models/Models/Base/BaseUserManagmentEntity.cs b/LuminousSales/Models/Models/Base/BaseUserManagmentEntity.cs new file mode 100644 index 0000000..1ddf80d --- /dev/null +++ b/LuminousSales/Models/Models/Base/BaseUserManagmentEntity.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Data.Base +{ + public abstract class BaseUserManagmentEntity + { + public BaseUserManagmentEntity(){} + protected BaseUserManagmentEntity(string Name) + { + this.Name = Name; + } + [Key] + public int Id { get; set; } + [Required] + public string Name { get; set; } + } +} diff --git a/LuminousSales/Models/Models/Deal.cs b/LuminousSales/Models/Models/Deal.cs index 5c34a72..d4cfa08 100644 --- a/LuminousSales/Models/Models/Deal.cs +++ b/LuminousSales/Models/Models/Deal.cs @@ -1,17 +1,13 @@ -using Models.Models.Interfaces; +using Data.Base; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Models.Models { - public class Deal : IBaseSalesProperties + public class Deal : BaseSales { - [Key] - public int Id { get; set; } - public User User { get; set; } - public double Amount { get; set; } - [Timestamp] - public byte[] time; + public Deal() : base(){} + public Deal(User User, ICollection Products) : base(User, Products){} } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Interfaces/IBaseProperties.cs b/LuminousSales/Models/Models/Interfaces/IBaseProperties.cs deleted file mode 100644 index d877d96..0000000 --- a/LuminousSales/Models/Models/Interfaces/IBaseProperties.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Models.Models.Interfaces -{ - public interface IBaseProperties - { - int Id { get; set; } - string Name { get; set; } - } -} diff --git a/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs b/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs deleted file mode 100644 index f44cc82..0000000 --- a/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Text; - -namespace Models.Models.Interfaces -{ - interface IBaseSalesProperties - { - User User { get; set; } - double Amount { get; set; } - } -} diff --git a/LuminousSales/Models/Models/Permission.cs b/LuminousSales/Models/Models/Permission.cs index 530faba..ad43ab9 100644 --- a/LuminousSales/Models/Models/Permission.cs +++ b/LuminousSales/Models/Models/Permission.cs @@ -1,14 +1,12 @@ -using Models.Models.Interfaces; +using Data.Base; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Models.Models { - public class Permission : IBaseProperties + public class Permission : BaseUserManagmentEntity { - [Key] - public int Id { get; set; } - public string Name { get; set; } - public virtual ICollection Role { get; set; } + public Permission() : base(){} + public Permission(string Name) : base(Name){} } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Product.cs b/LuminousSales/Models/Models/Product.cs index efb3ee3..b2f9bd1 100644 --- a/LuminousSales/Models/Models/Product.cs +++ b/LuminousSales/Models/Models/Product.cs @@ -1,17 +1,30 @@ -using Models.Models.Interfaces; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Models.Models { - public class Product : IBaseProperties + public class Product { + public Product(){} + public Product(string Name, double Price) + { + this.Name = Name; + this.Price = Price; + this.AmountInStock = 0; + } + public Product(string Name, double Price, double AmountInStock) + { + this.Name = Name; + this.Price = Price; + this.AmountInStock = AmountInStock; + } [Key] public int Id { get; set; } + [Required] public string Name { get; set; } + [Required] public double Price { get; set; } + [Required] public double AmountInStock { get; set; } - public virtual ICollection Deals { get; set; } - public virtual ICollection Stocks { get; set; } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Role.cs b/LuminousSales/Models/Models/Role.cs index 6883e02..29803da 100644 --- a/LuminousSales/Models/Models/Role.cs +++ b/LuminousSales/Models/Models/Role.cs @@ -1,13 +1,17 @@ -using Models.Models.Interfaces; +using Data.Base; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Models.Models { - public class Role : IBaseProperties + public class Role : BaseUserManagmentEntity { - [Key] - public int Id { get; set; } - public string Name { get; set; } + public Role() : base(){} + public Role(string Name, ICollection Permissions) : base(Name) + { + this.Permissions = Permissions; + } + [Required] + public virtual ICollection Permissions { get; set; } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Stock.cs b/LuminousSales/Models/Models/Stock.cs index 4423b52..56dbc8f 100644 --- a/LuminousSales/Models/Models/Stock.cs +++ b/LuminousSales/Models/Models/Stock.cs @@ -1,4 +1,4 @@ -using Models.Models.Interfaces; +using Data.Base; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -6,13 +6,9 @@ using System.Text; namespace Models.Models { - public class Stock : IBaseSalesProperties + public class Stock : BaseSales { - [Key] - public int Id { get; set; } - public User User { get; set; } - public double Amount { get; set; } - [Timestamp] - public byte[] time; + public Stock() : base(){} + public Stock(User User, ICollection Products) : base(User, Products){} } } diff --git a/LuminousSales/Models/Models/User.cs b/LuminousSales/Models/Models/User.cs index 74a302a..4608069 100644 --- a/LuminousSales/Models/Models/User.cs +++ b/LuminousSales/Models/Models/User.cs @@ -1,4 +1,4 @@ -using Models.Models.Interfaces; +using Data.Base; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -6,12 +6,17 @@ using System.Text; namespace Models.Models { - public class User : IBaseProperties + public class User : BaseUserManagmentEntity { - [Key] - public int Id { get; set; } - public string Name { get; set; } - public string Passcode { get; set; } - public virtual Role UsersRoles { get; set; } + public User() : base() { } + public User(string Name, string Password, Role Role) : base(Name) + { + this.Password = Password; + this.Role = Role; + } + [Required] + public string Password { get; set; } + [Required] + public virtual Role Role { get; set; } } }