From 303d20af01f74ad709351506955c8624c4d223a8 Mon Sep 17 00:00:00 2001 From: sardq Date: Tue, 28 May 2024 23:02:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=D1=80=D1=83=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/PlanProductionStorage.cs | 36 ++++++---- .../Models/PlanProduction.cs | 5 +- .../Models/PlanProductionWorkpiece.cs | 4 +- .../Controllers/HomeController.cs | 45 +++++++----- .../ConnectionPlanProductionWorkpiece.cshtml | 69 +++++++++---------- .../Views/Home/PlanProduction.cshtml | 32 ++++++++- .../Views/Home/Workpiece.cshtml | 2 +- 7 files changed, 120 insertions(+), 73 deletions(-) diff --git a/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs b/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs index 040004e..aa06610 100644 --- a/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs @@ -4,6 +4,7 @@ using FactoryContracts.SearchModels; using FactoryContracts.StoragesContracts; using FactoryContracts.ViewModels; using FactoryDatabaseImplement.Models; +using System.Reflection.PortableExecutable; namespace FactoryDatabaseImplement.Implements { @@ -97,19 +98,30 @@ namespace FactoryDatabaseImplement.Implements public PlanProductionViewModel? Update(PlanProductionBindingModel model) { using var context = new FactoryDatabase(); - var order = context.PlanProductions - .Include(x => x.Client) - .Include(x => x.Workpieces) - .ThenInclude(x => x.Workpiece) - .FirstOrDefault(x => x.Id == model.Id); - if (order == null) + using var transaction = context.Database.BeginTransaction(); + try { - return null; - } - order.Update(model); - context.SaveChanges(); - return order.GetViewModel; - } + var plan = context.PlanProductions + .Include(x => x.Client) + .Include(x => x.Workpieces) + .ThenInclude(x => x.Workpiece) + .FirstOrDefault(x => x.Id == model.Id); + if (plan == null) + { + return null; + } + plan.Update(model); + context.SaveChanges(); + plan.UpdateWorkpieces(context, model); + transaction.Commit(); + return plan.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } } } \ No newline at end of file diff --git a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs index d7ffa90..5195162 100644 --- a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs +++ b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs @@ -84,11 +84,12 @@ namespace FactoryDatabaseImplement.Models }; public void UpdateWorkpieces(FactoryDatabase context, PlanProductionBindingModel model) { + var planProductionWorkpieces = context.PlanProductionWorkpieces.Where(rec => rec.PlanProductionId == model.Id).ToList(); - if (planProductionWorkpieces != null && planProductionWorkpieces.Count > 0) + if (planProductionWorkpieces != null && planProductionWorkpieces.Count > 0 && model.PlanProductionWorkpieces.Count > 0) { context.PlanProductionWorkpieces.RemoveRange(planProductionWorkpieces.Where(rec => !model.PlanProductionWorkpieces.ContainsKey(rec.WorkpieceId))); - context.SaveChanges(); + context.SaveChanges(); foreach (var updateWorkpiece in planProductionWorkpieces) { updateWorkpiece.Count = model.PlanProductionWorkpieces[updateWorkpiece.WorkpieceId].Item2; diff --git a/Factory/FactoryDatabaseImplement/Models/PlanProductionWorkpiece.cs b/Factory/FactoryDatabaseImplement/Models/PlanProductionWorkpiece.cs index 2edc666..b184689 100644 --- a/Factory/FactoryDatabaseImplement/Models/PlanProductionWorkpiece.cs +++ b/Factory/FactoryDatabaseImplement/Models/PlanProductionWorkpiece.cs @@ -15,8 +15,8 @@ namespace FactoryDatabaseImplement.Models [Required] public int Count { get; set; } - public virtual PlanProduction PlanProduction { get; set; } = new(); + public virtual PlanProduction PlanProduction { get; set; } - public virtual Workpiece Workpiece { get; set; } = new(); + public virtual Workpiece Workpiece { get; set; } } } \ No newline at end of file diff --git a/Factory/FactoryWorkerApp/Controllers/HomeController.cs b/Factory/FactoryWorkerApp/Controllers/HomeController.cs index a181e1c..350c207 100644 --- a/Factory/FactoryWorkerApp/Controllers/HomeController.cs +++ b/Factory/FactoryWorkerApp/Controllers/HomeController.cs @@ -155,6 +155,8 @@ namespace FactoryWorkerApp.Controllers [HttpGet] public IActionResult PlanProduction(int id) { + var workpieces = _logic.GetWorkpieces(Client.user!.Id); + ViewBag.AllWorkpieces = workpieces; if (id != 0) { var value = _logic.GetPlanProduction(id); @@ -186,27 +188,39 @@ namespace FactoryWorkerApp.Controllers { if (!IsLoggedIn) return RedirectToAction("Index"); - var plan = _logic.GetPlanProduction(id); - ViewBag.PlanProduction = plan; - var workpieces = _logic.GetWorkpieces(id); - return View(workpieces); + ViewBag.PlanProductions = _logic.GetPlanProductions(Client.user!.Id); + ViewBag.Workpieces = _logic.GetWorkpieces(Client.user!.Id); + return View(); } [HttpPost] - public IActionResult ConnectionPlanProductionWorkpiece(int planProductionId, int workpieceId) + public void ConnectionPlanProductionWorkpiece(int planId, int workpieceId, int count) { if (!IsLoggedIn) - return RedirectToAction("Index"); - var plan = _logic.GetPlanProduction(planProductionId); - if (plan == null) - return RedirectToAction("Index"); - PlanProductionBindingModel productBinding = new() { Id = planProductionId, Count = plan.Count, Deadline = plan.Deadline, ClientId= plan.ClientId, ProductionName= plan.ProductionName, PlanProductionWorkpieces = plan.PlanProductionWorkpieces}; - //productBinding.PlanProductionWorkpieces.Add(_logic.GetWorkpiece(workpieceId)); - _logic.UpdatePlanProduction(productBinding); - return RedirectToAction("Index"); + Response.Redirect("Index"); + PlanProductionViewModel planProduction = _logic.GetPlanProduction(planId)!; + WorkpieceViewModel workpiece = _logic.GetWorkpiece(workpieceId)!; + if(planProduction.PlanProductionWorkpieces.ContainsKey(workpieceId)) + planProduction.PlanProductionWorkpieces[workpieceId] = (workpiece, planProduction.PlanProductionWorkpieces[workpieceId].Item2 + count); + else + planProduction.PlanProductionWorkpieces.Add(workpieceId, (workpiece, count)); + _logic.UpdatePlanProduction( + new PlanProductionBindingModel + { + Id = planId, + ClientId = Client.user!.Id, + Count = planProduction.Count, + Deadline = planProduction.Deadline, + PlanProductionWorkpieces = planProduction.PlanProductionWorkpieces, + ProductionName = planProduction.ProductionName, + } + ); - } + Response.Redirect("Index"); - [HttpGet] + + } + + [HttpGet] public IActionResult Reports() { return View(); @@ -304,7 +318,6 @@ namespace FactoryWorkerApp.Controllers return View(new ExecutionPhaseViewModel()); } [HttpPost] - // доделать public IActionResult ExecutionPhase(int id, string name, ExecutionPhaseStatus status, string impFIO, int planId) { ExecutionPhaseBindingModel model = new ExecutionPhaseBindingModel(); diff --git a/Factory/FactoryWorkerApp/Views/Home/ConnectionPlanProductionWorkpiece.cshtml b/Factory/FactoryWorkerApp/Views/Home/ConnectionPlanProductionWorkpiece.cshtml index 073977a..2ba8a50 100644 --- a/Factory/FactoryWorkerApp/Views/Home/ConnectionPlanProductionWorkpiece.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/ConnectionPlanProductionWorkpiece.cshtml @@ -1,7 +1,6 @@ -@using FactoryDataModels.Enums - -@{ +@{ ViewData["Title"] = "Connect plan and workpieces"; + }

Привязка заготовок к плану производства:

@@ -9,41 +8,35 @@
План производства:
-
- +
+
-

Список заготовок

-
-
Заготовки
-
- - - - - - - - - - @foreach (var workpiece in Model) - { - - - - - - } - -
Выбор Название Количество
- - @workpiece.WorkpieceName - -
-
-
-
-
-
-
+
+
Заготовка:
+
+ +
+
+
+
Количество заготовок:
+
+ +
+
+
+ +
\ No newline at end of file diff --git a/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml b/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml index a0e4b3b..62d023b 100644 --- a/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml @@ -2,12 +2,40 @@ @model PlanProductionViewModel; @{ - ViewData["Title"] = "Plan Production"; + ViewData["Title"] = "Plan Production"; + ViewBag.Workpieces = Model.PlanProductionWorkpieces; }

План производства

+
+

Заготовки

+
+ + + + + + + + + @foreach (var workpiece in ViewBag.Workpieces) + { + + + + + } + +
НазваниеКоличество
+ + @workpiece.Value.Item1.WorkpieceName + + +
+
+
Название:
@@ -24,4 +52,4 @@
-
\ No newline at end of file + diff --git a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml index 0512926..88acb43 100644 --- a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml @@ -46,7 +46,7 @@ } - +
Название: