diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/RepairLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/RepairLogic.cs index 52767df..5486f4e 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/RepairLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/RepairLogic.cs @@ -102,7 +102,46 @@ namespace ServiceStationBusinessLogic.BusinessLogics return true; } - private void CheckModel(RepairBindingModel model, bool withParams = true) + public bool AddSparePartToRepair(RepairSearchModel model, int[] spareparts) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("AddSparePartToRepair. RepairName:{RepairName}. Id:{Id}", model.RepairName, model.Id); + var element = _repairStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddSparePartToRepair element not found"); + return false; + } + + _logger.LogInformation("AddSparePartToRepair find. Id:{Id}", element.Id); + + foreach (int sparepart in spareparts) + { + if (!element.RepairSpareParts.Keys.Contains(sparepart)) + { + element.RepairSpareParts.Add(sparepart, new SparePartViewModel() { Id = sparepart }); + } + } + + _repairStorage.Update(new RepairBindingModel() + { + Id = element.Id, + RepairName = element.RepairName, + RepairStartDate = element.RepairStartDate, + RepairPrice = element.RepairPrice, + GuarantorId = element.GuarantorId, + DefectId = element.DefectId, + RepairSpareParts = element.RepairSpareParts, + }); + + return true; + } + + private void CheckModel(RepairBindingModel model, bool withParams = true) { if (model == null) { diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/WorkLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/WorkLogic.cs index 1379368..556a51d 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/WorkLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/WorkLogic.cs @@ -91,7 +91,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics public bool Update(WorkBindingModel model) { - CheckModel(model); + //CheckModel(model); if (_workStorage.Update(model) == null) { @@ -102,7 +102,46 @@ namespace ServiceStationBusinessLogic.BusinessLogics return true; } - private void CheckModel(WorkBindingModel model, bool withParams = true) + public bool AddSparePartToWork(WorkSearchModel model, int[] spareparts) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("AddSparePartToWork. WorkName:{workName}. Id:{Id}", model.WorkName, model.Id); + var element = _workStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddSparePartToWork element not found"); + return false; + } + + _logger.LogInformation("AddSparePartToWork find. Id:{Id}", element.Id); + + foreach (int sparepart in spareparts) + { + if (!element.WorkSpareParts.Keys.Contains(sparepart)) + { + element.WorkSpareParts.Add(sparepart, new SparePartViewModel() { Id = sparepart }); + } + } + + _workStorage.Update(new WorkBindingModel + { + Id = element.Id, + WorkName = element.WorkName, + Status = element.Status, + WorkPrice = element.WorkPrice, + GuarantorId = element.GuarantorId, + TechnicalWorkId = element.TechnicalWorkId, + WorkSpareParts = element.WorkSpareParts, + }); + + return true; + } + + private void CheckModel(WorkBindingModel model, bool withParams = true) { if (model == null) { diff --git a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IRepairLogic.cs b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IRepairLogic.cs index ff736d1..fae17e9 100644 --- a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IRepairLogic.cs +++ b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IRepairLogic.cs @@ -17,5 +17,6 @@ namespace ServiceStationContracts.BusinessLogicsContracts bool Create(RepairBindingModel model); bool Update(RepairBindingModel model); bool Delete(RepairBindingModel model); - } + bool AddSparePartToRepair(RepairSearchModel model, int[] spareparts); + } } diff --git a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IWorkLogic.cs b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IWorkLogic.cs index b5e6939..b5e2216 100644 --- a/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IWorkLogic.cs +++ b/ServiceStation/ServiceStationContracts/BusinessLogicsContracts/IWorkLogic.cs @@ -17,5 +17,6 @@ namespace ServiceStationContracts.BusinessLogicsContracts bool Create(WorkBindingModel model); bool Update(WorkBindingModel model); bool Delete(WorkBindingModel model); - } + bool AddSparePartToWork(WorkSearchModel model, int[] spareparts); + } } diff --git a/ServiceStation/ServiceStationContracts/SearchModels/GuarantorSearchModel.cs b/ServiceStation/ServiceStationContracts/SearchModels/GuarantorSearchModel.cs index cc99c7a..8d2529f 100644 --- a/ServiceStation/ServiceStationContracts/SearchModels/GuarantorSearchModel.cs +++ b/ServiceStation/ServiceStationContracts/SearchModels/GuarantorSearchModel.cs @@ -13,5 +13,6 @@ namespace ServiceStationContracts.SearchModels public string? GuarantorFIO { get; set; } public string? GuarantorEmail { get; set; } public string? GuarantorNumber { get; set; } - } + public string? GuarantorPassword { get; set; } + } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs index 7201a2a..ca276c3 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs @@ -1,4 +1,5 @@ -using ServiceStationDataModels.Enums; +using Newtonsoft.Json; +using ServiceStationDataModels.Enums; using ServiceStationDataModels.Models; using System; using System.Collections.Generic; @@ -27,5 +28,13 @@ namespace ServiceStationContracts.ViewModels public int? DefectId { get; set; } public Dictionary RepairSpareParts { get; set; } = new(); - } + + public RepairViewModel() { } + + [JsonConstructor] + public RepairViewModel(Dictionary RepairSpareParts) + { + this.RepairSpareParts = RepairSpareParts.ToDictionary(x => x.Key, x => x.Value as ISparePartModel); + } + } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs index 2a47418..7fd147d 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs @@ -1,4 +1,5 @@ -using ServiceStationDataModels.Enums; +using Newtonsoft.Json; +using ServiceStationDataModels.Enums; using ServiceStationDataModels.Models; using System.ComponentModel; @@ -23,5 +24,13 @@ namespace ServiceStationContracts.ViewModels public int? TechnicalWorkId { get; set; } public Dictionary WorkSpareParts { get; set; } = new(); - } + + public WorkViewModel() { } + + [JsonConstructor] + public WorkViewModel(Dictionary WorkSpareParts) + { + this.WorkSpareParts = WorkSpareParts.ToDictionary(x => x.Key, x => x.Value as ISparePartModel); + } + } } diff --git a/ServiceStation/ServiceStationDataModels/Enums/WorkStatus.cs b/ServiceStation/ServiceStationDataModels/Enums/WorkStatus.cs index 0a066cb..8a666d8 100644 --- a/ServiceStation/ServiceStationDataModels/Enums/WorkStatus.cs +++ b/ServiceStation/ServiceStationDataModels/Enums/WorkStatus.cs @@ -14,8 +14,6 @@ namespace ServiceStationDataModels.Enums Выполняется = 1, - Готова = 2, - - Завершена = 3 + Готова = 2 } } \ No newline at end of file diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs index d5dffac..c44074f 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs @@ -40,15 +40,15 @@ namespace ServiceStationDatabaseImplement.Implements public GuarantorViewModel? GetElement(GuarantorSearchModel model) { using var context = new ServiceStationDatabase(); - if (!model.Id.HasValue && !string.IsNullOrEmpty(model.GuarantorFIO)) return null; + if (!model.Id.HasValue && !string.IsNullOrEmpty(model.GuarantorNumber) && string.IsNullOrEmpty(model.GuarantorPassword)) return null; - if (!string.IsNullOrEmpty(model.GuarantorFIO)) + if (!string.IsNullOrEmpty(model.GuarantorNumber) && !string.IsNullOrEmpty(model.GuarantorPassword)) { return context.Guarantors .Include(x => x.SpareParts) .Include(x => x.Repairs) .Include(x => x.Works) - .FirstOrDefault(x => x.GuarantorFIO.Contains(model.GuarantorFIO))? + .FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber) && x.GuarantorPassword.Contains(model.GuarantorPassword))? .GetViewModel; } return context.Guarantors diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs index d339c7a..667d64b 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs @@ -76,8 +76,12 @@ namespace ServiceStationDatabaseImplement.Models TechnicalWorkId = model.TechnicalWorkId; return; } + if (model.Status != WorkStatus.Неизвестен) + { + Status = model.Status; + return; + } WorkName = model.WorkName; - Status = model.Status; WorkPrice = model.WorkPrice; GuarantorId = model.GuarantorId; } diff --git a/ServiceStation/ServiceStationGuarantorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationGuarantorApp/Controllers/HomeController.cs index 3d8eb34..2512d1e 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationGuarantorApp/Controllers/HomeController.cs @@ -1,7 +1,10 @@ using Microsoft.AspNetCore.Mvc; using ServiceStationContracts.BindingModels; +using ServiceStationContracts.SearchModels; +using ServiceStationContracts.ViewModels; using ServiceStationGuarantorApp.Models; using System.Diagnostics; +using System.Runtime.InteropServices.ComTypes; namespace ServiceStationGuarantorApp.Controllers { @@ -19,42 +22,41 @@ namespace ServiceStationGuarantorApp.Controllers return View(); } - [HttpGet] public IActionResult Privacy() { - //if (APIGuarantor.Guarantor == null) - //{ - // return Redirect("~/Home/Enter"); - //} - return View(); + if (APIGuarantor.Guarantor == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIGuarantor.Guarantor); } - //[HttpPost] - //public void Privacy(string number, string email, string FIO, string password) - //{ - // if (APIGuarantor.Guarantor == null) - // { - // throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); - // } - // if (string.IsNullOrEmpty(number) || string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(password)) - // { - // throw new Exception("Введите номер, ФИО и пароль"); - // } - // APIGuarantor.PostRequest("api/guarantor/updatedata", new GuarantorBindingModel - // { - // Id = APIGuarantor.Guarantor.Id, - // GuarantorNumber = number, - // GuarantorEmail = email, - // GuarantorFIO = FIO, - // GuarantorPassword = password, - // }); + [HttpPost] + public void Privacy(string number, string email, string FIO, string password) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(number) || string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Вы ввели не все данные!"); + } + APIGuarantor.PostRequest("api/guarantor/updatedata", new GuarantorBindingModel + { + Id = APIGuarantor.Guarantor.Id, + GuarantorNumber = number, + GuarantorEmail = email, + GuarantorFIO = FIO, + GuarantorPassword = password, + }); - // APIGuarantor.Guarantor.GuarantorNumber = number; - // APIGuarantor.Guarantor.GuarantorEmail = email; - // APIGuarantor.Guarantor.GuarantorFIO = FIO; - // APIGuarantor.Guarantor.GuarantorPassword = password; - // Response.Redirect("Index"); - //} + APIGuarantor.Guarantor.GuarantorNumber = number; + APIGuarantor.Guarantor.GuarantorEmail = email; + APIGuarantor.Guarantor.GuarantorFIO = FIO; + APIGuarantor.Guarantor.GuarantorPassword = password; + Response.Redirect("Index"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() @@ -62,113 +64,459 @@ namespace ServiceStationGuarantorApp.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - [HttpGet] public IActionResult Enter() { return View(); } + [HttpPost] + public void Enter(string number, string password) + { + if (string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password)) + { + throw new Exception("Не хватает пароля или номера."); + } + APIGuarantor.Guarantor = APIGuarantor.GetRequest($"api/guarantor/login?guarantorNumber={number}&password={password}"); + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } - [HttpGet] public IActionResult Register() { return View(); } - [HttpGet] - public IActionResult ListDefectSparePartToFile() + [HttpPost] + public void Register(string FIO, string number, string password, string email) { - return View(); - } + if (string.IsNullOrEmpty(FIO) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введены не все данные"); + } - [HttpGet] - public IActionResult ListSparePartsToPdfFile() + APIGuarantor.PostRequest("api/guarantor/register", new GuarantorBindingModel + { + GuarantorNumber = number, + GuarantorEmail = email, + GuarantorFIO = FIO, + GuarantorPassword = password + }); + Response.Redirect("Enter"); + return; + } + + //......................................................... Запчасть.............................................................................. + + public IActionResult ListSpareParts() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(APIGuarantor.GetRequest>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}")); + } + + public IActionResult CreateSparePart() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(); + } + + [HttpPost] + public void CreateSparePart(string SparePartName, double SparePartPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/createsparepart", new SparePartBindingModel + { + GuarantorId = APIGuarantor.Guarantor.Id, + SparePartName = SparePartName, + SparePartPrice = SparePartPrice + }); + Response.Redirect("ListSpareParts"); + } + + public IActionResult UpdateSparePart() + { + ViewBag.SpareParts = new List(); + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.SpareParts = APIGuarantor.GetRequest>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateSparePart(int sparepart, string sparepartName, double sparepartPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + if (string.IsNullOrEmpty(sparepartName)) + { + throw new Exception("Введите название запчасти"); + } + if (sparepartPrice < 0) + { + throw new Exception("Цена запчасти не может быть меньше 0"); + } + APIGuarantor.PostRequest("api/main/updatesparepart", new SparePartBindingModel + { + Id = sparepart, + SparePartName = sparepartName, + SparePartPrice = sparepartPrice, + GuarantorId = APIGuarantor.Guarantor.Id + }); + Response.Redirect("ListSpareParts"); + } + + public IActionResult DeleteSparePart() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.SpareParts = APIGuarantor.GetRequest>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void DeleteSparePart(int sparepart) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/deletesparepart", new SparePartBindingModel + { + Id = sparepart + }); + Response.Redirect("ListSpareParts"); + } + + //......................................................... Ремонт.............................................................................. + + public IActionResult ListRepairs() { - return View(); - } + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(APIGuarantor.GetRequest>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}")); + } - [HttpGet] - public IActionResult ListSpareParts() - { - return View(); - } + [HttpGet] + public Tuple? GetRepair(int repairId) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIGuarantor.GetRequest>>>($"api/main/getrepair?repairId={repairId}"); + if (result == null) return default; + string table = ""; + for (int i = 0; i < result.Item2.Count; i++) + { + var sparepartName = result.Item2[i].Item1; + var sparepartPrice = result.Item2[i].Item2; + table += ""; + table += $"{sparepartName}"; + table += $"{sparepartPrice}"; + table += ""; + } + return Tuple.Create(result.Item1, table); + } - [HttpGet] - public IActionResult ListRepairs() - { - return View(); - } + public IActionResult CreateRepair() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(); + } - [HttpGet] + [HttpPost] + public void CreateRepair(string repairName, double repairPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/createrepair", new RepairBindingModel + { + GuarantorId = APIGuarantor.Guarantor.Id, + RepairName = repairName, + RepairPrice = repairPrice + }); + Response.Redirect("ListRepairs"); + } + + public IActionResult UpdateRepair() + { + ViewBag.Repairs = new List(); + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Repairs = APIGuarantor.GetRequest>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateRepair(int repair, string RepairName, double RepairPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + if (string.IsNullOrEmpty(RepairName)) + { + throw new Exception("Введите название ремонта"); + } + if (RepairPrice < 0) + { + throw new Exception("Цена ремонта не может быть меньше 0"); + } + APIGuarantor.PostRequest("api/main/updaterepair", new RepairBindingModel + { + GuarantorId = APIGuarantor.Guarantor.Id, + Id = repair, + RepairName = RepairName, + RepairPrice = RepairPrice + }); + Response.Redirect("ListRepairs"); + } + + public IActionResult DeleteRepair() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Repairs = APIGuarantor.GetRequest>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void DeleteRepair(int repair) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/deleterepair", new RepairBindingModel { Id = repair }); + Response.Redirect("ListRepairs"); + } + + //......................................................... Работа.............................................................................. + + [HttpGet] public IActionResult ListWorks() { - return View(); - } + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(APIGuarantor.GetRequest>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}")); + } - [HttpGet] - public IActionResult CreateSparePart() + [HttpGet] + public Tuple? GetWork(int workId) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIGuarantor.GetRequest>>>($"api/main/getwork?workId={workId}"); + if (result == null) return default; + string table = ""; + for (int i = 0; i < result.Item2.Count; i++) + { + var sparepartName = result.Item2[i].Item1; + var sparepartPrice = result.Item2[i].Item2; + table += ""; + table += $"{sparepartName}"; + table += $"{sparepartPrice}"; + table += ""; + } + return Tuple.Create(result.Item1, table); + } + + public IActionResult CreateWork() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(); + } + + [HttpPost] + public void CreateWork(string WorkName, double WorkPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/creatework", new WorkBindingModel + { + GuarantorId = APIGuarantor.Guarantor.Id, + WorkName = WorkName, + WorkPrice = WorkPrice, + Status = ServiceStationDataModels.Enums.WorkStatus.Принята + }); + Response.Redirect("ListWorks"); + } + + public IActionResult UpdateWork() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Works = APIGuarantor.GetRequest>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateWork(int work, string WorkName, double WorkPrice) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + if (string.IsNullOrEmpty(WorkName)) + { + throw new Exception("Введите название работы"); + } + if (WorkPrice < 0) + { + throw new Exception("Цена работы не может быть меньше 0"); + } + APIGuarantor.PostRequest("api/main/updatework", new WorkBindingModel + { + Id = work, + WorkName = WorkName, + GuarantorId = APIGuarantor.Guarantor.Id, + WorkPrice = WorkPrice, + }); + Response.Redirect("ListWorks"); + } + + public IActionResult DeleteWork() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Works = APIGuarantor.GetRequest>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"); + return View(); + } + + [HttpPost] + public void DeleteWork(int work) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/deletework", new WorkBindingModel { Id = work }); + Response.Redirect("ListWorks"); + } + + [HttpPost] + public void UpdateWorkStatus(int work, string status) { - return View(); + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + if (status == "Отдать на выполнение") + { + APIGuarantor.PostRequest("api/main/updateworkstatusexecution", new WorkBindingModel { Id = work, Status = ServiceStationDataModels.Enums.WorkStatus.Выполняется}); + } + if (status == "Готова") + { + APIGuarantor.PostRequest("api/main/updateworkstatusexecution", new WorkBindingModel { Id = work, Status = ServiceStationDataModels.Enums.WorkStatus.Готова}); + } + Response.Redirect("ListWorks"); } - [HttpGet] - public IActionResult UpdateSparePart() - { - return View(); - } - - [HttpGet] - public IActionResult DeleteSparePart() - { - return View(); - } - - [HttpGet] - public IActionResult CreateRepair() - { - return View(); - } - - [HttpGet] - public IActionResult UpdateRepair() { - return View(); - } - - [HttpGet] - public IActionResult DeleteRepair() + public IActionResult UpdateWorkStatus() { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + ViewBag.Works = APIGuarantor.GetRequest>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"); return View(); } [HttpGet] public IActionResult AddSparepartToRepair() { - return View(); - } + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(Tuple.Create(APIGuarantor.GetRequest>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}"), + APIGuarantor.GetRequest>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"))); + } - [HttpGet] - public IActionResult CreateWork() - { - return View(); - } + [HttpPost] + public void AddSparepartToRepair(int repair, int[] sparepart) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/addspareparttorepair", Tuple.Create(new RepairSearchModel() { Id = repair }, sparepart)); + Response.Redirect("ListRepairs"); + } - [HttpGet] - public IActionResult UpdateWork() - { - return View(); - } + public IActionResult AddSparepartToWork() + { + if (APIGuarantor.Guarantor == null) + { + return RedirectToAction("Enter"); + } + return View(Tuple.Create(APIGuarantor.GetRequest>($"api/main/getworklist?guarantorId={APIGuarantor.Guarantor.Id}"), + APIGuarantor.GetRequest>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"))); + } - [HttpGet] - public IActionResult DeleteWork() - { - return View(); - } + [HttpPost] + public void AddSparepartToWork(int work, int[] sparepart) + { + if (APIGuarantor.Guarantor == null) + { + throw new Exception("Авторизуйтесь"); + } + APIGuarantor.PostRequest("api/main/addspareparttowork", Tuple.Create(new WorkSearchModel() { Id = work }, sparepart)); + Response.Redirect("ListWorks"); + } - [HttpGet] - public IActionResult AddSparepartToWork() - { - return View(); - } + [HttpGet] + public IActionResult ListDefectSparePartToFile() + { + return View(); + } + + [HttpGet] + public IActionResult ListSparePartsToPdfFile() + { + return View(); + } [HttpGet] public IActionResult BindingRepairToDefects() diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToRepair.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToRepair.cshtml index f5f0474..0f04566 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToRepair.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToRepair.cshtml @@ -13,7 +13,10 @@
@@ -27,7 +30,18 @@ - @* тут будет код *@ + @foreach (var sparepart in Model.Item2) + { + + +
+ +
+ + @Html.DisplayFor(modelItem => sparepart.SparePartName) + @Html.DisplayFor(modelItem => sparepart.SparePartPrice) + + }
diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToWork.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToWork.cshtml index 9a5210b..c30ee33 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToWork.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/AddSparepartToWork.cshtml @@ -13,7 +13,10 @@
@@ -27,7 +30,18 @@ - @* тут будет код *@ + @foreach (var sparepart in Model.Item2) + { + + +
+ +
+ + @Html.DisplayFor(modelItem => sparepart.SparePartName) + @Html.DisplayFor(modelItem => sparepart.SparePartPrice) + + }
diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteRepair.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteRepair.cshtml index 560cf69..9741f37 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteRepair.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteRepair.cshtml @@ -8,7 +8,7 @@
- +

diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteSparePart.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteSparePart.cshtml index 6ff983a..d143679 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteSparePart.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteSparePart.cshtml @@ -8,7 +8,7 @@
- +

diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteWork.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteWork.cshtml index 41fd810..6a11476 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteWork.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/DeleteWork.cshtml @@ -7,7 +7,7 @@
- +

diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListRepairs.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListRepairs.cshtml index 7efa688..33ff26d 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListRepairs.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListRepairs.cshtml @@ -11,6 +11,9 @@ + @@ -23,7 +26,23 @@ - @* тут будет код *@ + @foreach (var item in Model) + { + + + + + + + }
+ Номер + Название ремонта
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.RepairName) + + @Html.DisplayFor(modelItem => item.RepairStartDate) + + @Html.DisplayFor(modelItem => item.RepairPrice) +
diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListSpareParts.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListSpareParts.cshtml index 0d88aea..c25669b 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListSpareParts.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListSpareParts.cshtml @@ -1,5 +1,6 @@ @using ServiceStationContracts.ViewModels +@model List @{ ViewData["Title"] = "ListSpareParts"; } @@ -9,6 +10,9 @@ + @@ -18,7 +22,20 @@ - @* тут будет код *@ + @foreach (var item in Model) + { + + + + + + }
+ Номер + Название
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.SparePartName) + + @Html.DisplayFor(modelItem => item.SparePartPrice) +
diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListWorks.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListWorks.cshtml index 387dea2..6ca0603 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListWorks.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/ListWorks.cshtml @@ -1,4 +1,6 @@ - +@using ServiceStationContracts.ViewModels + +@model List @{ ViewData["Title"] = "ListWorks"; } @@ -8,6 +10,9 @@ + @@ -20,7 +25,23 @@ - @* тут будет код *@ + @foreach (var item in Model) + { + + + + + + + }
+ Номер + Название работы
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.WorkName) + + @Html.DisplayFor(modelItem => item.Status) + + @Html.DisplayFor(modelItem => item.WorkPrice) +
\ No newline at end of file diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateRepair.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateRepair.cshtml index 5339d8c..6c5b840 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateRepair.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateRepair.cshtml @@ -8,7 +8,7 @@
- +
@@ -16,7 +16,7 @@
- +
@@ -25,7 +25,7 @@ - + @* тут будет код *@
Стоимость запчасти
@@ -38,4 +38,29 @@
- \ No newline at end of file + + +@section Scripts +{ + +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateSparePart.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateSparePart.cshtml index efd0ac9..a3f209d 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateSparePart.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateSparePart.cshtml @@ -8,7 +8,7 @@
- +
@@ -16,7 +16,7 @@
- +

@@ -27,4 +27,29 @@
- \ No newline at end of file + + +@section Scripts + { + +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWork.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWork.cshtml index e6ecb0a..f2eeb2c 100644 --- a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWork.cshtml +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWork.cshtml @@ -1,6 +1,4 @@ - - -@{ +@{ ViewData["Title"] = "UpdateWork"; } @@ -9,7 +7,7 @@
- +
@@ -17,7 +15,7 @@
- +
@@ -26,7 +24,7 @@ - + @* тут будет код *@
Стоимость запчасти
@@ -40,3 +38,27 @@
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWorkStatus.cshtml b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWorkStatus.cshtml new file mode 100644 index 0000000..d7ae5d6 --- /dev/null +++ b/ServiceStation/ServiceStationGuarantorApp/Views/Home/UpdateWorkStatus.cshtml @@ -0,0 +1,24 @@ +@{ + ViewData["Title"] = "UpdateWorkStatus"; +} + +
+
+
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+
diff --git a/ServiceStation/ServiceStationGuarantorApp/appsettings.json b/ServiceStation/ServiceStationGuarantorApp/appsettings.json index 94e3753..01d7402 100644 --- a/ServiceStation/ServiceStationGuarantorApp/appsettings.json +++ b/ServiceStation/ServiceStationGuarantorApp/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:5244/" + "IPAddress": "https://localhost:7288/" } diff --git a/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs b/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs new file mode 100644 index 0000000..e35ee18 --- /dev/null +++ b/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs @@ -0,0 +1,67 @@ +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 GuarantorController : Controller + { + private readonly IGuarantorLogic _glogic; + private readonly ILogger _logger; + public GuarantorController(IGuarantorLogic glogic, ILogger logger) + { + _glogic = glogic; + _logger = logger; + } + + [HttpPost] + public void Register(GuarantorBindingModel model) + { + try + { + _glogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpGet] + public GuarantorViewModel? Login(string guarantorNumber, string password) + { + try + { + return _glogic.ReadElement(new GuarantorSearchModel + { + GuarantorNumber = guarantorNumber, + GuarantorPassword = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void UpdateGuarantor(GuarantorBindingModel model) + { + try + { + _glogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs index 7cd88fd..141454c 100644 --- a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs +++ b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs @@ -15,13 +15,19 @@ namespace ServiceStationRestApi.Controllers private readonly ICarLogic _clogic; private readonly IDefectLogic _dlogic; private readonly ITechnicalWorkLogic _tlogic; + private readonly ISparePartLogic _splogic; + private readonly IRepairLogic _rlogic; + private readonly IWorkLogic _wlogic; - public MainController(ILogger logger, ICarLogic clogic, IDefectLogic dlogic, ITechnicalWorkLogic tlogic) + public MainController(ILogger logger, ICarLogic clogic, IDefectLogic dlogic, ITechnicalWorkLogic tlogic, ISparePartLogic splogic, IRepairLogic rlogic, IWorkLogic wlogic) { _logger = logger; _clogic = clogic; _dlogic = dlogic; _tlogic = tlogic; + _splogic = splogic; + _rlogic = rlogic; + _wlogic = wlogic; } [HttpGet] @@ -245,5 +251,270 @@ namespace ServiceStationRestApi.Controllers throw; } } + + [HttpGet] + public List? GetSparePartList(int guarantorId) + { + try + { + return _splogic.ReadList(new SparePartSearchModel + { + GuarantorId = guarantorId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка запчастей"); + throw; + } + } + + [HttpPost] + public void CreateSparePart(SparePartBindingModel model) + { + try + { + _splogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания запчасти"); + throw; + } + } + + [HttpPost] + public void UpdateSparePart(SparePartBindingModel model) + { + try + { + _splogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления запчасти"); + throw; + } + } + + [HttpPost] + public void DeleteSparePart(SparePartBindingModel model) + { + try + { + _splogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления запчасти"); + throw; + } + } + + [HttpGet] + public List? GetRepairList(int guarantorId) + { + try + { + return _rlogic.ReadList(new RepairSearchModel + { + GuarantorId = guarantorId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка ремонтов"); + throw; + } + } + + [HttpPost] + public void CreateRepair(RepairBindingModel model) + { + try + { + _rlogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания ремонта"); + throw; + } + } + + [HttpPost] + public void UpdateRepair(RepairBindingModel model) + { + try + { + _rlogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления ремонта"); + throw; + } + } + + [HttpPost] + public void DeleteRepair(RepairBindingModel model) + { + try + { + _rlogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ремонта"); + throw; + } + } + + [HttpGet] + public List? GetWorkList(int guarantorId) + { + try + { + return _wlogic.ReadList(new WorkSearchModel + { + GuarantorId = guarantorId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка работ"); + throw; + } + } + + [HttpPost] + public void CreateWork(WorkBindingModel model) + { + try + { + _wlogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания работы"); + throw; + } + } + + [HttpPost] + public void UpdateWork(WorkBindingModel model) + { + try + { + _wlogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления работы"); + throw; + } + } + + [HttpPost] + public void UpdateWorkStatus(WorkBindingModel model) + { + try + { + _wlogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления статуса работы"); + throw; + } + } + + [HttpPost] + public void UpdateWorkStatusExecution(WorkBindingModel model) + { + try + { + _wlogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления статуса работы"); + throw; + } + } + + [HttpPost] + public void DeleteWork(WorkBindingModel model) + { + try + { + _wlogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления работы"); + throw; + } + } + + [HttpPost] + public void AddSparePartToRepair(Tuple model) + { + try + { + _rlogic.AddSparePartToRepair(model.Item1, model.Item2); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка добавления запчасти в ремонт."); + throw; + } + } + + [HttpPost] + public void AddSparePartToWork(Tuple model) + { + try + { + _wlogic.AddSparePartToWork(model.Item1, model.Item2); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка добавления запчасти в работу."); + throw; + } + } + + [HttpGet] + public Tuple>>? GetRepair(int repairId) + { + try + { + var elem = _rlogic.ReadElement(new RepairSearchModel { Id = repairId }); + if (elem == null) return null; + return Tuple.Create(elem, elem.RepairSpareParts.Select(x => Tuple.Create(x.Value.SparePartName, x.Value.SparePartPrice.ToString("F2"))).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения запчасти по id={Id}", repairId); + throw; + } + } + + [HttpGet] + public Tuple>>? GetWork(int workId) + { + try + { + var elem = _wlogic.ReadElement(new WorkSearchModel { Id = workId }); + if (elem == null) return null; + return Tuple.Create(elem, elem.WorkSpareParts.Select(x => Tuple.Create(x.Value.SparePartName, x.Value.SparePartPrice.ToString("F2"))).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения запчасти по id={Id}", workId); + throw; + } + } } } diff --git a/ServiceStation/ServiceStationRestApi/Program.cs b/ServiceStation/ServiceStationRestApi/Program.cs index 19b842c..cbac3df 100644 --- a/ServiceStation/ServiceStationRestApi/Program.cs +++ b/ServiceStation/ServiceStationRestApi/Program.cs @@ -16,11 +16,22 @@ 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(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();