18 Commits

Author SHA1 Message Date
batgo6o
8578b62989 Added constructors and base classses to Models 2021-03-14 10:17:13 +02:00
batgo6o
b45909ab63 EF Models created 2021-03-11 01:47:22 +02:00
Aneliya Konarcheva
f8ee73f50b commit new library 2021-03-07 13:09:15 +02:00
Aneliya Konarcheva
76f84a6afa commited manu changes 2021-03-07 12:25:58 +02:00
batgo6o
03740b08bc Fixed DbContext 2021-03-07 12:14:15 +02:00
Aneliya Konarcheva
6de2d1db6a commit changes 2 2021-03-07 12:07:45 +02:00
Aneliya Konarcheva
982ff0da15 commit changes 1 2021-03-07 11:59:17 +02:00
Aneliya Konarcheva
b2215cdd8f commit changes 2021-03-07 11:45:59 +02:00
Aneliya Konarcheva
04f5e9e455 Merge branch 'Models' into main 2021-03-07 11:35:49 +02:00
Aneliya Konarcheva
58f470ffbc private atributes 2021-03-07 11:17:43 +02:00
Aneliya Konarcheva
ee776460b2 methods buy and sell 2021-03-07 10:24:48 +02:00
Aneliya Konarcheva
219b0483f6 product business 2021-03-07 10:13:23 +02:00
Aneliya Konarcheva
39e9737476 class product 2021-03-07 10:04:51 +02:00
Aneliya Konarcheva
54e64cbb87 change 2021-03-07 09:46:54 +02:00
Dimitar Byalkov
8e0e5ad34a Merge pull request #1 from CapitalRhino/business-logic
Business logic
2021-03-07 09:44:07 +02:00
Aneliya Konarcheva
5a0c5411a8 commit changes 2021-03-06 21:10:40 +02:00
ani-konarcheva
438bffb502 commit Americans 2021-03-06 10:46:11 +02:00
Dimitar Byalkov
0692b6671b EntityFramework 2021-03-06 10:38:21 +02:00
33 changed files with 892 additions and 280 deletions

View File

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

View File

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

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 LuminousSales.Business;
using System;
namespace Display
{
class Program
{
static void Main(string[] args)
{
}
}
}

View File

@@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.31019.35 VisualStudioVersion = 16.0.31019.35
MinimumVisualStudioVersion = 10.0.40219.1 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 EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "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}") = "Display", "Display\Display.csproj", "{61E060C5-4360-4880-9ED7-6A139C988F0F}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -13,14 +15,18 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution 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.ActiveCfg = Debug|Any CPU
{40C482BF-B9C4-4460-BB1C-5A90959D1838}.Debug|Any CPU.Build.0 = 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 {40C482BF-B9C4-4460-BB1C-5A90959D1838}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40C482BF-B9C4-4460-BB1C-5A90959D1838}.Release|Any CPU.Build.0 = Release|Any CPU {40C482BF-B9C4-4460-BB1C-5A90959D1838}.Release|Any CPU.Build.0 = Release|Any CPU
{E1661853-3081-4C40-8E68-C063B3BC88A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

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

View File

@@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
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,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LuminousSales.Business
{
public class RolesBusiness
{
private RoleContext roleContext;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LuminousSales.Data.Model
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int AmountInStock { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Text;
using LuminousSales.Data.Model;
namespace LuminousSales.Data
{
public class ProductContext : DbContext
{
public ProductContext():base("name = ProductContext")
{
}
public DbSet<Product> Products { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
</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,49 @@
using Microsoft.EntityFrameworkCore; using Data;
using Microsoft.EntityFrameworkCore;
using Models.Models; using Models.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Models namespace Models
{ {
class LuminousContext : DbContext public class LuminousContext : DbContext
{ {
public LuminousContext(): base("name=LuminousContext") public LuminousContext()
{ {
} }
public LuminousContext(DbContextOptions options) : base(options)
{
}
public DbSet<User> User { get; set; } public DbSet<User> User { get; set; }
public DbSet<Role> Role { get; set; } public DbSet<Role> Role { get; set; }
public DbSet<Permission> Permission { get; set; } public DbSet<Permission> Permission { get; set; }
public DbSet<Product> Product { 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; } public DbSet<Stock> Stock { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseLazyLoadingProxies()
.UseSqlServer(Configuration.ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasIndex(user => new { user.Name, user.Password })
.IsUnique(true);
modelBuilder.Entity<Role>()
.HasIndex(role => new { role.Name })
.IsUnique(true);
modelBuilder.Entity<Permission>()
.HasIndex(permission => new { permission.Name })
.IsUnique(true);
modelBuilder.Entity<Product>()
.HasIndex(product => new { product.Name })
.IsUnique(true);
}
} }
} }

View File

@@ -0,0 +1,223 @@
// <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("20210314081427_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<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
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")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("RoleId");
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<int?>("DealId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("StockId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DealId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("StockId");
b.ToTable("Product");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Role");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
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")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RoleId");
b.HasIndex("Name", "Password")
.IsUnique();
b.ToTable("User");
});
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.Permission", b =>
{
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.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,209 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations
{
public partial class IntialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Permission",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
RoleId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Permission", x => x.Id);
table.ForeignKey(
name: "FK_Permission_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
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: false),
Password = table.Column<string>(nullable: false),
RoleId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
table.ForeignKey(
name: "FK_User_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Deal",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Deal", x => x.Id);
table.ForeignKey(
name: "FK_Deal_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Stock",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stock", x => x.Id);
table.ForeignKey(
name: "FK_Stock_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
Price = table.Column<double>(nullable: false),
AmountInStock = table.Column<double>(nullable: false),
DealId = table.Column<int>(nullable: true),
StockId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
table.ForeignKey(
name: "FK_Product_Deal_DealId",
column: x => x.DealId,
principalTable: "Deal",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Product_Stock_StockId",
column: x => x.StockId,
principalTable: "Stock",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Deal_UserId",
table: "Deal",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Permission_Name",
table: "Permission",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
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",
table: "Stock",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_User_RoleId",
table: "User",
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: "User");
migrationBuilder.DropTable(
name: "Role");
}
}
}

View File

@@ -0,0 +1,221 @@
// <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<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
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")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int?>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("RoleId");
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<int?>("DealId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("StockId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DealId");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("StockId");
b.ToTable("Product");
});
modelBuilder.Entity("Models.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Role");
});
modelBuilder.Entity("Models.Models.Stock", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<byte[]>("Time")
.IsConcurrencyToken()
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("rowversion");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
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")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RoleId");
b.HasIndex("Name", "Password")
.IsUnique();
b.ToTable("User");
});
modelBuilder.Entity("Models.Models.Deal", b =>
{
b.HasOne("Models.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.Permission", b =>
{
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.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Models.Models.User", b =>
{
b.HasOne("Models.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -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<Product> Products)
{
this.User = User;
this.Products = Products;
}
[Key]
public int Id { get; set; }
[Required]
public virtual User User { get; set; }
[Required]
public virtual ICollection<Product> Products { get; set; }
[Timestamp]
[Required]
public byte[] Time { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -1,15 +1,13 @@
using Models.Models.Interfaces; using Data.Base;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Models.Models namespace Models.Models
{ {
public class Deal : IBaseSalesProperties public class Deal : BaseSales
{ {
public User User { get; set; } public Deal() : base(){}
public ICollection<Product> ProductsADeal { get; set; } public Deal(User User, ICollection<Product> Products) : base(User, Products){}
public double Amount { get; set; }
[Timestamp]
public byte[] Time { get; set; }
} }
} }

View File

@@ -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; }
}
}

View File

@@ -1,15 +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; }
ICollection<Product> ProductsADeal { get; set;}
double Amount { get; set; }
public byte[] Time { get; set; }
}
}

View File

@@ -1,11 +1,12 @@
using Models.Models.Interfaces; using Data.Base;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Models.Models namespace Models.Models
{ {
public class Permission : IBaseProperties public class Permission : BaseUserManagmentEntity
{ {
public int Id { get; set; } public Permission() : base(){}
public Permission(string Name) : base(Name){}
public string Name { get; set; }
} }
} }

View File

@@ -1,12 +1,30 @@
using Models.Models.Interfaces; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Models.Models 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; } public int Id { get; set; }
[Required]
public string Name { get; set; } public string Name { get; set; }
[Required]
public double Price { get; set; } public double Price { get; set; }
public double AvailableInStock { get; set; } [Required]
public double AmountInStock { get; set; }
} }
} }

View File

@@ -1,14 +1,17 @@
using Models.Models.Interfaces; using Data.Base;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Models.Models namespace Models.Models
{ {
public class Role : IBaseProperties public class Role : BaseUserManagmentEntity
{ {
public int Id { get; set; } public Role() : base(){}
public string Name { get; set; } public Role(string Name, ICollection<Permission> Permissions) : base(Name)
public ICollection<User> UsersWithTheRole { get; set; } {
public ICollection<Permission> RolesPermissions{ get; set; } this.Permissions = Permissions;
}
[Required]
public virtual ICollection<Permission> Permissions { get; set; }
} }
} }

View File

@@ -1,4 +1,4 @@
using Models.Models.Interfaces; using Data.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@@ -6,12 +6,9 @@ using System.Text;
namespace Models.Models namespace Models.Models
{ {
class Stock : IBaseSalesProperties public class Stock : BaseSales
{ {
public User User { get; set; } public Stock() : base(){}
public ICollection<Product> ProductsADeal { get; set; } public Stock(User User, ICollection<Product> Products) : base(User, Products){}
public double Amount { get; set; }
[Timestamp]
public byte[] Time { get; set; }
} }
} }

View File

@@ -1,17 +1,22 @@
using Models.Models.Interfaces; using Data.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
namespace Models.Models namespace Models.Models
{ {
public class User : IBaseProperties public class User : BaseUserManagmentEntity
{ {
public int Id { get; set; } public User() : base() { }
public string Name { get; set; } public User(string Name, string Password, Role Role) : base(Name)
public string Passcode { get; set; } {
public Role Role { get; set; } this.Password = Password;
public ICollection<Deal> ItemsSoldByUser{ get; set; } this.Role = Role;
public ICollection<Product> ItemsStockedByUser { get; set; } }
[Required]
public string Password { get; set; }
[Required]
public virtual Role Role { get; set; }
} }
} }