diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln
index 40331d9..1be10f8 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop.sln
+++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln
@@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImple
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{5934B6B0-3EA1-4AA5-9A2D-144CDC7D4DB0}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{A51B81E4-9010-46BF-B17B-58B6F7A59FF9}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{A51B81E4-9010-46BF-B17B-58B6F7A59FF9}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,6 +47,10 @@ Global
{A51B81E4-9010-46BF-B17B-58B6F7A59FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51B81E4-9010-46BF-B17B-58B6F7A59FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51B81E4-9010-46BF-B17B-58B6F7A59FF9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F4FDBF1E-8279-406D-ADF0-F1FFDF1C88E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
index 3eaaccd..b7f797c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj
@@ -12,8 +12,7 @@
-
-
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
new file mode 100644
index 0000000..e7ba125
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
@@ -0,0 +1,32 @@
+using BlacksmithWorkshopDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+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= LAPTOP-0F602TLC;Initial Catalog=BlacksmithWorkshopDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
+ }
+
+ base.OnConfiguring(optionsBuilder);
+ }
+
+ public virtual DbSet WorkPieces { set; get; }
+
+ public virtual DbSet Manufactures { set; get; }
+
+ public virtual DbSet ManufactureWorkPieces { set; get; }
+
+ public virtual DbSet Orders { set; get; }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
new file mode 100644
index 0000000..7042ec6
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabaseImplement.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs
new file mode 100644
index 0000000..bb2612c
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Manufacture.cs
@@ -0,0 +1,119 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+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; }
+
+ public Dictionary? _manufactureWorkPieces = null;
+
+ //это поле не будет "мапиться" в бд
+ [NotMapped]
+ public Dictionary ManufactureWorkPieces
+ {
+ get
+ {
+ if (_manufactureWorkPieces == null)
+ {
+ _manufactureWorkPieces = WorkPieces
+ .ToDictionary(recPC => recPC.WorkPieceId, recPC => (recPC.WorkPiece as IWorkPieceModel, recPC.Count));
+ }
+
+ return _manufactureWorkPieces;
+ }
+ }
+
+ //для реализации связи многие ко многим с заготовками
+ [ForeignKey("ManufactureId")]
+ public virtual List WorkPieces { get; set; } = new();
+
+ [ForeignKey("ManufactureId")]
+ 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,
+ WorkPieces = model.ManufactureWorkPieces.Select(x => new ManufactureWorkPiece
+ {
+ WorkPiece = context.WorkPieces.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,
+ ManufactureWorkPieces = ManufactureWorkPieces
+ };
+
+ Dictionary IManufactureModel.ManufactureWorkPieces => throw new NotImplementedException();
+
+ public void UpdateWorkPieces(BlacksmithWorkshopDatabase context, ManufactureBindingModel model)
+ {
+ var manufactureWorkPieces = context.ManufactureWorkPieces.Where(rec => rec.ManufactureId == model.Id).ToList();
+
+ if (manufactureWorkPieces != null && manufactureWorkPieces.Count > 0)
+ {
+ // удалили те, которых нет в модели
+ context.ManufactureWorkPieces.RemoveRange(manufactureWorkPieces.Where(rec => !model.ManufactureWorkPieces.ContainsKey(rec.ManufactureId)));
+ context.SaveChanges();
+
+ // обновили количество у существующих записей
+ foreach (var updateManufacture in manufactureWorkPieces)
+ {
+ updateManufacture.Count = model.ManufactureWorkPieces[updateManufacture.ManufactureId].Item2;
+ model.ManufactureWorkPieces.Remove(updateManufacture.ManufactureId);
+ }
+
+ context.SaveChanges();
+ }
+
+ var manufacture = context.Manufactures.First(x => x.Id == Id);
+
+ foreach (var pc in model.ManufactureWorkPieces)
+ {
+ context.ManufactureWorkPieces.Add(new ManufactureWorkPiece
+ {
+ Manufacture = manufacture,
+ WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key),
+ Count = pc.Value.Item2
+ });
+
+ context.SaveChanges();
+ }
+
+ _manufactureWorkPieces = null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs
new file mode 100644
index 0000000..dbe90f6
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/ManufactureWorkPiece.cs
@@ -0,0 +1,27 @@
+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 ManufactureWorkPiece
+ {
+ public int Id { get; set; }
+
+ [Required]
+ public int ManufactureId { get; set; }
+
+ [Required]
+ public int WorkPieceId { get; set; }
+
+ [Required]
+ public int Count { get; set; }
+
+ public virtual WorkPiece WorkPiece { 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..7a8c5ad
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
@@ -0,0 +1,80 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Enums;
+using BlacksmithWorkshopDataModels.Models;
+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 Order : IOrderModel
+ {
+ public int Id { get; private set; }
+
+ [Required]
+ public int ManufactureId { get; private set; }
+
+ [Required]
+ public int Count { get; private set; }
+
+ [Required]
+ public double Sum { get; private set; }
+
+ [Required]
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ [Required]
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ //для передачи названия изделия
+ public virtual Manufacture Manufacture { get; set; }
+
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Order()
+ {
+ Id = model.Id,
+ ManufactureId = model.ManufactureId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ Status = model.Status;
+ DateImplement = model.DateImplement;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ManufactureId = ManufactureId,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement,
+ ManufactureName = Manufacture.ManufactureName
+ };
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs
new file mode 100644
index 0000000..19b0238
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/WorkPiece.cs
@@ -0,0 +1,71 @@
+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;
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopContracts.ViewModels;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class WorkPiece : IWorkPieceModel
+ {
+ public int Id { get; private set; }
+
+ [Required]
+ public string WorkPieceName { get; private set; } = string.Empty;
+
+ [Required]
+ public double Cost { get; set; }
+
+ //для реализации связи многие ко многим с изделиями
+ [ForeignKey("WorkPieceId")]
+ public virtual List ManufactureWorkPieces { get; set; } = new();
+
+ public static WorkPiece? Create(WorkPieceBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new WorkPiece()
+ {
+ Id = model.Id,
+ WorkPieceName = model.WorkPieceName,
+ Cost = model.Cost
+ };
+ }
+
+ public static WorkPiece Create(WorkPieceViewModel model)
+ {
+ return new WorkPiece
+ {
+ Id = model.Id,
+ WorkPieceName = model.WorkPieceName,
+ Cost = model.Cost
+ };
+ }
+
+ public void Update(WorkPieceBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ WorkPieceName = model.WorkPieceName;
+ Cost = model.Cost;
+ }
+
+ public WorkPieceViewModel GetViewModel => new()
+ {
+ Id = Id,
+ WorkPieceName = WorkPieceName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
index b65badc..c1033f7 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj
@@ -7,6 +7,7 @@
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj
index 9b80a97..51677ef 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj
@@ -1,25 +1,28 @@
-
- WinExe
- net6.0-windows
- enable
- true
- enable
-
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+ enable
+
-
-
-
-
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
-
+
+
-
+
-
\ No newline at end of file
+