From d2cc51b8c10451300741cf75fbd4b92c156a3921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Mon, 27 May 2024 01:47:37 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2=D1=81=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=B7=D0=B0=D0=B8=D0=BC=D0=BE=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B5=20rest=20api=20=D1=81=20=D0=B8=D0=BD=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=BE=D0=BC=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8F,=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/DefectLogic.cs | 39 ++ .../BusinessLogics/TechnicalWorkLogic.cs | 38 ++ .../BusinessLogicsContracts/IDefectLogic.cs | 1 + .../ITechnicalWorkLogic.cs | 2 + .../SearchModels/ExecutorSearchModel.cs | 1 + .../ServiceStationContracts.csproj | 4 + .../ViewModels/DefectViewModel.cs | 10 +- .../ViewModels/TechnicalWorkViewModel.cs | 11 +- .../Implements/DefectStorage.cs | 1 + .../Implements/ExecutorStorage.cs | 6 +- .../Models/TechnicalWork.cs | 1 - .../Controllers/HomeController.cs | 420 +++++++++++++++--- .../ServiceStationExecutorApp/Program.cs | 3 + .../Views/Home/ListCars.cshtml | 2 +- .../Views/Home/ListDefects.cshtml | 2 +- .../Views/Home/ListTechnicalWorks.cshtml | 2 +- .../Views/Home/Privacy.cshtml | 56 ++- .../Views/Home/UpdateDefect.cshtml | 26 +- .../Views/Home/UpdateTechnicalWork.cshtml | 29 +- .../appsettings.json | 4 +- .../Controllers/ExecutorController.cs | 66 +++ .../Controllers/MainController.cs | 240 +++++++++- 22 files changed, 877 insertions(+), 87 deletions(-) create mode 100644 ServiceStation/ServiceStationRestApi/Controllers/ExecutorController.cs diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/DefectLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/DefectLogic.cs index 175180c..fd76252 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/DefectLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/DefectLogic.cs @@ -4,6 +4,7 @@ using ServiceStationContracts.BusinessLogicsContracts; using ServiceStationContracts.SearchModels; using ServiceStationContracts.StoragesContracts; using ServiceStationContracts.ViewModels; +using ServiceStationDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -83,6 +84,44 @@ namespace ServiceStationBusinessLogic.BusinessLogics return true; } + public bool AddCarToDefect(DefectSearchModel model, int[] cars) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("AddCarToDefect. DefectName:{DefectName}. Id:{Id}", model.DefectType, model.Id); + var element = _defectStorage.GetElement(model); + + if(element == null) + { + _logger.LogWarning("AddCarToDefect element not found"); + return false; + } + + _logger.LogInformation("AddCarToDefect find. Id:{Id}", element.Id); + + foreach(int car in cars) + { + if (!element.DefectCars.Keys.Contains(car)) + { + element.DefectCars.Add(car, new CarViewModel() { Id = car }); + } + } + + _defectStorage.Update(new DefectBindingModel() + { + Id = element.Id, + DefectPrice = element.DefectPrice, + DefectType = element.DefectType, + ExecutorId = element.ExecutorId, + RepairId = element.RepairId, + DefectCars = element.DefectCars, + }); + + return true; + } + private void CheckModel(DefectBindingModel model, bool withParams = true) { if(model == null) diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/TechnicalWorkLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/TechnicalWorkLogic.cs index decd873..a2c4f40 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/TechnicalWorkLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/TechnicalWorkLogic.cs @@ -83,6 +83,44 @@ namespace ServiceStationBusinessLogic.BusinessLogics return true; } + public bool AddCarToTechnicalWork(TechnicalWorkSearchModel model, int[] cars) + { + if(model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("AddCarToTechnicalWork. WorkType:{worktype}. Id:{Id}", model.WorkType, model.Id); + var element = _technicalWorkStorage.GetElement(model); + + if(element == null) + { + _logger.LogWarning("AddCarToTechnicalWork element not found"); + return false; + } + + _logger.LogInformation("AddCarToTechnicalWork find. Id:{Id}", element.Id); + + foreach(int car in cars) + { + if (!element.TechnicalWorkCars.Keys.Contains(car)) + { + element.TechnicalWorkCars.Add(car, new CarViewModel() { Id = car }); + } + } + + _technicalWorkStorage.Update(new TechnicalWorkBindingModel + { + Id = element.Id, + WorkType = element.WorkType, + WorkPrice = element.WorkPrice, + DateStartWork = element.DateStartWork, + TechnicalWorkCars = element.TechnicalWorkCars, + ExecutorId = element.ExecutorId, + }); + + return true; + } + private void CheckModel(TechnicalWorkBindingModel model, bool withParams = true) { if (model == null) diff --git a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IDefectLogic.cs b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IDefectLogic.cs index f6495e3..62e0884 100644 --- a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IDefectLogic.cs +++ b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IDefectLogic.cs @@ -17,5 +17,6 @@ namespace ServiceStationContracts.BusinessLogicsContracts bool Create(DefectBindingModel model); bool Update(DefectBindingModel model); bool Delete(DefectBindingModel model); + bool AddCarToDefect(DefectSearchModel model, int[] cars); } } diff --git a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/ITechnicalWorkLogic.cs b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/ITechnicalWorkLogic.cs index a11ee7a..ac34cd5 100644 --- a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/ITechnicalWorkLogic.cs +++ b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/ITechnicalWorkLogic.cs @@ -17,5 +17,7 @@ namespace ServiceStationContracts.BusinessLogicsContracts bool Create(TechnicalWorkBindingModel model); bool Update(TechnicalWorkBindingModel model); bool Delete(TechnicalWorkBindingModel model); + bool AddCarToTechnicalWork(TechnicalWorkSearchModel model, int[] cars); + } } diff --git a/ServiceStation/ServiceStationContracts/SearchModels/ExecutorSearchModel.cs b/ServiceStation/ServiceStationContracts/SearchModels/ExecutorSearchModel.cs index 7c53c11..62bd540 100644 --- a/ServiceStation/ServiceStationContracts/SearchModels/ExecutorSearchModel.cs +++ b/ServiceStation/ServiceStationContracts/SearchModels/ExecutorSearchModel.cs @@ -12,5 +12,6 @@ namespace ServiceStationContracts.SearchModels public string? ExecutorFIO { get; set; } public string? ExecutorNumber { get; set; } public string? ExecutorEmail { get; set; } + public string? ExecutorPassword { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/ServiceStationContracts.csproj b/ServiceStation/ServiceStationContracts/ServiceStationContracts.csproj index 18fee99..f6669bd 100644 --- a/ServiceStation/ServiceStationContracts/ServiceStationContracts.csproj +++ b/ServiceStation/ServiceStationContracts/ServiceStationContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/ServiceStation/ServiceStationContracts/ViewModels/DefectViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/DefectViewModel.cs index ca5dec8..e256dea 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/DefectViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/DefectViewModel.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; namespace ServiceStationContracts.ViewModels { @@ -24,5 +24,13 @@ namespace ServiceStationContracts.ViewModels public int? RepairId { get; set; } public Dictionary DefectCars { get; set; } = new(); + + public DefectViewModel() { } + + [JsonConstructor] + public DefectViewModel(Dictionary DefectCars) + { + this.DefectCars = DefectCars.ToDictionary(x => x.Key, x => x.Value as ICarModel); + } } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs index 7d01462..4061b33 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs @@ -1,4 +1,5 @@ -using ServiceStationDataModels.Models; +using Newtonsoft.Json; +using ServiceStationDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -21,5 +22,13 @@ namespace ServiceStationContracts.ViewModels public int ExecutorId { get; set; } public Dictionary TechnicalWorkCars { get; set; } = new(); + + public TechnicalWorkViewModel() { } + + [JsonConstructor] + public TechnicalWorkViewModel(Dictionary TechnicalWorkCars) + { + this.TechnicalWorkCars = TechnicalWorkCars.ToDictionary(x => x.Key, x => x.Value as ICarModel); + } } } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs index 667bb2f..5e06dfa 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs @@ -44,6 +44,7 @@ namespace ServiceStationDatabaseImplement.Implements .Include(x => x.Repair) .Include(x => x.Executor) .Where(x => x.ExecutorId == model.ExecutorId) + .ToList() .Select(x => x.GetViewModel) .ToList(); } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs index f87bce2..4c377b5 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs @@ -40,15 +40,15 @@ namespace ServiceStationDatabaseImplement.Implements public ExecutorViewModel? GetElement(ExecutorSearchModel model) { using var context = new ServiceStationDatabase(); - if (!model.Id.HasValue && string.IsNullOrEmpty(model.ExecutorNumber)) return null; + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ExecutorNumber) && string.IsNullOrEmpty(model.ExecutorPassword)) return null; - if (!string.IsNullOrEmpty(model.ExecutorNumber)) + if (!string.IsNullOrEmpty(model.ExecutorNumber) && !string.IsNullOrEmpty(model.ExecutorPassword)) { return context.Executors .Include(x => x.Cars) .Include(x => x.Defects) .Include(x => x.TechnicalWorks) - .FirstOrDefault(x => x.ExecutorNumber.Contains(model.ExecutorNumber))? + .FirstOrDefault(x => x.ExecutorNumber.Contains(model.ExecutorNumber) && x.ExecutorPassword.Contains(model.ExecutorPassword))? .GetViewModel; } return context.Executors diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs index ad7dd45..7daa377 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs @@ -68,7 +68,6 @@ namespace ServiceStationDatabaseImplement.Models { WorkType = model.WorkType; WorkPrice = model.WorkPrice; - DateStartWork = model.DateStartWork; ExecutorId = model.ExecutorId; } public TechnicalWorkViewModel GetViewModel => new() diff --git a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs index 3cce699..2e11f52 100644 --- a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using ServiceStationContracts.BindingModels; +using ServiceStationContracts.SearchModels; using ServiceStationContracts.ViewModels; using ServiceStationExecutorApp.Models; using System.Collections.Generic; @@ -22,144 +24,418 @@ namespace ServiceStationExecutorApp.Controllers public IActionResult Privacy() { - return View(); + if(APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + return View(APIExecutor.Executor); + } + [HttpPost] + public void Privacy(string email, string fio, string number, string password) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введены не все данные"); + } + APIExecutor.PostRequest("api/executor/updateexecutor", new ExecutorBindingModel + { + ExecutorEmail = email, + ExecutorNumber = number, + ExecutorFIO = fio, + ExecutorPassword = password, + Id = APIExecutor.Executor.Id + }); + Response.Redirect("Index"); } public IActionResult Enter() { return View(); } + [HttpPost] + public void Enter(string executorNumber, string password) + { + if(string.IsNullOrEmpty(executorNumber) || string.IsNullOrEmpty(password)) + { + throw new Exception("Не хватает пароля или номера."); + } + APIExecutor.Executor = APIExecutor.GetRequest($"api/executor/login?executorNumber={executorNumber}&password={password}"); + if (APIExecutor.Executor == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } public IActionResult Register() { return View(); } + [HttpPost] + public void Register(string fio, string executorNumber, string password, string email) + { + if(string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(executorNumber) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введены не все данные"); + } + APIExecutor.PostRequest("api/executor/register", new ExecutorBindingModel + { + ExecutorNumber = executorNumber, + ExecutorEmail = email, + ExecutorFIO = fio, + ExecutorPassword = password + }); + Response.Redirect("Enter"); + return; + } public IActionResult ListCars() { - var cars = new List(); - cars.Add(new CarViewModel + if (APIExecutor.Executor == null) { - Id = 1, - CarNumber = "111", - CarBrand = "lamba", - ExecutorId = 1 - }); - - return View(cars); + return RedirectToAction("Enter"); + } + return View(APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}")); } public IActionResult ListDefects() { - var defects = new List(); - defects.Add(new DefectViewModel + if (APIExecutor.Executor == null) { - Id = 1, - DefectType = "type1", - DefectPrice = 100.0, - ExecutorId = 1 - }); - - return View(defects); + return RedirectToAction("Enter"); + } + return View(APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}")); } public IActionResult ListTechnicalWorks() { - var technicalWorks = new List(); - technicalWorks.Add(new TechnicalWorkViewModel + if (APIExecutor.Executor == null) { - Id = 1, - WorkType = "type1", - DateStartWork = DateTime.Now, - WorkPrice = 100.0, - ExecutorId = 1 - }); - - return View(technicalWorks); + return RedirectToAction("Enter"); + } + return View(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}")); + } + [HttpGet] + public Tuple? GetDefect(int defectId) + { + if(APIExecutor.Executor == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIExecutor.GetRequest>>>($"api/main/getdefect?defectId={defectId}"); + if (result == null) return default; + string table = ""; + for(int i = 0; i < result.Item2.Count; i++) + { + var carNumber = result.Item2[i].Item1; + var carBrand = result.Item2[i].Item2; + table += ""; + table += $"{carNumber}"; + table += $"{carBrand}"; + table += ""; + } + return Tuple.Create(result.Item1, table); + } + [HttpGet] + public Tuple? GetTechnicalWork(int technicalWorkId) + { + if(APIExecutor.Executor == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIExecutor.GetRequest>>>($"api/main/gettechnicalwork?technicalworkId={technicalWorkId}"); + if (result == null) return default; + string table = ""; + for(int i = 0;i{carNumber}"; + table += $"{carBrand}"; + table += ""; + } + return Tuple.Create(result.Item1, table); } public IActionResult DeleteCar() { - ViewBag.Cars = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Cars = APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void DeleteCar(int car) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/deletecar", new CarBindingModel + { + Id = car + }); + Response.Redirect("ListCars"); + } public IActionResult DeleteDefect() { - ViewBag.Defects = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Defects = APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void DeleteDefect(int defect) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/deletedefect", new DefectBindingModel { Id = defect }); + Response.Redirect("ListDefects"); + } public IActionResult DeleteTechnicalWork() { - ViewBag.TechnicalWorks = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.TechnicalWorks = APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void DeleteTechnicalWork(int technicalWork) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/deletetechnicalwork", new TechnicalWorkBindingModel { Id = technicalWork }); + Response.Redirect("ListTechnicalWorks"); + } public IActionResult UpdateCar() { - ViewBag.Cars = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Cars = APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void UpdateCar(int car, string carNumber, string carBrand) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + if (string.IsNullOrEmpty(carNumber)) + { + throw new Exception("Введите номер машины"); + } + if (string.IsNullOrEmpty(carBrand)) + { + throw new Exception("Введите бренд машины"); + } + APIExecutor.PostRequest("api/main/updatecar", new CarBindingModel + { + Id = car, + CarNumber = carNumber, + CarBrand = carBrand, + ExecutorId = APIExecutor.Executor.Id + }); + Response.Redirect("ListCars"); + } public IActionResult UpdateDefect() { - ViewBag.Defects = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Defects = APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void UpdateDefect(int defect, string DefectType, double DefectPrice) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + if (string.IsNullOrEmpty(DefectType)) + { + throw new Exception("Введите тип неисправности"); + } + if(DefectPrice < 100) + { + throw new Exception("Минимальная цена неисправности 100"); + } + APIExecutor.PostRequest("api/main/updatedefect", new DefectBindingModel + { + ExecutorId = APIExecutor.Executor.Id, + Id = defect, + DefectType = DefectType, + DefectPrice = DefectPrice + }); + Response.Redirect("ListDefects"); + } public IActionResult UpdateTechnicalWork() { - ViewBag.TechnicalWorks = new List(); + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.TechnicalWorks = APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"); return View(); } + [HttpPost] + public void UpdateTechnicalWork(int technicalWork, string TechnicalWorkType, double TechnicalWorkPrice) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + if (string.IsNullOrEmpty(TechnicalWorkType)) + { + throw new Exception("Введите тип ТО"); + } + if(TechnicalWorkPrice < 100) + { + throw new Exception("Цена ТО должны быть больше 100"); + } + APIExecutor.PostRequest("api/main/updatetechnicalwork", new TechnicalWorkBindingModel + { + Id = technicalWork, + WorkType = TechnicalWorkType, + ExecutorId = APIExecutor.Executor.Id, + WorkPrice = TechnicalWorkPrice, + }); + Response.Redirect("ListTechnicalWorks"); + } public IActionResult CreateCar() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } return View(); } + [HttpPost] + public void CreateCar(string CarNumber, string CarBrand) + { + if(APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/createcar", new CarBindingModel + { + ExecutorId = APIExecutor.Executor.Id, + CarNumber = CarNumber, + CarBrand = CarBrand + }); + Response.Redirect("ListCars"); + } public IActionResult CreateDefect() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } return View(); } + [HttpPost] + public void CreateDefect(string defectType, double defectPrice) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/createdefect", new DefectBindingModel + { + ExecutorId = APIExecutor.Executor.Id, + DefectType = defectType, + DefectPrice = defectPrice + }); + Response.Redirect("ListDefects"); + } public IActionResult CreateTechnicalWork() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } return View(); } + [HttpPost] + public void CreateTechnicalWork(string WorkType, double WorkPrice) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/createtechnicalwork", new TechnicalWorkBindingModel + { + ExecutorId = APIExecutor.Executor.Id, + WorkType = WorkType, + WorkPrice = WorkPrice, + DateStartWork = DateTime.Now + }); + Response.Redirect("ListTechnicalWorks"); + } public IActionResult AddCarToDefect() { - var defect = new DefectViewModel + if (APIExecutor.Executor == null) { - Id = 1, - DefectType = "type1", - DefectPrice = 1000.0, - ExecutorId = 1 - }; - var car = new CarViewModel + return RedirectToAction("Enter"); + } + return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"), + APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"))); + } + [HttpPost] + public void AddCarToDefect(int defect, int[] car) + { + if(APIExecutor.Executor == null) { - Id = 1, - CarNumber = "111", - CarBrand = "lamba" - }; - List defects = new List(); - List cars = new List(); - defects.Add(defect); - cars.Add(car); - return View(Tuple.Create(defects, cars)); + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/addcartodefect", Tuple.Create( + new DefectSearchModel() { Id = defect }, + car + )); + Response.Redirect("ListDefects"); } public IActionResult AddCarToTechnicalWork() { - var technicalWork = new TechnicalWorkViewModel + if (APIExecutor.Executor == null) { - Id = 1, - WorkType = "type1", - WorkPrice = 1000.0, - DateStartWork = DateTime.Now, - ExecutorId = 1 - }; - var car = new CarViewModel + return RedirectToAction("Enter"); + } + return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), + APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"))); + } + [HttpPost] + public void AddCarToTechnicalWork(int technicalWork, int[] car) + { + if (APIExecutor.Executor == null) { - Id = 1, - CarNumber = "111", - CarBrand = "lamba" - }; - List technicalWorks = new List(); - List cars = new List(); - technicalWorks.Add(technicalWork); - cars.Add(car); - return View(Tuple.Create(technicalWorks, cars)); + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/addcartotechnicalwork", Tuple.Create( + new TechnicalWorkSearchModel() { Id = technicalWork }, + car + )); + Response.Redirect("ListTechnicalWorks"); } public IActionResult BindingTechnicalWorkToWork() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } var technicalWork = new TechnicalWorkViewModel { Id = 1, @@ -183,6 +459,10 @@ namespace ServiceStationExecutorApp.Controllers } public IActionResult ListWorkToFile() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } var car = new CarViewModel { Id = 1, @@ -209,6 +489,10 @@ namespace ServiceStationExecutorApp.Controllers } public IActionResult ListCarsToPdf() { + if (APIExecutor.Executor == null) + { + return RedirectToAction("Enter"); + } return View(); } diff --git a/ServiceStation/ServiceStationExecutorApp/Program.cs b/ServiceStation/ServiceStationExecutorApp/Program.cs index 0727468..d9b457a 100644 --- a/ServiceStation/ServiceStationExecutorApp/Program.cs +++ b/ServiceStation/ServiceStationExecutorApp/Program.cs @@ -1,9 +1,12 @@ +using ServiceStationExecutorApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIExecutor.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCars.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCars.cshtml index a231ef8..112ac37 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCars.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCars.cshtml @@ -24,7 +24,7 @@ @foreach (var item in Model) { - + @Html.DisplayFor(modelItem => item.Id) diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListDefects.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListDefects.cshtml index df4dde2..723536f 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListDefects.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListDefects.cshtml @@ -23,7 +23,7 @@ @foreach (var item in Model) { - + @Html.DisplayFor(modelItem => item.Id) diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListTechnicalWorks.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListTechnicalWorks.cshtml index 9191383..90795fe 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListTechnicalWorks.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListTechnicalWorks.cshtml @@ -27,7 +27,7 @@ @foreach (var item in Model) { - + @Html.DisplayFor(modelItem => item.Id) diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml index af4fb19..3cf355c 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Privacy.cshtml @@ -1,6 +1,52 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

+@using ServiceStationContracts.ViewModels -

Use this page to detail your site's privacy policy.

+@model ExecutorViewModel + +@{ + ViewData["Title"] = "Privacy"; +} + + + +
+

Мои данные

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
\ No newline at end of file diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateDefect.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateDefect.cshtml index 8797db5..7e17002 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateDefect.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateDefect.cshtml @@ -26,7 +26,7 @@ Марка машины - + @* полученные машины *@ @@ -37,3 +37,27 @@ + +@section Scripts +{ + +} diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateTechnicalWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateTechnicalWork.cshtml index 3b0fa34..4222edb 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateTechnicalWork.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/UpdateTechnicalWork.cshtml @@ -9,7 +9,7 @@
- +
@@ -26,7 +26,7 @@ Марка машины - + @* полученные машины *@ @@ -38,3 +38,28 @@
+@section Scripts +{ + +} + + diff --git a/ServiceStation/ServiceStationExecutorApp/appsettings.json b/ServiceStation/ServiceStationExecutorApp/appsettings.json index 10f68b8..d4ed994 100644 --- a/ServiceStation/ServiceStationExecutorApp/appsettings.json +++ b/ServiceStation/ServiceStationExecutorApp/appsettings.json @@ -5,5 +5,7 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "IPAddress": "https://localhost:7288/" } diff --git a/ServiceStation/ServiceStationRestApi/Controllers/ExecutorController.cs b/ServiceStation/ServiceStationRestApi/Controllers/ExecutorController.cs new file mode 100644 index 0000000..5bfd1a5 --- /dev/null +++ b/ServiceStation/ServiceStationRestApi/Controllers/ExecutorController.cs @@ -0,0 +1,66 @@ +using Microsoft.AspNetCore.Mvc; +using ServiceStationContracts.BindingModels; +using ServiceStationContracts.BusinessLogicsContracts; +using ServiceStationContracts.SearchModels; +using ServiceStationContracts.ViewModels; + +namespace ServiceStationRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ExecutorController : Controller + { + private readonly IExecutorLogic _elogic; + private readonly ILogger _logger; + + public ExecutorController(IExecutorLogic elogic, ILogger logger) + { + _elogic = elogic; + _logger = logger; + } + + [HttpPost] + public void Register(ExecutorBindingModel model) + { + try + { + _elogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpGet] + public ExecutorViewModel? Login(string executorNumber, string password) + { + try + { + return _elogic.ReadElement(new ExecutorSearchModel + { + ExecutorNumber = executorNumber, + ExecutorPassword = password + }); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void UpdateExecutor(ExecutorBindingModel model) + { + try + { + _elogic.Update(model); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs index 8eb19db..7cd88fd 100644 --- a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs +++ b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs @@ -1,4 +1,9 @@ using Microsoft.AspNetCore.Mvc; +using ServiceStationContracts.BindingModels; +using ServiceStationContracts.BusinessLogicsContracts; +using ServiceStationContracts.SearchModels; +using ServiceStationContracts.ViewModels; +using ServiceStationDatabaseImplement.Models; namespace ServiceStationRestApi.Controllers { @@ -6,6 +11,239 @@ namespace ServiceStationRestApi.Controllers [ApiController] public class MainController : Controller { - + private readonly ILogger _logger; + private readonly ICarLogic _clogic; + private readonly IDefectLogic _dlogic; + private readonly ITechnicalWorkLogic _tlogic; + + public MainController(ILogger logger, ICarLogic clogic, IDefectLogic dlogic, ITechnicalWorkLogic tlogic) + { + _logger = logger; + _clogic = clogic; + _dlogic = dlogic; + _tlogic = tlogic; + } + + [HttpGet] + public List? GetCarList(int executorId) + { + try + { + return _clogic.ReadList(new CarSearchModel + { + ExecutorId = executorId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка машин"); + throw; + } + } + [HttpGet] + public List? GetDefectList(int executorId) + { + try + { + return _dlogic.ReadList(new DefectSearchModel + { + ExecutorId = executorId + }); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка неисправностей"); + throw; + } + } + [HttpGet] + public List? GetTechnicalWorkList(int executorId) + { + try + { + return _tlogic.ReadList(new TechnicalWorkSearchModel + { + ExecutorId = executorId + }); + } + catch( Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка ТО"); + throw; + } + } + [HttpPost] + public void CreateCar(CarBindingModel model) + { + try + { + _clogic.Create(model); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка создания машины"); + throw; + } + } + [HttpPost] + public void CreateDefect(DefectBindingModel model) + { + try + { + _dlogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания неисправности"); + throw; + } + } + [HttpPost] + public void CreateTechnicalWork(TechnicalWorkBindingModel model) + { + try + { + _tlogic.Create(model); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка создания ТО"); + throw; + } + } + [HttpPost] + public void DeleteCar(CarBindingModel model) + { + try + { + _clogic.Delete(model); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка удаления машины"); + throw; + } + } + [HttpPost] + public void DeleteDefect(DefectBindingModel model) + { + try + { + _dlogic.Delete(model); + } + catch( Exception ex) + { + _logger.LogError(ex, "Ошибка удаления неисправности"); + throw; + } + } + [HttpPost] + public void DeleteTechnicalWork(TechnicalWorkBindingModel model) + { + try + { + _tlogic.Delete(model); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ТО"); + throw; + } + } + [HttpPost] + public void UpdateCar(CarBindingModel model) + { + try + { + _clogic.Update(model); + } + catch( Exception ex) + { + _logger.LogError(ex, "Ошибка обновления машины"); + throw; + } + } + [HttpPost] + public void UpdateDefect(DefectBindingModel model) + { + try + { + _dlogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления неисправности"); + throw; + } + } + [HttpPost] + public void UpdateTechnicalWork(TechnicalWorkBindingModel model) + { + try + { + _tlogic.Update(model); + } + catch( Exception ex) + { + _logger.LogError(ex, "Ошибка обновления ТО"); + throw; + } + } + [HttpPost] + public void AddCarToDefect(Tuple model) + { + try + { + _dlogic.AddCarToDefect(model.Item1, model.Item2); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка добавления машины в неисправность."); + throw; + } + } + [HttpPost] + public void AddCarToTechnicalWork(Tuple model) + { + try + { + _tlogic.AddCarToTechnicalWork(model.Item1, model.Item2); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка добавления машины в ТО."); + throw; + } + } + [HttpGet] + public Tuple>>? GetDefect(int defectId) + { + try + { + var elem = _dlogic.ReadElement(new DefectSearchModel { Id = defectId }); + if (elem == null) return null; + return Tuple.Create(elem, elem.DefectCars.Select(x => Tuple.Create(x.Value.CarNumber, x.Value.CarBrand)).ToList()); + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка получения машины по id={Id}", defectId); + throw; + } + } + [HttpGet] + public Tuple>>? GetTechnicalWork(int technicalWorkId) + { + try + { + var elem = _tlogic.ReadElement(new TechnicalWorkSearchModel { Id = technicalWorkId }); + if (elem == null) return null; + return Tuple.Create(elem, elem.TechnicalWorkCars.Select(x => Tuple.Create(x.Value.CarNumber, x.Value.CarBrand)).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения машины по id={Id}", technicalWorkId); + throw; + } + } } } From 12351d8cec1a78f646f49d5579b86fc6f5fc33e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Mon, 27 May 2024 15:10:33 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D1=87=D1=83=D1=82=D1=8C=20=D0=B4=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D1=87=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 30 ++----------------- .../Home/BindingTechnicalWorkToWork.cshtml | 4 +-- .../Views/Home/ListWorkToFile.cshtml | 2 +- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs index 2e11f52..6f16cb8 100644 --- a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -451,11 +451,9 @@ namespace ServiceStationExecutorApp.Controllers WorkPrice = 1000.0, Status = ServiceStationDataModels.Enums.WorkStatus.Принята }; - List technicalWorks = new List(); - List works = new List(); - technicalWorks.Add(technicalWork); + List works = new(); works.Add(work); - return View(Tuple.Create(technicalWorks, works)); + return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), works)); } public IActionResult ListWorkToFile() { @@ -463,29 +461,7 @@ namespace ServiceStationExecutorApp.Controllers { return RedirectToAction("Enter"); } - var car = new CarViewModel - { - Id = 1, - CarNumber = "111", - CarBrand = "lamba" - }; - var car2 = new CarViewModel - { - Id = 2, - CarNumber = "121", - CarBrand = "lamba" - }; - var car3 = new CarViewModel - { - Id = 3, - CarNumber = "131", - CarBrand = "lamba" - }; - List cars = new List(); - cars.Add(car); - cars.Add(car2); - cars.Add(car3); - return View(cars); + return View(APIExecutor.GetRequest>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}")); } public IActionResult ListCarsToPdf() { diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/BindingTechnicalWorkToWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/BindingTechnicalWorkToWork.cshtml index e040e41..131d3a8 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/BindingTechnicalWorkToWork.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/BindingTechnicalWorkToWork.cshtml @@ -1,4 +1,4 @@ -@using ServiceStationContracts.ViewModels; + @using ServiceStationContracts.ViewModels; @using ServiceStationDataModels.Models; @{ @@ -8,7 +8,7 @@ @model Tuple, List>
-

Добавление машин к неисправностям:

+

Привязка ТО к работе:

diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListWorkToFile.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListWorkToFile.cshtml index cf1fdf2..572fd5c 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListWorkToFile.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListWorkToFile.cshtml @@ -8,7 +8,7 @@

- Создание отчета по машинам + Создание списка работ