diff --git a/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs b/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs index e5c61e2..c9db262 100644 --- a/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs @@ -37,7 +37,7 @@ namespace FactoryDatabaseImplement.Implements } using var context = new FactoryDatabase(); return context.Clients - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) || + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) && (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs b/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs index c65f032..0c6a232 100644 --- a/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs +++ b/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs @@ -73,7 +73,8 @@ namespace FactoryDatabaseImplement.Models { Id = Id, ExecutionPhaseName = ExecutionPhaseName, - ImplementerFIO = ImplementerFIO, + PlanProductionName = PlanProduction == null ? null : PlanProduction.ProductionName, + ImplementerFIO = ImplementerFIO, ClientId = ClientId, PlanProductionId = PlanProductionId, Status = Status, diff --git a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs index fab6f1d..d7ffa90 100644 --- a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs +++ b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs @@ -11,7 +11,7 @@ namespace FactoryDatabaseImplement.Models public int Id { get; private set; } [Required] public int ClientId { get; private set; } - public virtual Client Client { get; private set; } = new(); + public virtual Client Client { get; private set; } [Required] public string ProductionName { get; private set; } = string.Empty; diff --git a/Factory/FactoryWorkerApp/Controllers/HomeController.cs b/Factory/FactoryWorkerApp/Controllers/HomeController.cs index f18b481..a181e1c 100644 --- a/Factory/FactoryWorkerApp/Controllers/HomeController.cs +++ b/Factory/FactoryWorkerApp/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using FactoryContracts.BindingModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using FactoryContracts.BindingModels; using FactoryContracts.ViewModels; using FactoryDatabaseImplement.Models; using FactoryDataModels.Enums; @@ -49,8 +50,8 @@ namespace FactoryWorkerApp.Controllers if (user != null) { Client.user = user; - Response.Redirect("Index"); } + Response.Redirect("Index"); } [HttpGet] public IActionResult Register() @@ -104,21 +105,34 @@ namespace FactoryWorkerApp.Controllers return View(new WorkpieceViewModel()); } [HttpPost] - public IActionResult Workpiece(WorkpieceBindingModel model) + public IActionResult Workpiece(int id, string workpiecename, string material, int cost, int[] productIds, int[] counts) { - if (model.Id == 0) + WorkpieceBindingModel model = new WorkpieceBindingModel(); + model.Id = id; + model.WorkpieceName = workpiecename; + model.Material = material; + model.Cost = cost; + model.ClientId = Client.user!.Id; + var products = _logic.GetProducts(); + for (int i = 0; i < productIds.Length; i++) + { + var product = products!.FirstOrDefault(x => x.Id == productIds[i])!; + if (counts[i] <= 0) + continue; + model.WorkpieceProducts[productIds[i]] = (product, counts[i]); + } + if (model.WorkpieceProducts.Count == 0) + return RedirectToAction("Workpieces"); + if (model.Id == 0) { model.DateCreate = DateTime.Now; - model.ClientId = Client.user!.Id; - if (_logic.CreateWorkpiece(model)) - return RedirectToAction("Workpieces"); + _logic.CreateWorkpiece(model); } else { - if (_logic.UpdateWorkpiece(model)) - return RedirectToAction("Workpieces"); + _logic.UpdateWorkpiece(model); } - return View(); + return RedirectToAction("Workpieces"); } [HttpGet] diff --git a/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml b/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml index 1f05ba9..61df184 100644 --- a/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml @@ -12,12 +12,12 @@