From 6b1213db9361aa243cc5cf402c62b2e58d80b7a0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 8 Apr 2023 19:10:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B1=20=D0=B8=20=D0=B2=D1=8C=D1=8E?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FactoryDatabase.cs | 36 ++ .../Implements/ComponentStorage.cs | 84 ++++ .../Implements/EngenierStorage.cs | 83 +++ .../Implements/LatheBusyStorage.cs | 81 +++ .../Implements/LatheStorage.cs | 95 ++++ .../Implements/MasterStorage.cs | 105 ++++ .../Implements/PlanStorage.cs | 101 ++++ .../Implements/ReinforcedStorage.cs | 100 ++++ .../Implements/StageStorage.cs | 104 ++++ .../20230402190902_initmigration.Designer.cs | 447 +++++++++++++++++ .../20230402190902_initmigration.cs | 350 +++++++++++++ .../20230402191341_initmigration1.Designer.cs | 473 ++++++++++++++++++ .../20230402191341_initmigration1.cs | 78 +++ .../20230402191647_initmigration2.Designer.cs | 472 +++++++++++++++++ .../20230402191647_initmigration2.cs | 129 +++++ .../FactoryDatabaseModelSnapshot.cs | 469 +++++++++++++++++ .../Models/Component.cs | 61 +++ .../Models/Engenier.cs | 58 +++ .../FactoryDatabaseImplement/Models/Lathe.cs | 92 ++++ .../Models/LatheBusy.cs | 51 ++ .../Models/LatheReinforced.cs | 25 + .../FactoryDatabaseImplement/Models/Master.cs | 58 +++ .../FactoryDatabaseImplement/Models/Plan.cs | 147 ++++++ .../Models/PlanComponents.cs | 27 + .../Models/PlanLathe.cs | 27 + .../Models/Reinforced.cs | 102 ++++ .../Models/ReinforcedComponent.cs | 27 + .../FactoryDatabaseImplement/Models/Stage.cs | 47 ++ FactoryView/FactoryView/Form1.Designer.cs | 46 ++ FactoryView/FactoryView/Form1.cs | 15 + FactoryView/FactoryView/Form1.resx | 60 +++ FactoryView/FactoryView/Program.cs | 41 ++ 32 files changed, 4091 insertions(+) create mode 100644 FactoryView/FactoryDatabaseImplement/FactoryDatabase.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/ComponentStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/EngenierStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/LatheBusyStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/LatheStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/MasterStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/PlanStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/ReinforcedStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Implements/StageStorage.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.Designer.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.Designer.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.Designer.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Migrations/FactoryDatabaseModelSnapshot.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Component.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Engenier.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Lathe.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/LatheBusy.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/LatheReinforced.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Master.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Plan.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/PlanComponents.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/PlanLathe.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Reinforced.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/ReinforcedComponent.cs create mode 100644 FactoryView/FactoryDatabaseImplement/Models/Stage.cs create mode 100644 FactoryView/FactoryView/Form1.Designer.cs create mode 100644 FactoryView/FactoryView/Form1.cs create mode 100644 FactoryView/FactoryView/Form1.resx create mode 100644 FactoryView/FactoryView/Program.cs diff --git a/FactoryView/FactoryDatabaseImplement/FactoryDatabase.cs b/FactoryView/FactoryDatabaseImplement/FactoryDatabase.cs new file mode 100644 index 0000000..9279503 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/FactoryDatabase.cs @@ -0,0 +1,36 @@ +using FactoryDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement +{ + public class FactoryDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlServer(); //todo привязывай данные + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Masters { set; get; } + public virtual DbSet Engeniers { set; get; } + public virtual DbSet Reinforceds { set; get; } + public virtual DbSet Components { set; get; } + public virtual DbSet ReinforcedComponents { set; get; } + public virtual DbSet Lathes { set; get; } + public virtual DbSet LatheBusies { set; get; } + public virtual DbSet LatheReinforcedes { set; get; } + public virtual DbSet Plans { set; get; } + public virtual DbSet Stages { set; get; } + public virtual DbSet PlanLathes { set; get; } + public virtual DbSet PlanComponents { set; get; } + + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/ComponentStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..73175d4 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,84 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.Components.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new FactoryDatabase(); + 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 FactoryDatabase(); + 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 FactoryDatabase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new FactoryDatabase(); + 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 FactoryDatabase(); + 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/FactoryView/FactoryDatabaseImplement/Implements/EngenierStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/EngenierStorage.cs new file mode 100644 index 0000000..a5701ec --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/EngenierStorage.cs @@ -0,0 +1,83 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class EngenierStorage + { + public EngenierViewModel? Delete(EngenierBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Engeniers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Engeniers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public EngenierViewModel? GetElement(EngenierSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new FactoryDatabase(); + return context.Engeniers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(EngenierSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.Engeniers.Where(x => x.Fio.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.Engeniers.Select(x => x.GetViewModel).ToList(); + } + + public EngenierViewModel? Insert(EngenierBindingModel model) + { + var newEngenier = Engenier.Create(model); + if (newEngenier == null) + { + return null; + } + using var context = new FactoryDatabase(); + context.Engeniers.Add(newEngenier); + context.SaveChanges(); + return newEngenier.GetViewModel; + } + + public EngenierViewModel? Update(EngenierBindingModel model) + { + using var context = new FactoryDatabase(); + var engenier = context.Engeniers.FirstOrDefault(x => x.Id == model.Id); + if (engenier == null) + { + return null; + } + engenier.Update(model); + context.SaveChanges(); + return engenier.GetViewModel; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/LatheBusyStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/LatheBusyStorage.cs new file mode 100644 index 0000000..1568835 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/LatheBusyStorage.cs @@ -0,0 +1,81 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class LatheBusyStorage : ILatheBusyStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.LatheBusies.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(LatheBusySearchModel model) + { + if (model.Id is null) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.LatheBusies.Where(x => x.Percent == model.Percent).Select(x => x.GetViewModel).ToList(); + } + + public LatheBusyViewModel? GetElement(LatheBusySearchModel model) + { + if (model.Id is null) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.LatheBusies.FirstOrDefault(x => x.Percent == model.Percent)?.GetViewModel; + } + + public LatheBusyViewModel? Insert(LatheBusyBindingModel model) + { + var newLatheBusy = LatheBusy.Create(new FactoryDatabase(), model); + if (newLatheBusy == null) + { + return null; + } + using var context = new FactoryDatabase(); + context.LatheBusies.Add(newLatheBusy); + context.SaveChanges(); + return newLatheBusy.GetViewModel; + } + + public LatheBusyViewModel? Update(LatheBusyBindingModel model) + { + using var context = new FactoryDatabase(); + var latheBusy = context.LatheBusies.FirstOrDefault(x => x.Id == model.Id); + if (latheBusy == null) + { + return null; + } + latheBusy.Update(model); + context.SaveChanges(); + return latheBusy.GetViewModel; + } + + public LatheBusyViewModel? Delete(LatheBusyBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.LatheBusies.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.LatheBusies.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/LatheStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/LatheStorage.cs new file mode 100644 index 0000000..ba8cfc5 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/LatheStorage.cs @@ -0,0 +1,95 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class LatheStorage : ILatheStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.Lathes.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(LatheSearchModel model) + { + if (string.IsNullOrEmpty(model.LatheName)) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.Lathes.Where(x => x.LatheName.Contains(model.LatheName)).Select(x => x.GetViewModel).ToList(); + } + + public LatheViewModel? GetElement(LatheSearchModel model) + { + if (string.IsNullOrEmpty(model.LatheName) && !model.Id.HasValue) + { + return null; + } + using var context = new FactoryDatabase(); + return context.Lathes.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.LatheName) && x.LatheName == model.LatheName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public LatheViewModel? Insert(LatheBindingModel model) + { + var newLathe = Lathe.Create(new FactoryDatabase(), model); + if (newLathe == null) + { + return null; + } + using var context = new FactoryDatabase(); + context.Lathes.Add(newLathe); + context.SaveChanges(); + return newLathe.GetViewModel; + } + + public LatheViewModel? Update(LatheBindingModel model) + { + using var context = new FactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var Lathe = context.Lathes.FirstOrDefault(rec => rec.Id == model.Id); + if (Lathe == null) + { + return null; + } + Lathe.Update(model); + context.SaveChanges(); + Lathe.UpdateComponents(context, model); + transaction.Commit(); + return Lathe.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public LatheViewModel? Delete(LatheBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Lathes.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Lathes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/MasterStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/MasterStorage.cs new file mode 100644 index 0000000..36fdea9 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/MasterStorage.cs @@ -0,0 +1,105 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class MasterStorage : IMasterStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + + return context.Masters + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(MasterSearchModel model) + { + if (string.IsNullOrEmpty(model.Email)) + { + return new(); + } + + using var context = new FactoryDatabase(); + + return context.Masters + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public MasterViewModel? GetElement(MasterSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + + using var context = new FactoryDatabase(); + + return context.Masters + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public MasterViewModel? Insert(MasterBindingModel model) + { + using var context = new FactoryDatabase(); + + var newMaster = Master.Create(context, model); + + if (newMaster == null) + { + return null; + } + + context.Masters.Add(newMaster); + context.SaveChanges(); + + return newMaster.GetViewModel; + } + + public MasterViewModel? Update(MasterBindingModel model) + { + using var context = new FactoryDatabase(); + var master = context.Masters.FirstOrDefault(x => x.Id == model.Id); + + if (master == null) + { + return null; + } + + master.Update(model); + context.SaveChanges(); + + return master.GetViewModel; + } + + public MasterViewModel? Delete(MasterBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Masters.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Masters.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/PlanStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/PlanStorage.cs new file mode 100644 index 0000000..5470472 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/PlanStorage.cs @@ -0,0 +1,101 @@ +using Microsoft.EntityFrameworkCore; +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FactoryDatabaseImplement; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class PlanStorage : IPlanStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe).ToList() + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(PlanSearchModel model) + { + if (string.IsNullOrEmpty(model.PlanName)) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe) + .Where(x => x.PlanName.Contains(model.PlanName)).ToList().Select(x => x.GetViewModel).ToList(); + } + + public PlanViewModel? GetElement(PlanSearchModel model) + { + if (string.IsNullOrEmpty(model.PlanName) && !model.Id.HasValue) + { + return null; + } + using var context = new FactoryDatabase(); + return context.Plans.Include(x => x.Components).ThenInclude(x => x.Component).Include(x => x.Lathes).ThenInclude(x => x.Lathe) + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.PlanName) && x.PlanName == model.PlanName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public PlanViewModel? Insert(PlanBindingModel model) + { + using var context = new FactoryDatabase(); + var newPlan = Plan.Create(context, model); + if (newPlan == null) + { + return null; + } + context.Plans.Add(newPlan); + context.SaveChanges(); + return newPlan.GetViewModel; + } + + public PlanViewModel? Update(PlanBindingModel model) + { + using var context = new FactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var Plan = context.Plans.FirstOrDefault(rec => rec.Id == model.Id); + if (Plan == null) + { + return null; + } + Plan.Update(model); + context.SaveChanges(); + Plan.UpdateComponents(context, model); + Plan.UpdateLathes(context, model); + transaction.Commit(); + return Plan.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public PlanViewModel? Delete(PlanBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Plans.Include(x => x.Components).Include(x => x.Lathes).FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Plans.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/ReinforcedStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..ec9b913 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,100 @@ +using Microsoft.EntityFrameworkCore; +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FactoryDatabaseImplement; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class ReinforcedStorage : IReinforcedStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component).ToList() + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + return new(); + } + using var context = new FactoryDatabase(); + return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component) + .Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).ToList().Select(x => x.GetViewModel).ToList(); + } + + public ReinforcedViewModel? GetElement(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue) + { + return null; + } + using var context = new FactoryDatabase(); + return context.Reinforceds.Include(x => x.Components).ThenInclude(x => x.Component) + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ReinforcedViewModel? Insert(ReinforcedBindingModel model) + { + using var context = new FactoryDatabase(); + var newReinforced = Reinforced.Create(context, model); + if (newReinforced == null) + { + return null; + } + context.Reinforceds.Add(newReinforced); + context.SaveChanges(); + return newReinforced.GetViewModel; + } + + public ReinforcedViewModel? Update(ReinforcedBindingModel model) + { + using var context = new FactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var Reinforced = context.Reinforceds.FirstOrDefault(rec => rec.Id == model.Id); + if (Reinforced == null) + { + return null; + } + Reinforced.Update(model); + context.SaveChanges(); + Reinforced.UpdateComponents(context, model); + transaction.Commit(); + return Reinforced.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ReinforcedViewModel? Delete(ReinforcedBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Reinforceds.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Reinforceds.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Implements/StageStorage.cs b/FactoryView/FactoryDatabaseImplement/Implements/StageStorage.cs new file mode 100644 index 0000000..6b5e499 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Implements/StageStorage.cs @@ -0,0 +1,104 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using FactoryDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Implements +{ + public class StageStorage : IStageStorage + { + public List GetFullList() + { + using var context = new FactoryDatabase(); + + return context.Stages + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(StageSearchModel model) + { + if (model.Id is null) + { + return new(); + } + + using var context = new FactoryDatabase(); + + return context.Stages + .Where(x => x.Id.Equals(model.Id)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public StageViewModel? GetElement(StageSearchModel model) + { + if (model.Id is null) + { + return new(); + } + + using var context = new FactoryDatabase(); + + return context.Stages + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + public StageViewModel? Insert(StageBindingModel model) + { + using var context = new FactoryDatabase(); + + var newStage = Stage.Create(context, model); + + if (newStage == null) + { + return null; + } + + context.Stages.Add(newStage); + context.SaveChanges(); + + return newStage.GetViewModel; + } + + public StageViewModel? Update(StageBindingModel model) + { + using var context = new FactoryDatabase(); + var Stage = context.Stages.FirstOrDefault(x => x.Id == model.Id); + + if (Stage == null) + { + return null; + } + + Stage.Update(model); + context.SaveChanges(); + + return Stage.GetViewModel; + } + + public StageViewModel? Delete(StageBindingModel model) + { + using var context = new FactoryDatabase(); + var element = context.Stages.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Stages.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.Designer.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.Designer.cs new file mode 100644 index 0000000..f842240 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.Designer.cs @@ -0,0 +1,447 @@ +// +using FactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FactoryDatabase))] + [Migration("20230402190902_initmigration")] + partial class initmigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FactoryDatabaseImplement.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.Property("EnginierId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Engeniers"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BusyId") + .HasColumnType("int"); + + b.Property("LatheName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BusyId"); + + b.HasIndex("MasterId"); + + b.ToTable("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Percent") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("LatheBusies"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("LatheReinforcedes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Plans"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanLathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EngenierId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EngenierId"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanId") + .HasColumnType("int"); + + b.Property("ReinforsedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null) + .WithMany("Lathes") + .HasForeignKey("BusyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Master", null) + .WithMany("LatheId") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany("Reinforceds") + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Components") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany() + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Lathes") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Engenier", null) + .WithMany("Reinforceds") + .HasForeignKey("EngenierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Navigation("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Navigation("LatheId"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Navigation("Components"); + + b.Navigation("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.cs new file mode 100644 index 0000000..3156c85 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402190902_initmigration.cs @@ -0,0 +1,350 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FactoryDatabaseImplement.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), + EnginierId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Engeniers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Engeniers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LatheBusies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Percent = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LatheBusies", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Masters", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Masters", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Plans", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanName = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Plans", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Stages", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanId = table.Column(type: "int", nullable: false), + ReinforsedId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stages", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Reinforceds", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + EngenierId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reinforceds", x => x.Id); + table.ForeignKey( + name: "FK_Reinforceds_Engeniers_EngenierId", + column: x => x.EngenierId, + principalTable: "Engeniers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Lathes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + LatheName = table.Column(type: "nvarchar(max)", nullable: false), + MasterId = table.Column(type: "int", nullable: false), + BusyId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Lathes", x => x.Id); + table.ForeignKey( + name: "FK_Lathes_LatheBusies_BusyId", + column: x => x.BusyId, + principalTable: "LatheBusies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Lathes_Masters_MasterId", + column: x => x.MasterId, + principalTable: "Masters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlanComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlanComponents", x => x.Id); + table.ForeignKey( + name: "FK_PlanComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PlanComponents_Plans_PlanId", + column: x => x.PlanId, + principalTable: "Plans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ReinforcedComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReinforcedComponents", x => x.Id); + table.ForeignKey( + name: "FK_ReinforcedComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReinforcedComponents_Reinforceds_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforceds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "LatheReinforcedes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + LatheId = table.Column(type: "int", nullable: false), + ReinforcedId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LatheReinforcedes", x => x.Id); + table.ForeignKey( + name: "FK_LatheReinforcedes_Lathes_LatheId", + column: x => x.LatheId, + principalTable: "Lathes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LatheReinforcedes_Reinforceds_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforceds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlanLathes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlanId = table.Column(type: "int", nullable: false), + LatheId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlanLathes", x => x.Id); + table.ForeignKey( + name: "FK_PlanLathes_Lathes_LatheId", + column: x => x.LatheId, + principalTable: "Lathes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PlanLathes_Plans_PlanId", + column: x => x.PlanId, + principalTable: "Plans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_LatheReinforcedes_LatheId", + table: "LatheReinforcedes", + column: "LatheId"); + + migrationBuilder.CreateIndex( + name: "IX_LatheReinforcedes_ReinforcedId", + table: "LatheReinforcedes", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_Lathes_BusyId", + table: "Lathes", + column: "BusyId"); + + migrationBuilder.CreateIndex( + name: "IX_Lathes_MasterId", + table: "Lathes", + column: "MasterId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanComponents_ComponentId", + table: "PlanComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanComponents_PlanId", + table: "PlanComponents", + column: "PlanId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanLathes_LatheId", + table: "PlanLathes", + column: "LatheId"); + + migrationBuilder.CreateIndex( + name: "IX_PlanLathes_PlanId", + table: "PlanLathes", + column: "PlanId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ComponentId", + table: "ReinforcedComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ReinforcedId", + table: "ReinforcedComponents", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_Reinforceds_EngenierId", + table: "Reinforceds", + column: "EngenierId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "LatheReinforcedes"); + + migrationBuilder.DropTable( + name: "PlanComponents"); + + migrationBuilder.DropTable( + name: "PlanLathes"); + + migrationBuilder.DropTable( + name: "ReinforcedComponents"); + + migrationBuilder.DropTable( + name: "Stages"); + + migrationBuilder.DropTable( + name: "Lathes"); + + migrationBuilder.DropTable( + name: "Plans"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Reinforceds"); + + migrationBuilder.DropTable( + name: "LatheBusies"); + + migrationBuilder.DropTable( + name: "Masters"); + + migrationBuilder.DropTable( + name: "Engeniers"); + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.Designer.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.Designer.cs new file mode 100644 index 0000000..6fba762 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.Designer.cs @@ -0,0 +1,473 @@ +// +using System; +using FactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FactoryDatabase))] + [Migration("20230402191341_initmigration1")] + partial class initmigration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FactoryDatabaseImplement.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.Property("EnginierId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Engeniers"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BusyId") + .HasColumnType("int"); + + b.Property("LatheName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BusyId"); + + b.HasIndex("MasterId"); + + b.ToTable("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Percent") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("LatheBusies"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("LatheReinforcedes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.Property("PlanName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("Plans"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanLathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EngenierId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EngenierId"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanId") + .HasColumnType("int"); + + b.Property("ReinforsedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null) + .WithMany("Lathes") + .HasForeignKey("BusyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Master", null) + .WithMany("LatheId") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany("Reinforceds") + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", null) + .WithMany("Plans") + .HasForeignKey("ComponentId"); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", null) + .WithMany("Plans") + .HasForeignKey("PlanId"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Components") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany() + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Lathes") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Engenier", null) + .WithMany("Reinforceds") + .HasForeignKey("EngenierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("Plans"); + + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Navigation("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Navigation("LatheId"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Navigation("Components"); + + b.Navigation("Lathes"); + + b.Navigation("Plans"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.cs new file mode 100644 index 0000000..75a5c30 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191341_initmigration1.cs @@ -0,0 +1,78 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + /// + public partial class initmigration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ComponentId", + table: "Plans", + type: "int", + nullable: true); + + migrationBuilder.AddColumn( + name: "PlanId", + table: "Plans", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Plans_ComponentId", + table: "Plans", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_Plans_PlanId", + table: "Plans", + column: "PlanId"); + + migrationBuilder.AddForeignKey( + name: "FK_Plans_Components_ComponentId", + table: "Plans", + column: "ComponentId", + principalTable: "Components", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Plans_Plans_PlanId", + table: "Plans", + column: "PlanId", + principalTable: "Plans", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Plans_Components_ComponentId", + table: "Plans"); + + migrationBuilder.DropForeignKey( + name: "FK_Plans_Plans_PlanId", + table: "Plans"); + + migrationBuilder.DropIndex( + name: "IX_Plans_ComponentId", + table: "Plans"); + + migrationBuilder.DropIndex( + name: "IX_Plans_PlanId", + table: "Plans"); + + migrationBuilder.DropColumn( + name: "ComponentId", + table: "Plans"); + + migrationBuilder.DropColumn( + name: "PlanId", + table: "Plans"); + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.Designer.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.Designer.cs new file mode 100644 index 0000000..03582e1 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.Designer.cs @@ -0,0 +1,472 @@ +// +using System; +using FactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FactoryDatabase))] + [Migration("20230402191647_initmigration2")] + partial class initmigration2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FactoryDatabaseImplement.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.Property("EnginierId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Engeniers"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BusyId") + .HasColumnType("int"); + + b.Property("LatheName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BusyId"); + + b.HasIndex("MasterId"); + + b.ToTable("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Percent") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("LatheBusies"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("LatheReinforcedes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Plans"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanLathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EngenierId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EngenierId"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.Property("ReinforsedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null) + .WithMany("Lathes") + .HasForeignKey("BusyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Master", null) + .WithMany("LatheId") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany("Reinforceds") + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Components") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany() + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Lathes") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Engenier", null) + .WithMany("Reinforceds") + .HasForeignKey("EngenierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", null) + .WithMany("Stages") + .HasForeignKey("ComponentId"); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", null) + .WithMany("Stages") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + + b.Navigation("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Navigation("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Navigation("LatheId"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Navigation("Components"); + + b.Navigation("Lathes"); + + b.Navigation("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.cs b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.cs new file mode 100644 index 0000000..6895af5 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/20230402191647_initmigration2.cs @@ -0,0 +1,129 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + /// + public partial class initmigration2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Plans_Components_ComponentId", + table: "Plans"); + + migrationBuilder.DropForeignKey( + name: "FK_Plans_Plans_PlanId", + table: "Plans"); + + migrationBuilder.DropIndex( + name: "IX_Plans_ComponentId", + table: "Plans"); + + migrationBuilder.DropIndex( + name: "IX_Plans_PlanId", + table: "Plans"); + + migrationBuilder.DropColumn( + name: "ComponentId", + table: "Plans"); + + migrationBuilder.DropColumn( + name: "PlanId", + table: "Plans"); + + migrationBuilder.AddColumn( + name: "ComponentId", + table: "Stages", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Stages_ComponentId", + table: "Stages", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_Stages_PlanId", + table: "Stages", + column: "PlanId"); + + migrationBuilder.AddForeignKey( + name: "FK_Stages_Components_ComponentId", + table: "Stages", + column: "ComponentId", + principalTable: "Components", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Stages_Plans_PlanId", + table: "Stages", + column: "PlanId", + principalTable: "Plans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Stages_Components_ComponentId", + table: "Stages"); + + migrationBuilder.DropForeignKey( + name: "FK_Stages_Plans_PlanId", + table: "Stages"); + + migrationBuilder.DropIndex( + name: "IX_Stages_ComponentId", + table: "Stages"); + + migrationBuilder.DropIndex( + name: "IX_Stages_PlanId", + table: "Stages"); + + migrationBuilder.DropColumn( + name: "ComponentId", + table: "Stages"); + + migrationBuilder.AddColumn( + name: "ComponentId", + table: "Plans", + type: "int", + nullable: true); + + migrationBuilder.AddColumn( + name: "PlanId", + table: "Plans", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Plans_ComponentId", + table: "Plans", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_Plans_PlanId", + table: "Plans", + column: "PlanId"); + + migrationBuilder.AddForeignKey( + name: "FK_Plans_Components_ComponentId", + table: "Plans", + column: "ComponentId", + principalTable: "Components", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Plans_Plans_PlanId", + table: "Plans", + column: "PlanId", + principalTable: "Plans", + principalColumn: "Id"); + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Migrations/FactoryDatabaseModelSnapshot.cs b/FactoryView/FactoryDatabaseImplement/Migrations/FactoryDatabaseModelSnapshot.cs new file mode 100644 index 0000000..cebff87 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Migrations/FactoryDatabaseModelSnapshot.cs @@ -0,0 +1,469 @@ +// +using System; +using FactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FactoryDatabase))] + partial class FactoryDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FactoryDatabaseImplement.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.Property("EnginierId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Engeniers"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BusyId") + .HasColumnType("int"); + + b.Property("LatheName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BusyId"); + + b.HasIndex("MasterId"); + + b.ToTable("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Percent") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("LatheBusies"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("LatheReinforcedes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Plans"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("LatheId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LatheId"); + + b.HasIndex("PlanId"); + + b.ToTable("PlanLathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EngenierId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EngenierId"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.Property("ReinforsedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PlanId"); + + b.ToTable("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.LatheBusy", null) + .WithMany("Lathes") + .HasForeignKey("BusyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Master", null) + .WithMany("LatheId") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheReinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany("Reinforceds") + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanComponents", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Components") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.PlanLathe", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Lathe", "Lathe") + .WithMany() + .HasForeignKey("LatheId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", "Plan") + .WithMany("Lathes") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lathe"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Engenier", null) + .WithMany("Reinforceds") + .HasForeignKey("EngenierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FactoryDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Stage", b => + { + b.HasOne("FactoryDatabaseImplement.Models.Component", null) + .WithMany("Stages") + .HasForeignKey("ComponentId"); + + b.HasOne("FactoryDatabaseImplement.Models.Plan", null) + .WithMany("Stages") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + + b.Navigation("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Engenier", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Lathe", b => + { + b.Navigation("Reinforceds"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.LatheBusy", b => + { + b.Navigation("Lathes"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Master", b => + { + b.Navigation("LatheId"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Plan", b => + { + b.Navigation("Components"); + + b.Navigation("Lathes"); + + b.Navigation("Stages"); + }); + + modelBuilder.Entity("FactoryDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Component.cs b/FactoryView/FactoryDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..cd5bec5 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Component.cs @@ -0,0 +1,61 @@ + +using FactoryContracts.BindingModels; +using FactoryContracts.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; +using FactoryDataModels.Models; + +namespace FactoryDatabaseImplement.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; } + + [Required] + public int EnginierId { get; set; } + + [ForeignKey("ComponentId")] + public virtual List ReinforcedComponents { get; set; } = new(); + + [ForeignKey("ComponentId")] + public virtual List Stages { get; set; } = new(); + + + public static Component Create(ComponentBindingModel model) + { + return new Component + { + Id = model.Id, + ComponentName = model.ComponentName, + }; + } + + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + }; + + + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Engenier.cs b/FactoryView/FactoryDatabaseImplement/Models/Engenier.cs new file mode 100644 index 0000000..c3e510e --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Engenier.cs @@ -0,0 +1,58 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.Models; +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 FactoryDatabaseImplement.Models +{ + public class Engenier : IEngenierModel + { + public int Id { get; set; } + + [Required] + public string Fio { get; set; } = string.Empty; + + [Required] + public string Email { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [ForeignKey("EngenierId")] + public virtual List Reinforceds { get; set; } = new(); + + + public EngenierViewModel GetViewModel => new() + { + Id = Id, + Fio = Fio, + Email = Email, + Password = Password + }; + + public static Engenier Create(EngenierBindingModel model) + { + return new Engenier() + { + Id = model.Id, + Fio = model.Fio, + Email = model.Email, + Password = model.Password + }; + } + + public void Update(EngenierBindingModel model) + { + Fio = model.Fio; + Email = model.Email; + Password = model.Password; + } + } +} + diff --git a/FactoryView/FactoryDatabaseImplement/Models/Lathe.cs b/FactoryView/FactoryDatabaseImplement/Models/Lathe.cs new file mode 100644 index 0000000..18fc641 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Lathe.cs @@ -0,0 +1,92 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.Models; +using Microsoft.Data.SqlClient.DataClassification; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Models +{ + public class Lathe : ILatheModel + { + public int Id { get; set; } + [Required] + public string LatheName { get; set; } = String.Empty; + [Required] + public int MasterId { get; set; } + [Required] + public int BusyId { get; set; } + [Required] + private Dictionary? _latheReinforcedes = null; + + [NotMapped] + public Dictionary LatheReinforcedes { + get { + if (_latheReinforcedes == null) + { + _latheReinforcedes = Reinforceds.ToDictionary(recLR => recLR.ReinforcedId, recLR => + (recLR.Reinforced as IReinforcedModel, recLR.Count)); + } + return _latheReinforcedes; + } + } + [ForeignKey("LatheId")] + public virtual List Reinforceds { get; set; } = new(); + + public static Lathe Create(FactoryDatabase context, LatheBindingModel model) + { + return new Lathe() + { + Id = model.Id, + LatheName = model.LatheName, + }; + } + + public void Update(LatheBindingModel model) + { + Id = model.Id; + LatheName = model.LatheName; + } + + public LatheViewModel GetViewModel => new() + { + Id = Id, + LatheName = LatheName, + }; + + public void UpdateComponents(FactoryDatabase context, LatheBindingModel model) + { + var LatheReinforsed = context.LatheReinforcedes.Where(rec => rec.LatheId == model.Id).ToList(); + if (LatheReinforsed != null && LatheReinforsed.Count > 0) + { + context.LatheReinforcedes.RemoveRange(LatheReinforsed.Where(rec => !model.LatheReinforcedes.ContainsKey(rec.LatheId))); + context.SaveChanges(); + LatheReinforsed = context.LatheReinforcedes.Where(rec => rec.LatheId == model.Id).ToList(); + foreach (var updateComponent in LatheReinforsed) + { + updateComponent.Count = model.LatheReinforcedes[updateComponent.LatheId].Item2; + model.LatheReinforcedes.Remove(updateComponent.LatheId); + } + context.SaveChanges(); + } + var Lathe = context.Lathes.First(x => x.Id == Id); + foreach (var pc in model.LatheReinforcedes) + { + context.LatheReinforcedes.Add(new LatheReinforced + { + Lathe = Lathe, + Reinforced = context.Reinforceds.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _latheReinforcedes = null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/LatheBusy.cs b/FactoryView/FactoryDatabaseImplement/Models/LatheBusy.cs new file mode 100644 index 0000000..c99b6b5 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/LatheBusy.cs @@ -0,0 +1,51 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.Models; +using Microsoft.Data.SqlClient.DataClassification; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Models +{ + public class LatheBusy : ILatheBusyModel + { + public int Id { get; set; } + [Required] + public int Percent { get; set; } + + [ForeignKey("BusyId")] + public virtual List Lathes { get; set; } = new(); + [Required] + public DateTime Date { get; set; } + + public static LatheBusy Create(FactoryDatabase context, LatheBusyBindingModel model) + { + return new LatheBusy() + { + Id = model.Id, + Percent = model.Percent, + }; + } + + public void Update(LatheBusyBindingModel model) + { + Id = model.Id; + Id = model.Id; + Percent = model.Percent; + } + + public LatheBusyViewModel GetViewModel => new() + { + Id = Id, + Percent = Percent, + }; + + + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/LatheReinforced.cs b/FactoryView/FactoryDatabaseImplement/Models/LatheReinforced.cs new file mode 100644 index 0000000..eab8983 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/LatheReinforced.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Models +{ + public class LatheReinforced + { + public int Id { get; set; } + [Required] + public int LatheId { get; set; } + [Required] + public int ReinforcedId { get; set; } + [Required] + public int Count { get; set; } + + public virtual Lathe Lathe { get; set; } = new(); + + public virtual Reinforced Reinforced { get; set; } = new(); + + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Master.cs b/FactoryView/FactoryDatabaseImplement/Models/Master.cs new file mode 100644 index 0000000..6383b6b --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Master.cs @@ -0,0 +1,58 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Models +{ + public class Master : IMasterModel + { + public int Id { get; set; } + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public string Fio { get; set; } = string.Empty; + + [Required] + public string Email { get; set; } = string.Empty; + + [ForeignKey("MasterId")] + public virtual List LatheId { get; set; } = new(); + + public static Master Create(FactoryDatabase context, MasterBindingModel model) + { + return new Master() + { + Id = model.Id, + Fio = model.Fio, + Email = model.Email, + Password = model.Password + }; + } + + public void Update(MasterBindingModel model) + { + Id = model.Id; + Fio = model.Fio; + Email = model.Email; + Password = model.Password; + } + + public MasterViewModel GetViewModel => new() + { + Id = Id, + Fio = Fio, + Email = Email, + Password = Password + }; + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Plan.cs b/FactoryView/FactoryDatabaseImplement/Models/Plan.cs new file mode 100644 index 0000000..aa7953e --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Plan.cs @@ -0,0 +1,147 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.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 FactoryDatabaseImplement.Models +{ + public class Plan : IPlanModel + { + public int Id { get; set; } + [Required] + public string PlanName { get; set; } = String.Empty; + + [Required] + public DateTime date { get; set; } + + [Required] + private Dictionary? _planLathes { get; set; } = null; + + + [NotMapped] + public Dictionary PlanLathes + { + get + { + if (_planLathes == null) + { + _planLathes = Lathes.ToDictionary(recPL => recPL.LatheId, recPL => + (recPL.Lathe as ILatheModel, recPL.Count)); + } + return _planLathes; + } + } + + [ForeignKey("PlanId")] + public virtual List Lathes { get; set; } = new(); + + [Required] + private Dictionary _planComponents { get; set; } = null; + + [NotMapped] + public Dictionary PlanComponents + { + get + { + if (_planComponents == null) + { + _planComponents = Components.ToDictionary(recPL => recPL.ComponentId, recPL => + (recPL.Component as IComponentModel, recPL.Count)); + } + return _planComponents; + } + } + + [ForeignKey("PlanId")] + public virtual List Components { get; set; } = new(); + + public static Plan Create(FactoryDatabase context, PlanBindingModel model) + { + return new Plan() + { + Id = model.Id, + PlanName = model.PlanName, + }; + } + + [ForeignKey("PlanId")] + public virtual List Stages { get; set; } = new(); + + public void Update(PlanBindingModel model) + { + + PlanName = model.PlanName; + } + + public PlanViewModel GetViewModel => new() + { + Id = Id, + PlanName = PlanName, + }; + + + + public void UpdateLathes(FactoryDatabase context, PlanBindingModel model) + { + var PlanLathes = context.PlanLathes.Where(rec => rec.PlanId == model.Id).ToList(); + if (PlanLathes != null && PlanLathes.Count > 0) + { + context.PlanLathes.RemoveRange(PlanLathes.Where(rec => !model.PlanLathes.ContainsKey(rec.LatheId))); + context.SaveChanges(); + foreach (var updateComponent in PlanLathes) + { + updateComponent.Count = model.PlanLathes[updateComponent.LatheId].Item2; + model.PlanLathes.Remove(updateComponent.LatheId); + } + context.SaveChanges(); + } + var Plans = context.Plans.First(x => x.Id == Id); + foreach (var pc in model.PlanLathes) + { + context.PlanLathes.Add(new PlanLathe + { + Plan = Plans, + Lathe = context.Lathes.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _planLathes = null; + } + + public void UpdateComponents(FactoryDatabase context, PlanBindingModel model) + { + var PlanComponents = context.PlanComponents.Where(rec => rec.PlanId == model.Id).ToList(); + if (PlanComponents != null && PlanComponents.Count > 0) + { + context.PlanComponents.RemoveRange(PlanComponents.Where(rec => !model.PlanComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + PlanComponents = context.PlanComponents.Where(rec => rec.PlanId == model.Id).ToList(); + foreach (var updateComponent in PlanComponents) + { + updateComponent.Count = model.PlanComponents[updateComponent.ComponentId].Item2; + model.PlanComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var Plans = context.Plans.First(x => x.Id == Id); + foreach (var pc in model.PlanComponents) + { + context.PlanComponents.Add(new PlanComponents + { + Plan = Plans, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _planComponents = null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/PlanComponents.cs b/FactoryView/FactoryDatabaseImplement/Models/PlanComponents.cs new file mode 100644 index 0000000..56069fa --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/PlanComponents.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 FactoryDatabaseImplement.Models +{ + public class PlanComponents + { + public int Id { get; set; } + + [Required] + public int PlanId { get; set; } + + [Required] + public int ComponentId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Component Component { get; set; } = new(); + + public virtual Plan Plan { get; set; } = new(); + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/PlanLathe.cs b/FactoryView/FactoryDatabaseImplement/Models/PlanLathe.cs new file mode 100644 index 0000000..374f2ff --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/PlanLathe.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 FactoryDatabaseImplement.Models +{ + public class PlanLathe + { + public int Id { get; set; } + + [Required] + public int PlanId { get; set; } + + [Required] + public int LatheId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Plan Plan { get; set; } = new(); + + public virtual Lathe Lathe { get; set; } = new(); + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Reinforced.cs b/FactoryView/FactoryDatabaseImplement/Models/Reinforced.cs new file mode 100644 index 0000000..21cb0c4 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Reinforced.cs @@ -0,0 +1,102 @@ +using FactoryDataModels.Models; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +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 FactoryDatabaseImplement.Models +{ + public class Reinforced : IReinforcedModel + { + public int Id { get; set; } + + [Required] + public string ReinforcedName { get; set; } = string.Empty; + + [Required] + public double Price { get; set; } + + [Required] + public int EngenierId { get; set; } + + private Dictionary? _reinforcedComponents = null; + + [NotMapped] + public Dictionary ReinforcedComponents + { + get + { + if (_reinforcedComponents == null) + { + _reinforcedComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count)); + } + return _reinforcedComponents; + } + } + + [ForeignKey("ReinforcedId")] + public virtual List Components { get; set; } = new(); + + + public static Reinforced Create(FactoryDatabase context, ReinforcedBindingModel model) + { + return new Reinforced() + { + Id = model.Id, + ReinforcedName = model.ReinforcedName, + Components = model.ReinforcedComponents.Select(x => new ReinforcedComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(ReinforcedBindingModel model) + { + ReinforcedName = model.ReinforcedName; + } + + public ReinforcedViewModel GetViewModel => new() + { + Id = Id, + ReinforcedName = ReinforcedName, + ReinforcedComponents = ReinforcedComponents + }; + + public void UpdateComponents(FactoryDatabase context, ReinforcedBindingModel model) + { + var ReinforcedComponents = context.ReinforcedComponents.Where(rec => rec.ReinforcedId == model.Id).ToList(); + if (ReinforcedComponents != null && ReinforcedComponents.Count > 0) + { + context.ReinforcedComponents.RemoveRange(ReinforcedComponents.Where(rec => !model.ReinforcedComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + ReinforcedComponents = context.ReinforcedComponents.Where(rec => rec.ReinforcedId == model.Id).ToList(); + foreach (var updateComponent in ReinforcedComponents) + { + updateComponent.Count = model.ReinforcedComponents[updateComponent.ComponentId].Item2; + model.ReinforcedComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var Reinforced = context.Reinforceds.First(x => x.Id == Id); + foreach (var pc in model.ReinforcedComponents) + { + context.ReinforcedComponents.Add(new ReinforcedComponent + { + Reinforced = Reinforced, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _reinforcedComponents = null; + } + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/ReinforcedComponent.cs b/FactoryView/FactoryDatabaseImplement/Models/ReinforcedComponent.cs new file mode 100644 index 0000000..baf7b6d --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/ReinforcedComponent.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 FactoryDatabaseImplement.Models +{ + public class ReinforcedComponent + { + public int Id { get; set; } + + [Required] + public int ReinforcedId { get; set; } + + [Required] + public int ComponentId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Component Component { get; set; } = new(); + + public virtual Reinforced Reinforced { get; set; } = new(); + } +} diff --git a/FactoryView/FactoryDatabaseImplement/Models/Stage.cs b/FactoryView/FactoryDatabaseImplement/Models/Stage.cs new file mode 100644 index 0000000..b2e09a1 --- /dev/null +++ b/FactoryView/FactoryDatabaseImplement/Models/Stage.cs @@ -0,0 +1,47 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryDatabaseImplement.Models +{ + public class Stage : IStageModel + { + public int Id { get; set; } + + [Required] + public int PlanId { get; set; } + + [Required] + public int ReinforsedId { get; set; } + + public static Stage Create(FactoryDatabase context, StageBindingModel model) + { + return new Stage() + { + Id = model.Id, + ReinforsedId = model.ReinforsedId, + PlanId = model.PlanId + }; + } + + public void Update(StageBindingModel model) + { + ReinforsedId = model.ReinforsedId; + PlanId = model.PlanId; + } + + + public StageViewModel GetViewModel => new() + { + Id = Id, + ReinforsedId = ReinforsedId, + PlanId = PlanId + }; + } +} diff --git a/FactoryView/FactoryView/Form1.Designer.cs b/FactoryView/FactoryView/Form1.Designer.cs new file mode 100644 index 0000000..0adbff8 --- /dev/null +++ b/FactoryView/FactoryView/Form1.Designer.cs @@ -0,0 +1,46 @@ +namespace Factory +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + SuspendLayout(); + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "Form1"; + Text = "Form1"; + Load += Form1_Load; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/FactoryView/FactoryView/Form1.cs b/FactoryView/FactoryView/Form1.cs new file mode 100644 index 0000000..4651b32 --- /dev/null +++ b/FactoryView/FactoryView/Form1.cs @@ -0,0 +1,15 @@ +namespace Factory +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/FactoryView/FactoryView/Form1.resx b/FactoryView/FactoryView/Form1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FactoryView/FactoryView/Form1.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FactoryView/FactoryView/Program.cs b/FactoryView/FactoryView/Program.cs new file mode 100644 index 0000000..457394e --- /dev/null +++ b/FactoryView/FactoryView/Program.cs @@ -0,0 +1,41 @@ +using Factory; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + +namespace FactoryView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + + public static ServiceProvider? ServiceProvider => _serviceProvider; + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font; + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + + services.AddTransient(); + } + } +} \ No newline at end of file