diff --git a/LuminousSales/Business/Business/UserManagment/CreateInitialUser.cs b/LuminousSales/Business/Business/UserManagment/CreateInitialUser.cs index 9b3fb4b..d6df069 100644 --- a/LuminousSales/Business/Business/UserManagment/CreateInitialUser.cs +++ b/LuminousSales/Business/Business/UserManagment/CreateInitialUser.cs @@ -9,55 +9,31 @@ namespace Business.Business.UserManagment public class CreateInitialUser { private LuminousContext context; - private string RoleName; private string Username; private string Password; private UserController userctl; - public CreateInitialUser(string RoleName, string Username, string Password) + public CreateInitialUser(string Username, string Password) { userctl = new UserController(); - this.RoleName = RoleName; this.Username = Username; this.Password = Password; } - public void CreatePermissions() + public void CreateRoles() { - using (context = new LuminousContext()) { - var admin = new Permission("Admin"); - var roleChanger = new Permission("Role Creator"); - var userCreation = new Permission("User Creator"); - var report = new Permission("Report"); - var stock = new Permission("Stock"); - var sell = new Permission("Sell"); - context.Permission.AddRange - ( - admin, - roleChanger, - userCreation, - report, - stock, - sell - ); + var Admin = new Role("Admin"); + var Manager = new Role("Manager"); + var Cashier = new Role("Cashier"); + context.Role.AddRange(Admin, Manager, Cashier); context.SaveChanges(); - Console.WriteLine("Permissions were intialized"); - } - } - - public void CreateFirstRole() - { - using (context = new LuminousContext()) - { - var AdminPermission = context.Permission.FirstOrDefault(p => p.Name == "Admin"); - userctl.CreateRole(this.RoleName , AdminPermission); } } public void CreateFirstUser() { using (context = new LuminousContext()) { - var roleToAttach = context.Role.Where(r => r.Name == this.RoleName).FirstOrDefault(); + int roleToAttach = context.Role.FirstOrDefault(r => r.Name == "Admin").Id; userctl.CreateUser(this.Username, this.Password, roleToAttach); } } diff --git a/LuminousSales/Business/Business/UserManagment/UserController.cs b/LuminousSales/Business/Business/UserManagment/UserController.cs index 1e4a237..a50e63f 100644 --- a/LuminousSales/Business/Business/UserManagment/UserController.cs +++ b/LuminousSales/Business/Business/UserManagment/UserController.cs @@ -1,5 +1,4 @@ -using Data.Models; -using Models; +using Models; using Models.Models; using System; using System.Collections.Generic; @@ -12,26 +11,11 @@ namespace Business.Business.UserManagment public class UserController { private LuminousContext context; - public void CreateRole(string RoleName, Permission Permission) - { - using (context = new LuminousContext()) - { - var role = new Role(RoleName); - var relationship = new RolePermission(); - relationship.Roles = role; - relationship.Permission = Permission; - role.Permissions.Add(relationship); - Permission.Role.Add(relationship); - context.RolePermission.Add(relationship); - context.Role.Add(role); - context.SaveChanges(); - } - } - public void CreateUser(string Username, string Password, Role Role) + public void CreateUser(string Username, string Password, int RoleId) { using (context = new LuminousContext()) { - var user = new User(Username, Password, Role); + var user = new User(Username, Password, RoleId); context.User.Add(user); context.SaveChanges(); } diff --git a/LuminousSales/Business/Business/UserManagment/UserValidator.cs b/LuminousSales/Business/Business/UserManagment/UserValidator.cs index 405d90d..c48f5f7 100644 --- a/LuminousSales/Business/Business/UserManagment/UserValidator.cs +++ b/LuminousSales/Business/Business/UserManagment/UserValidator.cs @@ -10,26 +10,24 @@ namespace Business.Business.UserManagment public class UserValidator { private LuminousContext context; - public bool CheckIfUserIsCreated() + public void CheckIfUserEverCreated() { using (context = new LuminousContext()) { if (context.User.ToList().Any()) { - return true; + throw new ArgumentException("First user is already created!"); } - return false; } } - public bool CheckPassword(string Password) + public void CheckPassword(string Password) { using (context = new LuminousContext()) { if (context.User.ToList().Exists(user => user.Password == Password)) { - return true; + throw new ArgumentException("Invalid User!"); } - return false; } } } diff --git a/LuminousSales/Display/Program.cs b/LuminousSales/Display/Program.cs index 39dc4f7..8137f9b 100644 --- a/LuminousSales/Display/Program.cs +++ b/LuminousSales/Display/Program.cs @@ -11,15 +11,16 @@ namespace Display static void Main(string[] args) { var val = new UserValidator(); - if (!val.CheckIfUserIsCreated()) + try { - var InitialCreation = new CreateInitialUser("Admin", "Admin", "pass123"); - InitialCreation.CreateFirstRole(); + val.CheckIfUserEverCreated(); + var InitialCreation = new CreateInitialUser("Admin", "pass123"); + InitialCreation.CreateRoles(); InitialCreation.CreateFirstUser(); } - else + catch (Exception e) { - Console.WriteLine("Already created"); + Console.WriteLine(e.Message); } } } diff --git a/LuminousSales/Models/LuminousContext.cs b/LuminousSales/Models/LuminousContext.cs index 80f918c..20278c7 100644 --- a/LuminousSales/Models/LuminousContext.cs +++ b/LuminousSales/Models/LuminousContext.cs @@ -1,5 +1,4 @@ using Data; -using Data.Models; using Microsoft.EntityFrameworkCore; using Models.Models; @@ -19,11 +18,9 @@ namespace Models public DbSet User { get; set; } public DbSet Role { get; set; } - public DbSet Permission { get; set; } public DbSet Product { get; set; } public DbSet Deal { get; set; } public DbSet Stock { get; set; } - public DbSet RolePermission { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -40,22 +37,9 @@ namespace Models 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); - modelBuilder.Entity() - .HasKey(rp => new { rp.RoleId, rp.PermisionId }); - modelBuilder.Entity() - .HasOne(rp => rp.Roles) - .WithMany(rp => rp.Permissions) - .HasForeignKey(rp => rp.RoleId); - modelBuilder.Entity() - .HasOne(rp => rp.Permission) - .WithMany(rp => rp.Role) - .HasForeignKey(rp => rp.PermisionId); } } } diff --git a/LuminousSales/Models/Migrations/20210317183331_InitialMigration.Designer.cs b/LuminousSales/Models/Migrations/20210318105825_init.Designer.cs similarity index 73% rename from LuminousSales/Models/Migrations/20210317183331_InitialMigration.Designer.cs rename to LuminousSales/Models/Migrations/20210318105825_init.Designer.cs index d84a0fa..f835cde 100644 --- a/LuminousSales/Models/Migrations/20210317183331_InitialMigration.Designer.cs +++ b/LuminousSales/Models/Migrations/20210318105825_init.Designer.cs @@ -10,8 +10,8 @@ using Models; namespace Data.Migrations { [DbContext(typeof(LuminousContext))] - [Migration("20210317183331_InitialMigration")] - partial class InitialMigration + [Migration("20210318105825_init")] + partial class init { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -21,21 +21,6 @@ namespace Data.Migrations .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("Data.Models.RolePermission", b => - { - b.Property("RoleId") - .HasColumnType("int"); - - b.Property("PermisionId") - .HasColumnType("int"); - - b.HasKey("RoleId", "PermisionId"); - - b.HasIndex("PermisionId"); - - b.ToTable("RolePermission"); - }); - modelBuilder.Entity("Models.Models.Deal", b => { b.Property("Id") @@ -43,6 +28,12 @@ namespace Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + b.Property("Time") .IsConcurrencyToken() .IsRequired() @@ -54,30 +45,13 @@ namespace Data.Migrations b.HasKey("Id"); + b.HasIndex("ProductId"); + b.HasIndex("UserId"); b.ToTable("Deal"); }); - modelBuilder.Entity("Models.Models.Permission", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Permission"); - }); - modelBuilder.Entity("Models.Models.Product", b => { b.Property("Id") @@ -88,9 +62,6 @@ namespace Data.Migrations b.Property("AmountInStock") .HasColumnType("float"); - b.Property("DealId") - .HasColumnType("int"); - b.Property("Name") .IsRequired() .HasColumnType("nvarchar(450)"); @@ -98,18 +69,11 @@ namespace Data.Migrations 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"); }); @@ -139,6 +103,12 @@ namespace Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + b.Property("Time") .IsConcurrencyToken() .IsRequired() @@ -150,6 +120,8 @@ namespace Data.Migrations b.HasKey("Id"); + b.HasIndex("ProductId"); + b.HasIndex("UserId"); b.ToTable("Stock"); @@ -183,23 +155,14 @@ namespace Data.Migrations b.ToTable("User"); }); - modelBuilder.Entity("Data.Models.RolePermission", b => - { - b.HasOne("Models.Models.Permission", "Permission") - .WithMany("Role") - .HasForeignKey("PermisionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Models.Models.Role", "Roles") - .WithMany("Permissions") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - modelBuilder.Entity("Models.Models.Deal", b => { + b.HasOne("Models.Models.Product", "Products") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("Models.Models.User", "User") .WithMany() .HasForeignKey("UserId") @@ -207,19 +170,14 @@ namespace Data.Migrations .IsRequired(); }); - 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", "Products") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("Models.Models.User", "User") .WithMany() .HasForeignKey("UserId") diff --git a/LuminousSales/Models/Migrations/20210317183331_InitialMigration.cs b/LuminousSales/Models/Migrations/20210318105825_init.cs similarity index 66% rename from LuminousSales/Models/Migrations/20210317183331_InitialMigration.cs rename to LuminousSales/Models/Migrations/20210318105825_init.cs index 7f86c8c..ec2bf8f 100644 --- a/LuminousSales/Models/Migrations/20210317183331_InitialMigration.cs +++ b/LuminousSales/Models/Migrations/20210318105825_init.cs @@ -3,21 +3,23 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Data.Migrations { - public partial class InitialMigration : Migration + public partial class init : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "Permission", + name: "Product", columns: table => new { Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: false) + Name = table.Column(nullable: false), + Price = table.Column(nullable: false), + AmountInStock = table.Column(nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Permission", x => x.Id); + table.PrimaryKey("PK_Product", x => x.Id); }); migrationBuilder.CreateTable( @@ -33,30 +35,6 @@ namespace Data.Migrations table.PrimaryKey("PK_Role", x => x.Id); }); - migrationBuilder.CreateTable( - name: "RolePermission", - columns: table => new - { - RoleId = table.Column(nullable: false), - PermisionId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_RolePermission", x => new { x.RoleId, x.PermisionId }); - table.ForeignKey( - name: "FK_RolePermission_Permission_PermisionId", - column: x => x.PermisionId, - principalTable: "Permission", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_RolePermission_Role_RoleId", - column: x => x.RoleId, - principalTable: "Role", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "User", columns: table => new @@ -85,11 +63,19 @@ namespace Data.Migrations Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(nullable: false), + ProductId = table.Column(nullable: false), + Amount = 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.Cascade); table.ForeignKey( name: "FK_Deal_User_UserId", column: x => x.UserId, @@ -105,11 +91,19 @@ namespace Data.Migrations Id = table.Column(nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(nullable: false), + ProductId = table.Column(nullable: false), + Amount = 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.Cascade); table.ForeignKey( name: "FK_Stock_User_UserId", column: x => x.UserId, @@ -118,62 +112,22 @@ namespace Data.Migrations onDelete: ReferentialAction.Cascade); }); - 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_ProductId", + table: "Deal", + column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_Deal_UserId", table: "Deal", column: "UserId"); - migrationBuilder.CreateIndex( - name: "IX_Permission_Name", - table: "Permission", - column: "Name", - unique: true); - - 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", @@ -181,9 +135,9 @@ namespace Data.Migrations unique: true); migrationBuilder.CreateIndex( - name: "IX_RolePermission_PermisionId", - table: "RolePermission", - column: "PermisionId"); + name: "IX_Stock_ProductId", + table: "Stock", + column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_Stock_UserId", @@ -204,12 +158,6 @@ namespace Data.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( - name: "Product"); - - migrationBuilder.DropTable( - name: "RolePermission"); - migrationBuilder.DropTable( name: "Deal"); @@ -217,7 +165,7 @@ namespace Data.Migrations name: "Stock"); migrationBuilder.DropTable( - name: "Permission"); + name: "Product"); migrationBuilder.DropTable( name: "User"); diff --git a/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs index 1d4f7dc..05368e7 100644 --- a/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs +++ b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs @@ -19,21 +19,6 @@ namespace Data.Migrations .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("Data.Models.RolePermission", b => - { - b.Property("RoleId") - .HasColumnType("int"); - - b.Property("PermisionId") - .HasColumnType("int"); - - b.HasKey("RoleId", "PermisionId"); - - b.HasIndex("PermisionId"); - - b.ToTable("RolePermission"); - }); - modelBuilder.Entity("Models.Models.Deal", b => { b.Property("Id") @@ -41,6 +26,12 @@ namespace Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + b.Property("Time") .IsConcurrencyToken() .IsRequired() @@ -52,30 +43,13 @@ namespace Data.Migrations b.HasKey("Id"); + b.HasIndex("ProductId"); + b.HasIndex("UserId"); b.ToTable("Deal"); }); - modelBuilder.Entity("Models.Models.Permission", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Permission"); - }); - modelBuilder.Entity("Models.Models.Product", b => { b.Property("Id") @@ -86,9 +60,6 @@ namespace Data.Migrations b.Property("AmountInStock") .HasColumnType("float"); - b.Property("DealId") - .HasColumnType("int"); - b.Property("Name") .IsRequired() .HasColumnType("nvarchar(450)"); @@ -96,18 +67,11 @@ namespace Data.Migrations 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"); }); @@ -137,6 +101,12 @@ namespace Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + b.Property("Time") .IsConcurrencyToken() .IsRequired() @@ -148,6 +118,8 @@ namespace Data.Migrations b.HasKey("Id"); + b.HasIndex("ProductId"); + b.HasIndex("UserId"); b.ToTable("Stock"); @@ -181,23 +153,14 @@ namespace Data.Migrations b.ToTable("User"); }); - modelBuilder.Entity("Data.Models.RolePermission", b => - { - b.HasOne("Models.Models.Permission", "Permission") - .WithMany("Role") - .HasForeignKey("PermisionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Models.Models.Role", "Roles") - .WithMany("Permissions") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - modelBuilder.Entity("Models.Models.Deal", b => { + b.HasOne("Models.Models.Product", "Products") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("Models.Models.User", "User") .WithMany() .HasForeignKey("UserId") @@ -205,19 +168,14 @@ namespace Data.Migrations .IsRequired(); }); - 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", "Products") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("Models.Models.User", "User") .WithMany() .HasForeignKey("UserId") diff --git a/LuminousSales/Models/Models/Base/BaseSales.cs b/LuminousSales/Models/Models/Base/BaseSales.cs index 10b1b36..6135325 100644 --- a/LuminousSales/Models/Models/Base/BaseSales.cs +++ b/LuminousSales/Models/Models/Base/BaseSales.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Text; namespace Data.Base @@ -12,17 +13,26 @@ namespace Data.Base { } - protected BaseSales(User User, ICollection Products) + protected BaseSales(int UserId, int ProductId, double Amount) { - this.User = User; - this.Products = Products; + this.UserId = UserId; + this.ProductId = ProductId; + this.Amount = Amount; } [Key] public int Id { get; set; } [Required] + [ForeignKey("User")] + public int UserId { get; set; } + [Required] public virtual User User { get; set; } [Required] - public virtual ICollection Products { get; set; } + [ForeignKey("Product")] + public int ProductId { get; set; } + [Required] + public virtual Product Products { get; set; } + [Required] + public double Amount { get; set; } [Timestamp] [Required] public byte[] Time { get; set; } diff --git a/LuminousSales/Models/Models/Deal.cs b/LuminousSales/Models/Models/Deal.cs index c245e5f..7790ffe 100644 --- a/LuminousSales/Models/Models/Deal.cs +++ b/LuminousSales/Models/Models/Deal.cs @@ -6,6 +6,6 @@ namespace Models.Models public class Deal : BaseSales { public Deal() : base(){} - public Deal(User User, ICollection Products) : base(User, Products){} + public Deal(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount) { } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Permission.cs b/LuminousSales/Models/Models/Permission.cs deleted file mode 100644 index 97e9243..0000000 --- a/LuminousSales/Models/Models/Permission.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Data.Base; -using Data.Models; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Models.Models -{ - public class Permission : BaseUserManagmentEntity - { - public Permission() : base(){} - public Permission(string Name) : base(Name){} - [Required] - public virtual ICollection Role { get; set; } - } -} \ No newline at end of file diff --git a/LuminousSales/Models/Models/Role.cs b/LuminousSales/Models/Models/Role.cs index e39fb7b..8eebf30 100644 --- a/LuminousSales/Models/Models/Role.cs +++ b/LuminousSales/Models/Models/Role.cs @@ -1,5 +1,4 @@ using Data.Base; -using Data.Models; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -9,9 +8,6 @@ namespace Models.Models public class Role : BaseUserManagmentEntity { public Role() : base(){} - public Role(string Name) : base(Name) - { - } - public virtual ICollection Permissions { get; set; } = new List<> + public Role(string Name) : base(Name){} } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/RolePermission.cs b/LuminousSales/Models/Models/RolePermission.cs deleted file mode 100644 index c8812d2..0000000 --- a/LuminousSales/Models/Models/RolePermission.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Models.Models; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Data.Models -{ - public class RolePermission - { - public int RoleId { get; set; } - public virtual Role Roles { get; set; } - public int PermisionId { get; set; } - public virtual Permission Permission { get; set; } - } -} diff --git a/LuminousSales/Models/Models/Stock.cs b/LuminousSales/Models/Models/Stock.cs index 1a0bd4c..8161b30 100644 --- a/LuminousSales/Models/Models/Stock.cs +++ b/LuminousSales/Models/Models/Stock.cs @@ -9,6 +9,6 @@ namespace Models.Models public class Stock : BaseSales { public Stock() : base(){} - public Stock(User User, ICollection Products) : base(User, Products){} + public Stock(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount){} } } diff --git a/LuminousSales/Models/Models/User.cs b/LuminousSales/Models/Models/User.cs index 4608069..d1a26a2 100644 --- a/LuminousSales/Models/Models/User.cs +++ b/LuminousSales/Models/Models/User.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Text; namespace Models.Models @@ -9,14 +10,16 @@ namespace Models.Models public class User : BaseUserManagmentEntity { public User() : base() { } - public User(string Name, string Password, Role Role) : base(Name) + public User(string Name, string Password, int RoleId) : base(Name) { this.Password = Password; - this.Role = Role; + this.RoleId = RoleId; } [Required] public string Password { get; set; } [Required] + [ForeignKey("Role")] + public int RoleId { get; set; } public virtual Role Role { get; set; } } }