diff --git a/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs b/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs index 7e4b263..ddc617e 100644 --- a/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs +++ b/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs @@ -4,6 +4,7 @@ using FactoryContracts.SearchModels; using FactoryContracts.StoragesContracts; using FactoryContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace FactoryBusinessLogic.BusinessLogics { @@ -97,9 +98,9 @@ namespace FactoryBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет логина клиента", nameof(model.Login)); } - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$")) { - throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + throw new ArgumentException("Почта не соответствует требованиям", nameof(model.Email)); } if (string.IsNullOrEmpty(model.Password)) { diff --git a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs index d9a40c1..269206e 100644 --- a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs +++ b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs @@ -1,9 +1,7 @@ -using DocumentFormat.OpenXml.Office.CustomUI; -using FactoryContracts.BindingModels; +using FactoryContracts.BindingModels; using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.SearchModels; using FactoryContracts.ViewModels; -using FactoryDatabaseImplement.Models; using FactoryDataModels.Enums; using FactoryDataModels.Models; using FactoryStorekepeerApp.Models; @@ -19,16 +17,18 @@ namespace FactoryStorekeeperApp.Controllers private readonly IMachineLogic machineLogic; private readonly IRequirementLogic requirementLogic; private readonly IProductLogic productLogic; + private readonly IPlanProductionLogic planProductionLogic; - private bool IsLoggedIn { get { return Client.client != null; } } + private static bool IsLoggedIn { get { return Client.client != null; } } - public HomeController(ILogger logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic) + public HomeController(ILogger logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic) { _logger = logger; this.clientLogic = clientLogic; this.requirementLogic = requirementLogic; this.productLogic = productLogic; this.machineLogic = machineLogic; + this.planProductionLogic = planProductionLogic; } public IActionResult Index() @@ -83,7 +83,7 @@ namespace FactoryStorekeeperApp.Controllers { if (!password.Equals(passwordConfirm)) { - return Error(); + throw new ArgumentException("Пароли не совпадают"); } clientLogic.Create(new ClientBindingModel { @@ -160,7 +160,10 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - machineLogic.Delete(new MachineBindingModel { Id = id }); + if (id != 0) + { + machineLogic.Delete(new MachineBindingModel { Id = id }); + } return Redirect("~/Home/Machines"); } [HttpGet] @@ -234,7 +237,8 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - productLogic.Delete(new ProductBindingModel { Id = id }); + if (id != 0) + productLogic.Delete(new ProductBindingModel { Id = id }); return Redirect("~/Home/Products"); } [HttpGet] @@ -306,11 +310,80 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - requirementLogic.Delete(new RequirementBindingModel { Id = id }); + if (id != 0) + requirementLogic.Delete(new RequirementBindingModel { Id = id }); return Redirect("~/Home/Requirements"); } [HttpGet] + public IActionResult MachinePlanProductions() + { + if (!IsLoggedIn) + { + return Redirect("~/Home/Enter"); + } + var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel + { + ClientId = Client.client.Id, + }); + var machines = machineLogic.ReadList(new MachineSearchModel + { + ClientId = Client.client.Id, + }); + ViewBag.planProductions = planProductions; + ViewBag.machines = machines; + return View(); + } + + [HttpPost] + public IActionResult MachinePlanProductions(int machine, List planproductions, int count) + { + if (!IsLoggedIn) + { + return Unauthorized(); + } + var existMachine = machineLogic.ReadElement(new MachineSearchModel + { + Id = machine, + ClientId = Client.client.Id + }); + var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel + { + ClientId = Client.client.Id, + }).Where(x => planproductions.Contains(x.Id)) + .ToList(); + if (existMachine != null && planProductions.Count > 0) + { + foreach (var planId in planproductions) + { + var currPlan = planProductions.Where(x => x.Id == planId).FirstOrDefault(); + if (currPlan != null) + { + if (existMachine.MachinePlanProductions.ContainsKey(planId)) + { + var currTuple = existMachine.MachinePlanProductions[planId]; + existMachine.MachinePlanProductions[planId] = (currTuple.Item1, currTuple.Item2 + count); + } + else + { + existMachine.MachinePlanProductions.Add(planId, (currPlan, count)); + } + } + } + machineLogic.Update(new MachineBindingModel + { + Id = existMachine.Id, + MachineName = existMachine.MachineName, + ClientId = Client.client.Id, + ExploitationStartDate = existMachine.ExploitationStartDate, + Lifetime = existMachine.Lifetime, + MachinePlanProductions = existMachine.MachinePlanProductions, + }); + } + return Redirect("~/Home/Index"); + } + + [HttpGet] public IActionResult Reports() { if (!IsLoggedIn) diff --git a/Factory/FactoryStorekeeperApp/Program.cs b/Factory/FactoryStorekeeperApp/Program.cs index db59e66..77539bd 100644 --- a/Factory/FactoryStorekeeperApp/Program.cs +++ b/Factory/FactoryStorekeeperApp/Program.cs @@ -12,12 +12,14 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml b/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml index 49c6a2e..f88ce67 100644 --- a/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml +++ b/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml @@ -10,37 +10,17 @@
Станок:
- +
-

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

-
-
Заготовки
-
- - - - - - - - - - @foreach (var planProduction in Model) - { - - - - - - } - -
Выбор Название Количество
- - @planProduction.ProductionName - -
-
+
+
Количество:
+ +
+
+
Список планов производств:
+