From 17db7a656c05da442102989e4f9bbbc4610bc09a Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 28 May 2024 22:40:13 +0400 Subject: [PATCH] ControllersShiza --- .../Controllers/DetailController.cs | 14 ++++++++----- .../Controllers/HomeController.cs | 7 ++++++- .../Controllers/ProductController.cs | 2 +- .../Controllers/ProductionController.cs | 2 -- Course/ImplementerApp/ImplementerData.cs | 20 +++++++++++++++---- .../ImplementerApp/Views/Home/Privacy.cshtml | 20 +++++++++++++++++++ .../ImplementerApp/Views/Home/Register.cshtml | 2 +- 7 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Course/ImplementerApp/Controllers/DetailController.cs b/Course/ImplementerApp/Controllers/DetailController.cs index ce46fca..21c1413 100644 --- a/Course/ImplementerApp/Controllers/DetailController.cs +++ b/Course/ImplementerApp/Controllers/DetailController.cs @@ -17,7 +17,6 @@ namespace ImplementerApp.Controllers private bool IsLoggedIn { get { return UserImplementer.user != null; } } private int UserId { get { return UserImplementer.user!.Id; } } - [HttpGet] public IActionResult IndexDetail() { @@ -57,8 +56,13 @@ namespace ImplementerApp.Controllers { model.DateCreate = DateTime.Now; model.UserId = UserImplementer.user!.Id; - if (_data.CreateDetail(model)) - return RedirectToAction("IndexDetail"); + try { + if (_data.CreateDetail(model)) + return RedirectToAction("IndexDetail"); + } catch (ArgumentException ex) + { + return RedirectToAction("Error", ex.Message); + } } else { @@ -69,9 +73,9 @@ namespace ImplementerApp.Controllers } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() + public IActionResult Error(string ex) { - return View(); + return View(ex); } } } diff --git a/Course/ImplementerApp/Controllers/HomeController.cs b/Course/ImplementerApp/Controllers/HomeController.cs index 4177736..6aaf48d 100644 --- a/Course/ImplementerApp/Controllers/HomeController.cs +++ b/Course/ImplementerApp/Controllers/HomeController.cs @@ -22,7 +22,12 @@ namespace ImplementerApp.Controllers private bool IsLoggedIn { get { return UserImplementer.user != null; } } private int UserId { get { return UserImplementer.user!.Id; } } - + [HttpPost] + public JsonResult CheckLogin(string login) + { + var unique = _data.CheckLogin(login); + return Json(new { isUnique = unique }); + } public IActionResult IndexNonReg() { if (!IsLoggedIn) diff --git a/Course/ImplementerApp/Controllers/ProductController.cs b/Course/ImplementerApp/Controllers/ProductController.cs index 463ec3c..c52a317 100644 --- a/Course/ImplementerApp/Controllers/ProductController.cs +++ b/Course/ImplementerApp/Controllers/ProductController.cs @@ -17,7 +17,7 @@ namespace ImplementerApp.Controllers private bool IsLoggedIn { get { return UserImplementer.user != null; } } private int UserId { get { return UserImplementer.user!.Id; } } - + [HttpGet] public IActionResult IndexProduct() { diff --git a/Course/ImplementerApp/Controllers/ProductionController.cs b/Course/ImplementerApp/Controllers/ProductionController.cs index 0980968..c19e39a 100644 --- a/Course/ImplementerApp/Controllers/ProductionController.cs +++ b/Course/ImplementerApp/Controllers/ProductionController.cs @@ -16,8 +16,6 @@ namespace ImplementerApp.Controllers } private bool IsLoggedIn { get { return UserImplementer.user != null; } } private int UserId { get { return UserImplementer.user!.Id; } } - - [HttpGet] public IActionResult IndexProduction() { diff --git a/Course/ImplementerApp/ImplementerData.cs b/Course/ImplementerApp/ImplementerData.cs index 6146b60..1a27d39 100644 --- a/Course/ImplementerApp/ImplementerData.cs +++ b/Course/ImplementerApp/ImplementerData.cs @@ -89,6 +89,10 @@ namespace ImplementerApp { return _detailLogic.ReadElement(new() { Id= id }); } + public bool CheckDetailName(string name) + { + return _detailLogic.ReadElement(new() { Name = name }) == null; + } public List? GetProducts(int userId) { @@ -110,8 +114,12 @@ namespace ImplementerApp { return _productLogic.Create(model); } + public bool CheckProductName(string name) + { + return _productLogic.ReadElement(new() { Name = name }) == null; + } - public List? GetProductions(int userId) + public List? GetProductions(int userId) { return _productionLogic.ReadList(new() { UserId = userId }); } @@ -130,9 +138,13 @@ namespace ImplementerApp public bool DeleteProduction(int productionId) { return _productionLogic.Delete(new() { Id = productionId}); - } - - public List? GetMachines() + } + public bool CheckProductionName(string name) + { + return _productionLogic.ReadElement(new() { Name = name }) == null; + } + + public List? GetMachines() { return _machineLogic.ReadList(null); } diff --git a/Course/ImplementerApp/Views/Home/Privacy.cshtml b/Course/ImplementerApp/Views/Home/Privacy.cshtml index e68278d..d6c3496 100644 --- a/Course/ImplementerApp/Views/Home/Privacy.cshtml +++ b/Course/ImplementerApp/Views/Home/Privacy.cshtml @@ -43,6 +43,26 @@