From f0b5b4a6b79a5fac0399a9d3fb7913910143f01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 25 May 2023 13:31:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/RepairRequestViewModel.cs | 4 +++ .../Implements/RepairRequestStorage.cs | 2 ++ .../Models/RepairRequest.cs | 6 +++- .../Controllers/HomeController.cs | 19 +++++++++- CarService/CarServiceWebApp/Program.cs | 2 ++ .../Views/Home/RepairRequests.cshtml | 36 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 2 +- 7 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml diff --git a/CarService/CarServiceContracts/ViewModels/RepairRequestViewModel.cs b/CarService/CarServiceContracts/ViewModels/RepairRequestViewModel.cs index ec69250..008acf5 100644 --- a/CarService/CarServiceContracts/ViewModels/RepairRequestViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/RepairRequestViewModel.cs @@ -10,5 +10,9 @@ namespace CarServiceContracts.ViewModels [DisplayName("Дата создания")] public DateTime DateCreated { get; set; } = DateTime.Now; public int VehicleId { get; set; } + public string VehicleName { get; set; } = string.Empty; + public string VehiclePlate { get; set; } = string.Empty; + public string VehicleVIN { get; set; } = string.Empty; + public string CustomerName { get; set; } = string.Empty; } } diff --git a/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs index f54c511..489e044 100644 --- a/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs +++ b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs @@ -13,6 +13,8 @@ namespace CarServiceDatabase.Implements { using var context = new CarServiceDbContext(); return context.RepairRequests + .Include(x => x.Vehicle) + .ThenInclude(x => x.Customer) .Select(x => x.GetViewModel) .ToList(); } diff --git a/CarService/CarServiceDatabase/Models/RepairRequest.cs b/CarService/CarServiceDatabase/Models/RepairRequest.cs index a7ab094..22789ae 100644 --- a/CarService/CarServiceDatabase/Models/RepairRequest.cs +++ b/CarService/CarServiceDatabase/Models/RepairRequest.cs @@ -49,7 +49,11 @@ namespace CarServiceDatabase.Models { Id = Id, DateCreated = DateCreated, - VehicleId = VehicleId + VehicleId = VehicleId, + VehicleName = Vehicle.Name, + VehiclePlate = Vehicle.Plate, + VehicleVIN = Vehicle.VIN ?? "Отсутствует", + CustomerName = Vehicle.Customer.Name + " " + Vehicle.Customer.Surname }; } } diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index 7dd39f3..ca432ef 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -14,13 +14,15 @@ namespace CarServiceWebApp.Controllers private readonly IWorkLogic _workLogic; private readonly IWorkerLogic _workerLogic; private readonly IItemLogic _itemLogic; + private readonly IRepairRequestLogic _repairRequestLogic; - public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic) + public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic, IRepairRequestLogic repairRequestLogic) { _logger = logger; _workLogic = workLogic; _workerLogic = workerLogic; _itemLogic = itemLogic; + _repairRequestLogic = repairRequestLogic; } /// /// Главная страница @@ -247,6 +249,21 @@ namespace CarServiceWebApp.Controllers } return Redirect("~/Home/Items"); } + [HttpGet] + public IActionResult RepairRequests() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Index"); + } + var RepairRequests = _repairRequestLogic.ReadList(null); + ViewBag.RepairRequests = RepairRequests; + if (RepairRequests?.Count == 0) + { + ViewBag.Exception = "Пока нет заявок"; + } + return View(); + } /// /// Вывод ошибок /// diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index 187d902..1836894 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -15,6 +15,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml b/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml new file mode 100644 index 0000000..c0263f4 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml @@ -0,0 +1,36 @@ +@{ + ViewData["Title"] = "Заявки на ремонт"; +} + +
+

Заявки

+ @if (ViewBag.RepairRequests.Count != 0) + { +
+ + + + + + + + + + + + @foreach (var request in ViewBag.RepairRequests) + { + + + + + + + + } + +
Дата созданияТранспортное средствоVIN-номерГос. номерКлиент
@request.DateCreated@request.VehicleName@request.VehicleVIN@request.VehiclePlate@request.CustomerName
+
+ } +
@ViewBag.Exception
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml index 7e55390..673ce29 100644 --- a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml +++ b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml @@ -23,7 +23,7 @@ Работы