diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln
index 92a182c..e078500 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop.sln
+++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln
@@ -16,7 +16,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessL
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{EDD43E5F-0F85-4EEE-A23E-A6CB69B46952}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{36F843C7-79F6-47F5-B331-C610B098CE4F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{36F843C7-79F6-47F5-B331-C610B098CE4F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{B0480235-7C98-437D-92E1-C7560116555A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -48,6 +50,10 @@ Global
{36F843C7-79F6-47F5-B331-C610B098CE4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36F843C7-79F6-47F5-B331-C610B098CE4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36F843C7-79F6-47F5-B331-C610B098CE4F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B0480235-7C98-437D-92E1-C7560116555A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0480235-7C98-437D-92E1-C7560116555A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0480235-7C98-437D-92E1-C7560116555A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0480235-7C98-437D-92E1-C7560116555A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
index 072b1ac..21732a7 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
@@ -9,12 +9,23 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
index e6011ba..e75171f 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
@@ -7,6 +7,16 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
index 79490b5..165882c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -7,6 +7,16 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModel/BlacksmithWorkshopDataModel.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDataModel/BlacksmithWorkshopDataModel.csproj
index 45fc359..3472c0a 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModel/BlacksmithWorkshopDataModel.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModel/BlacksmithWorkshopDataModel.csproj
@@ -7,6 +7,16 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
new file mode 100644
index 0000000..4c2d095
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
@@ -0,0 +1,31 @@
+using BlacksmithWorkshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement
+{
+ public class BlacksmithWorkshopDatabase : DbContext
+ {
+ protected override void OnConfiguring(DbContextOptionsBuilder
+optionsBuilder)
+ {
+ if (optionsBuilder.IsConfigured == false)
+ {
+ optionsBuilder.UseSqlServer(@"Data
+Source=CHESHIR\SQLEXPRESS;Initial BlacksmithWorkshopDatabaseFull;Integrated
+Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
+ }
+ base.OnConfiguring(optionsBuilder);
+ }
+ public virtual DbSet Components { set; get; }
+ public virtual DbSet Manufactures { set; get; }
+ public virtual DbSet ManufactureComponents { set; get; }
+ public virtual DbSet Orders { set; get; }
+ }
+
+}
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
new file mode 100644
index 0000000..bd26c58
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
@@ -0,0 +1,27 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..4db089d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,90 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDatabaseImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Components
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ComponentSearchModel
+ model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Components
+ .Where(x => x.ComponentName.Contains(model.ComponentName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Components
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
+ model.ComponentName) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ context.Components.Add(newComponent);
+ context.SaveChanges();
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var component = context.Components.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ context.SaveChanges();
+ return component.GetViewModel;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var element = context.Components.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Components.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs
new file mode 100644
index 0000000..47a7b1a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs
@@ -0,0 +1,110 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Implements
+{
+ public class ManufactureStorage :IManufactureStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Manufactures
+ .Include(x => x.Components)
+ .ThenInclude(x => x.Component)
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ManufactureSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ManufactureName))
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Manufactures
+ .Include(x => x.Components)
+ .ThenInclude(x => x.Component)
+ .Where(x => x.ManufactureName.Contains(model.ManufactureName))
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ManufactureViewModel? GetElement(ManufactureSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ManufactureName) &&
+ !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Manufactures
+ .Include(x => x.Components)
+ .ThenInclude(x => x.Component)
+ .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) &&
+ x.ManufactureName == model.ManufactureName) ||
+ (model.Id.HasValue && x.Id ==
+ model.Id))
+ ?.GetViewModel;
+ }
+ public ManufactureViewModel? Insert(ManufactureBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var newProduct = Manufacture.Create(context, model);
+ if (newProduct == null)
+ {
+ return null;
+ }
+ context.Manufactures.Add(newProduct);
+ context.SaveChanges();
+ return newProduct.GetViewModel;
+ }
+ public ManufactureViewModel? Update(ManufactureBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ using var transaction = context.Database.BeginTransaction();
+ try
+ {
+ var product = context.Manufactures.FirstOrDefault(rec =>
+ rec.Id == model.Id);
+ if (product == null)
+ {
+ return null;
+ }
+ product.Update(model);
+ context.SaveChanges();
+ product.UpdateComponents(context, model);
+ transaction.Commit();
+ return product.GetViewModel;
+ }
+ catch
+ {
+ transaction.Rollback();
+ throw;
+ }
+ }
+ public ManufactureViewModel? Delete(ManufactureBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var element = context.Manufactures
+ .Include(x => x.Components)
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Manufactures.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..400d08a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs
@@ -0,0 +1,77 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Implements
+{
+ internal class OrderStorage : IOrderStorage
+ {
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var element = context.Orders
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Orders.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Orders
+ .FirstOrDefault(x =>
+ (model.Id.HasValue && x.Id ==
+ model.Id))
+ ?.GetViewModel;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Orders
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Orders
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ throw new NotImplementedException();
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.Designer.cs
new file mode 100644
index 0000000..d65ae40
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.Designer.cs
@@ -0,0 +1,177 @@
+//
+using System;
+using BlacksmithWorkshopDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace BlacksmithWorkshopDatabaseImplement.Migrations
+{
+ [DbContext(typeof(BlacksmithWorkshopDatabase))]
+ [Migration("20230226193259_InitMigration")]
+ partial class InitMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ManufactureName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Manufactures");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.Property("ProductId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("ProductId");
+
+ b.ToTable("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateImplement")
+ .HasColumnType("datetime2");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.Property("ManufactureName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ProductId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ProductId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component")
+ .WithMany("ManufactureComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
+ .WithMany("Components")
+ .HasForeignKey("ProductId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Manufacture");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
+ .WithMany("Orders")
+ .HasForeignKey("ProductId");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.cs
new file mode 100644
index 0000000..07d23da
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20230226193259_InitMigration.cs
@@ -0,0 +1,127 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace BlacksmithWorkshopDatabaseImplement.Migrations
+{
+ ///
+ public partial class InitMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Components",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ComponentName = table.Column(type: "nvarchar(max)", nullable: false),
+ Cost = table.Column(type: "float", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Components", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Manufactures",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ManufactureName = table.Column(type: "nvarchar(max)", nullable: false),
+ Price = table.Column(type: "float", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Manufactures", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "ManufactureComponents",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ManufactureId = table.Column(type: "int", nullable: false),
+ ComponentId = table.Column(type: "int", nullable: false),
+ Count = table.Column(type: "int", nullable: false),
+ ProductId = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_ManufactureComponents", x => x.Id);
+ table.ForeignKey(
+ name: "FK_ManufactureComponents_Components_ComponentId",
+ column: x => x.ComponentId,
+ principalTable: "Components",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_ManufactureComponents_Manufactures_ProductId",
+ column: x => x.ProductId,
+ principalTable: "Manufactures",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Orders",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ManufactureId = table.Column(type: "int", nullable: false),
+ Count = table.Column(type: "int", nullable: false),
+ Sum = table.Column(type: "float", nullable: false),
+ ManufactureName = table.Column(type: "nvarchar(max)", nullable: false),
+ Status = table.Column(type: "int", nullable: false),
+ DateCreate = table.Column(type: "datetime2", nullable: false),
+ DateImplement = table.Column(type: "datetime2", nullable: true),
+ ProductId = table.Column(type: "int", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Orders", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Orders_Manufactures_ProductId",
+ column: x => x.ProductId,
+ principalTable: "Manufactures",
+ principalColumn: "Id");
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ManufactureComponents_ComponentId",
+ table: "ManufactureComponents",
+ column: "ComponentId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ManufactureComponents_ProductId",
+ table: "ManufactureComponents",
+ column: "ProductId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ProductId",
+ table: "Orders",
+ column: "ProductId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "ManufactureComponents");
+
+ migrationBuilder.DropTable(
+ name: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Components");
+
+ migrationBuilder.DropTable(
+ name: "Manufactures");
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..ba6152b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs
@@ -0,0 +1,174 @@
+//
+using System;
+using BlacksmithWorkshopDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace BlacksmithWorkshopDatabaseImplement.Migrations
+{
+ [DbContext(typeof(BlacksmithWorkshopDatabase))]
+ partial class BlacksmithWorkshopDatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ManufactureName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Manufactures");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.Property("ProductId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("ProductId");
+
+ b.ToTable("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateImplement")
+ .HasColumnType("datetime2");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.Property("ManufactureName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ProductId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ProductId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component")
+ .WithMany("ManufactureComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
+ .WithMany("Components")
+ .HasForeignKey("ProductId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Manufacture");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
+ .WithMany("Orders")
+ .HasForeignKey("ProductId");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs
new file mode 100644
index 0000000..1ec8832
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Component.cs
@@ -0,0 +1,64 @@
+using BlacksmithWorkshopDataModel.Models;
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class Component : IComponentModel
+ {
+
+ public int Id { get; private set; }
+ [Required]
+ public string ComponentName { get; private set; } = string.Empty;
+ [Required]
+ public double Cost { get; set; }
+ [ForeignKey("ComponentId")]
+ public virtual List ManufactureComponents { get; set; } =
+ new();
+ public static Component? Create(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public static Component Create(ComponentViewModel model)
+ {
+ return new Component
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+ }
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs
new file mode 100644
index 0000000..96823e4
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs
@@ -0,0 +1,103 @@
+using BlacksmithWorkshopDataModel.Models;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopContracts.BindingModels;
+
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class Manufacture : IManufactureModel
+ {
+ public int Id { get; set; }
+ [Required]
+ public string ManufactureName { get; set; } = string.Empty;
+ [Required]
+ public double Price { get; set; }
+ private Dictionary? _manufactureComponents =
+ null;
+ [NotMapped]
+ public Dictionary ManufactureComponents
+ {
+ get
+ {
+ if (_manufactureComponents == null)
+ {
+ _manufactureComponents = Components
+ .ToDictionary(recPC => recPC.ComponentId, recPC =>
+ (recPC.Component as IComponentModel, recPC.Count));
+ }
+ return _manufactureComponents;
+ }
+ }
+ [ForeignKey("ProductId")]
+ public virtual List Components { get; set; } = new();
+ [ForeignKey("ProductId")]
+ public virtual List Orders { get; set; } = new();
+ public static Manufacture Create(BlacksmithWorkshopDatabase context,
+ ManufactureBindingModel model)
+ {
+ return new Manufacture()
+ {
+ Id = model.Id,
+ ManufactureName = model.ManufactureName,
+ Price = model.Price,
+ Components = model.ManufactureComponents.Select(x => new
+ ManufactureComponent
+ {
+ Component = context.Components.First(y => y.Id == x.Key),
+ Count = x.Value.Item2
+ }).ToList()
+ };
+ }
+ public void Update(ManufactureBindingModel model)
+ {
+ ManufactureName = model.ManufactureName;
+ Price = model.Price;
+ }
+ public ManufactureViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ManufactureName = ManufactureName,
+ Price = Price,
+ ManufactureComponents = ManufactureComponents
+ };
+ public void UpdateComponents(BlacksmithWorkshopDatabase context,
+ ManufactureBindingModel model)
+ {
+ var manufactureComponents = context.ManufactureComponents.Where(rec => rec.ManufactureId == model.Id).ToList();
+ if (manufactureComponents != null && manufactureComponents.Count > 0)
+ { // удалили те, которых нет в модели
+ context.ManufactureComponents.RemoveRange(manufactureComponents.Where(rec
+ => !model.ManufactureComponents.ContainsKey(rec.ComponentId)));
+ context.SaveChanges();
+ // обновили количество у существующих записей
+ foreach (var updateComponent in manufactureComponents)
+ {
+ updateComponent.Count =
+ model.ManufactureComponents[updateComponent.ComponentId].Item2;
+ model.ManufactureComponents.Remove(updateComponent.ComponentId);
+ }
+ context.SaveChanges();
+ }
+ var manufacture = context.Manufactures.First(x => x.Id == Id);
+ foreach (var pc in model.ManufactureComponents)
+ {
+ context.ManufactureComponents.Add(new ManufactureComponent
+ {
+ Manufacture = manufacture,
+ Component = context.Components.First(x => x.Id == pc.Key),
+ Count = pc.Value.Item2
+ });
+ context.SaveChanges();
+ }
+ _manufactureComponents = null;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs
new file mode 100644
index 0000000..e372bf6
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureComponent.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class ManufactureComponent
+ {
+ public int Id { get; set; }
+ [Required]
+ public int ManufactureId { get; set; }
+ [Required]
+ public int ComponentId { get; set; }
+ [Required]
+ public int Count { get; set; }
+ public virtual Component Component { get; set; } = new();
+ public virtual Manufacture Manufacture { get; set; } = new();
+ }
+
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
new file mode 100644
index 0000000..9fc654b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
@@ -0,0 +1,79 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModel.Enums;
+using BlacksmithWorkshopDataModel.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int ManufactureId { get; private set; }
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+ public string ManufactureName { get; private set; } = string.Empty;
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ ManufactureId = model.ManufactureId,
+ ManufactureName = model.ManufactureName,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+
+
+ };
+ }
+
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Id = model.Id;
+ ManufactureId = model.ManufactureId;
+ ManufactureName = model.ManufactureName;
+ Count = model.Count;
+ Sum = model.Sum;
+ Status = model.Status;
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
+
+
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ManufactureId = ManufactureId,
+ ManufactureName = ManufactureName,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
index a21d158..bd26c58 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
@@ -6,6 +6,19 @@
enable
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
index 18034b1..1d28130 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj
@@ -7,6 +7,16 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+