diff --git a/LuminousSales/Business/Business.csproj b/LuminousSales/Business/Business.csproj index e001fc0..0295fe7 100644 --- a/LuminousSales/Business/Business.csproj +++ b/LuminousSales/Business/Business.csproj @@ -1,21 +1,15 @@ - netstandard2.0 + netstandard2.1 - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + diff --git a/LuminousSales/Business/Business/UsersController.cs b/LuminousSales/Business/Business/UsersController.cs new file mode 100644 index 0000000..7312096 --- /dev/null +++ b/LuminousSales/Business/Business/UsersController.cs @@ -0,0 +1,14 @@ +using Models; + +namespace LuminousSales.Business +{ + public class UsersController + { + private LuminousContext userContext; + + public UsersController() + { + this.userContext = new LuminousContext(); + } + } +} diff --git a/LuminousSales/Business/DealsBusiness.cs b/LuminousSales/Business/DealsBusiness.cs deleted file mode 100644 index 1cecbc8..0000000 --- a/LuminousSales/Business/DealsBusiness.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Business -{ - public class DealsBusiness - { - private DealContext dealContext; - - } -} diff --git a/LuminousSales/Business/PermissionsBusiness.cs b/LuminousSales/Business/PermissionsBusiness.cs deleted file mode 100644 index 63c4810..0000000 --- a/LuminousSales/Business/PermissionsBusiness.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Business -{ - public class PermissionsBusiness - { - private PermissionContext permissionContext; - - - } -} diff --git a/LuminousSales/Business/ProductBusiness.cs b/LuminousSales/Business/ProductBusiness.cs deleted file mode 100644 index b684c5c..0000000 --- a/LuminousSales/Business/ProductBusiness.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Models.Models; - -namespace Business -{ - public class ProductBusiness - { - private ProductContext productContext; - - public List 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(); - } - } - } - - } -} diff --git a/LuminousSales/Business/RolesBusiness.cs b/LuminousSales/Business/RolesBusiness.cs deleted file mode 100644 index 3509d4d..0000000 --- a/LuminousSales/Business/RolesBusiness.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Business -{ - public class RolesBusiness - { - private RoleContext roleContext; - } -} diff --git a/LuminousSales/Business/RolesToPermissionBusiness.cs b/LuminousSales/Business/RolesToPermissionBusiness.cs deleted file mode 100644 index c0704f9..0000000 --- a/LuminousSales/Business/RolesToPermissionBusiness.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace LuminousSales.Business -{ - public class RolesToPermissionBusiness - { - private RolesToPermissionContext rolesToPermissionContext; - - } -} diff --git a/LuminousSales/Business/StocksBusiness.cs b/LuminousSales/Business/StocksBusiness.cs deleted file mode 100644 index e39bbcf..0000000 --- a/LuminousSales/Business/StocksBusiness.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace LuminousSales.Business -{ - public class StocksBusiness - { - private StockContext stockContext; - } -} diff --git a/LuminousSales/Business/UsersBusiness.cs b/LuminousSales/Business/UsersBusiness.cs deleted file mode 100644 index bdbc5a1..0000000 --- a/LuminousSales/Business/UsersBusiness.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.ApplicationInsights.Extensibility.Implementation; - -namespace Business -{ - public class UsersBusiness - { - private UserContext userContext; - } -} diff --git a/LuminousSales/Business/UsersToRolesBusiness.cs b/LuminousSales/Business/UsersToRolesBusiness.cs deleted file mode 100644 index 0f08621..0000000 --- a/LuminousSales/Business/UsersToRolesBusiness.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Business -{ - public class UsersToRolesBusiness - { - private UsersToRolesContext usersToRolesContext; - - - } -} diff --git a/LuminousSales/Display/Display.csproj b/LuminousSales/Display/Display.csproj new file mode 100644 index 0000000..e4f4d1c --- /dev/null +++ b/LuminousSales/Display/Display.csproj @@ -0,0 +1,20 @@ + + + + Exe + netcoreapp3.1 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/LuminousSales/Display/Program.cs b/LuminousSales/Display/Program.cs new file mode 100644 index 0000000..3d0306f --- /dev/null +++ b/LuminousSales/Display/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Display +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/LuminousSales/LuminousSales.sln b/LuminousSales/LuminousSales.sln index 20c489c..da15b65 100644 --- a/LuminousSales/LuminousSales.sln +++ b/LuminousSales/LuminousSales.sln @@ -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 diff --git a/LuminousSales/LuminousSales/Data/DealContext.cs b/LuminousSales/LuminousSales/Data/DealContext.cs deleted file mode 100644 index 8f68a8b..0000000 --- a/LuminousSales/LuminousSales/Data/DealContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class DealContext : DbContext - { - public DealContext() : base() - { - - } - - public DbSet Deal { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - - } - } - diff --git a/LuminousSales/LuminousSales/Data/PermissionContext.cs b/LuminousSales/LuminousSales/Data/PermissionContext.cs deleted file mode 100644 index da5785e..0000000 --- a/LuminousSales/LuminousSales/Data/PermissionContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class PermissionContext: DbContext - { - public PermissionContext() : base() - { - - } - - - public DbSet Permission { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - } -} - diff --git a/LuminousSales/LuminousSales/Data/ProductContext.cs b/LuminousSales/LuminousSales/Data/ProductContext.cs deleted file mode 100644 index c8f62b2..0000000 --- a/LuminousSales/LuminousSales/Data/ProductContext.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class ProductContext : DbContext - { - public ProductContext():base() - { - - } - public DbSet Products { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - - } -} diff --git a/LuminousSales/LuminousSales/Data/RoleContext.cs b/LuminousSales/LuminousSales/Data/RoleContext.cs deleted file mode 100644 index 0ceae06..0000000 --- a/LuminousSales/LuminousSales/Data/RoleContext.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class RoleContext : DbContext - { - public RoleContext():base() - { - - } - - - public DbSet Role { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - } - - - - -} - diff --git a/LuminousSales/LuminousSales/Data/RolesToPermissionContext.cs b/LuminousSales/LuminousSales/Data/RolesToPermissionContext.cs deleted file mode 100644 index fac79e3..0000000 --- a/LuminousSales/LuminousSales/Data/RolesToPermissionContext.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class RolesToPermissionContext:DbContext - { - public RolesToPermissionContext():base() - { - - - } - - - public DbSet RoleToPermission { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - } - - } - diff --git a/LuminousSales/LuminousSales/Data/StockContext.cs b/LuminousSales/LuminousSales/Data/StockContext.cs deleted file mode 100644 index eb51bf2..0000000 --- a/LuminousSales/LuminousSales/Data/StockContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class StockContext:DbContext - { - public StockContext():base() - { - - - } - - public DbSet Stock { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - } -} - diff --git a/LuminousSales/LuminousSales/Data/UserContext.cs b/LuminousSales/LuminousSales/Data/UserContext.cs deleted file mode 100644 index 71ce98b..0000000 --- a/LuminousSales/LuminousSales/Data/UserContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class UserContext:DbContext - { - public UserContext():base() - { - - } - - public DbSet User { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server= (localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - - - } -} diff --git a/LuminousSales/LuminousSales/Data/UsersToRolesContext.cs b/LuminousSales/LuminousSales/Data/UsersToRolesContext.cs deleted file mode 100644 index eec7afa..0000000 --- a/LuminousSales/LuminousSales/Data/UsersToRolesContext.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.EntityFrameworkCore; -using Models.Models; - -namespace LuminousSales.Data -{ - public class UsersToRolesContext:DbContext - { - public UsersToRolesContext():base() - { - - } - public DbSet Role { get; set; } - - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=LuminousSales;Integrated Security = true;"); - } - - } -} diff --git a/LuminousSales/LuminousSales/Program.cs b/LuminousSales/LuminousSales/Program.cs deleted file mode 100644 index 2fb4f7b..0000000 --- a/LuminousSales/LuminousSales/Program.cs +++ /dev/null @@ -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); - - - } - } -} diff --git a/LuminousSales/Models/Configuration.cs b/LuminousSales/Models/Configuration.cs new file mode 100644 index 0000000..a6e9b92 --- /dev/null +++ b/LuminousSales/Models/Configuration.cs @@ -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"; + } +} diff --git a/LuminousSales/LuminousSales/LuminousSales.csproj b/LuminousSales/Models/Data.csproj similarity index 57% rename from LuminousSales/LuminousSales/LuminousSales.csproj rename to LuminousSales/Models/Data.csproj index df20564..0cd4ad8 100644 --- a/LuminousSales/LuminousSales/LuminousSales.csproj +++ b/LuminousSales/Models/Data.csproj @@ -1,15 +1,16 @@ - Exe - netcoreapp2.1 - - + netstandard2.1 - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + all @@ -17,9 +18,4 @@ - - - - - diff --git a/LuminousSales/Models/LuminousContext.cs b/LuminousSales/Models/LuminousContext.cs index a038eed..8e00dbd 100644 --- a/LuminousSales/Models/LuminousContext.cs +++ b/LuminousSales/Models/LuminousContext.cs @@ -1,22 +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 { get; set; } public DbSet Role { get; set; } public DbSet Permission { get; set; } public DbSet Product { get; set; } - public DbSet Deal{ get; set; } + public DbSet Deal { get; set; } public DbSet 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); } } } diff --git a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs b/LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs new file mode 100644 index 0000000..06b57e4 --- /dev/null +++ b/LuminousSales/Models/Migrations/20210310234527_IntialMigration.Designer.cs @@ -0,0 +1,191 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + 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") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Permission"); + }); + + modelBuilder.Entity("Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AmountInStock") + .HasColumnType("float"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("Models.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PermissionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PermissionId"); + + b.ToTable("Role"); + }); + + modelBuilder.Entity("Models.Models.Stock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("UserId"); + + b.ToTable("Stock"); + }); + + modelBuilder.Entity("Models.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Passcode") + .HasColumnType("nvarchar(max)"); + + b.Property("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 + } + } +} diff --git a/LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs b/LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs new file mode 100644 index 0000000..9757514 --- /dev/null +++ b/LuminousSales/Models/Migrations/20210310234527_IntialMigration.cs @@ -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(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) + }, + 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(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: true), + Passcode = table.Column(nullable: true), + UsersRolesId = table.Column(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(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(nullable: true), + Amount = table.Column(nullable: false), + ProductId = table.Column(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(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(nullable: true), + Amount = table.Column(nullable: false), + ProductId = table.Column(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"); + } + } +} diff --git a/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs new file mode 100644 index 0000000..712dd6d --- /dev/null +++ b/LuminousSales/Models/Migrations/LuminousContextModelSnapshot.cs @@ -0,0 +1,189 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + 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") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Permission"); + }); + + modelBuilder.Entity("Models.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AmountInStock") + .HasColumnType("float"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("Models.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PermissionId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PermissionId"); + + b.ToTable("Role"); + }); + + modelBuilder.Entity("Models.Models.Stock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Amount") + .HasColumnType("float"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("UserId"); + + b.ToTable("Stock"); + }); + + modelBuilder.Entity("Models.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Passcode") + .HasColumnType("nvarchar(max)"); + + b.Property("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 + } + } +} diff --git a/LuminousSales/Models/Models.csproj b/LuminousSales/Models/Models.csproj deleted file mode 100644 index 866b85d..0000000 --- a/LuminousSales/Models/Models.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netstandard2.0 - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/LuminousSales/Models/Models/Deal.cs b/LuminousSales/Models/Models/Deal.cs index 6835e79..5c34a72 100644 --- a/LuminousSales/Models/Models/Deal.cs +++ b/LuminousSales/Models/Models/Deal.cs @@ -1,24 +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 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; } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs b/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs index 16a06af..f44cc82 100644 --- a/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs +++ b/LuminousSales/Models/Models/Interfaces/IBaseSalesProperties.cs @@ -8,10 +8,6 @@ namespace Models.Models.Interfaces interface IBaseSalesProperties { User User { get; set; } - ICollection ProductsADeal { get; set;} double Amount { get; set; } - - byte[] GetTime(); - void SetTime(byte[] value); } } diff --git a/LuminousSales/Models/Models/Permission.cs b/LuminousSales/Models/Models/Permission.cs index 523351c..530faba 100644 --- a/LuminousSales/Models/Models/Permission.cs +++ b/LuminousSales/Models/Models/Permission.cs @@ -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 { get; set; } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Product.cs b/LuminousSales/Models/Models/Product.cs index 0e49343..efb3ee3 100644 --- a/LuminousSales/Models/Models/Product.cs +++ b/LuminousSales/Models/Models/Product.cs @@ -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 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 08811ad..676b5d6 100644 --- a/LuminousSales/Models/Models/Role.cs +++ b/LuminousSales/Models/Models/Role.cs @@ -6,9 +6,8 @@ namespace Models.Models { public class Role : IBaseProperties { + [Key] public int Id { get; set; } public string Name { get; set; } - public ICollection UsersWithTheRole { get; set; } - public ICollection RolesPermissions{ get; set; } } } \ No newline at end of file diff --git a/LuminousSales/Models/Models/Stock.cs b/LuminousSales/Models/Models/Stock.cs index 7c0407f..4fa5c16 100644 --- a/LuminousSales/Models/Models/Stock.cs +++ b/LuminousSales/Models/Models/Stock.cs @@ -8,20 +8,11 @@ namespace Models.Models { public class Stock : IBaseSalesProperties { + [Key] + public int Id { get; set; } public User User { get; set; } - public ICollection 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; } } diff --git a/LuminousSales/Models/Models/User.cs b/LuminousSales/Models/Models/User.cs index 3691aa5..74a302a 100644 --- a/LuminousSales/Models/Models/User.cs +++ b/LuminousSales/Models/Models/User.cs @@ -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 ItemsSoldByUser{ get; set; } - public ICollection ItemsStockedByUser { get; set; } + public virtual Role UsersRoles { get; set; } } }