From f453017dbb474b6713cc075511f2dcb84a47cc61 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 16:55:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D1=80=D1=83=D0=B4=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B2=D1=8F=D0=B7=D0=BE=D0=BA=20=D0=B8=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=BC=D0=BE=D1=82=D1=80=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/ItemForRepairSearchModel.cs | 1 + .../ViewModels/WorkInRequestViewModel.cs | 1 + .../Implements/ItemForRepairStorage.cs | 8 ++- .../Implements/RepairRequestStorage.cs | 2 + .../Implements/WorkInRequestStorage.cs | 3 +- .../Models/RepairRequest.cs | 2 +- .../Models/WorkInRequest.cs | 3 +- .../Controllers/HomeController.cs | 65 ++++++++++++++++++- CarService/CarServiceWebApp/Program.cs | 4 ++ .../Views/Home/Attachment.cshtml | 14 ++++ .../Views/Home/RepairRequest.cshtml | 17 +++++ .../Views/Home/RepairRequests.cshtml | 2 + .../Views/Home/WorksInRequest.cshtml | 14 ++++ 13 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 CarService/CarServiceWebApp/Views/Home/Attachment.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml diff --git a/CarService/CarServiceContracts/SearchModels/ItemForRepairSearchModel.cs b/CarService/CarServiceContracts/SearchModels/ItemForRepairSearchModel.cs index 3a7473e..0619e45 100644 --- a/CarService/CarServiceContracts/SearchModels/ItemForRepairSearchModel.cs +++ b/CarService/CarServiceContracts/SearchModels/ItemForRepairSearchModel.cs @@ -3,5 +3,6 @@ public class ItemForRepairSearchModel { public int? Id { get; set; } + public int? ItemId { get; set; } } } diff --git a/CarService/CarServiceContracts/ViewModels/WorkInRequestViewModel.cs b/CarService/CarServiceContracts/ViewModels/WorkInRequestViewModel.cs index a341113..63fe30b 100644 --- a/CarService/CarServiceContracts/ViewModels/WorkInRequestViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/WorkInRequestViewModel.cs @@ -12,5 +12,6 @@ namespace CarServiceContracts.ViewModels public decimal Cost { get; set; } public int RepairRequestId { get; set; } public int WorkId { get; set; } + public string WorkName { get; set; } = string.Empty; } } diff --git a/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs b/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs index bef70f1..462f0be 100644 --- a/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs +++ b/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs @@ -21,7 +21,7 @@ namespace CarServiceDatabase.Implements { using var context = new CarServiceDbContext(); return context.ItemsForRepair - .Where(x => x.Id == model.Id) + .Where(x => x.RepairRequestId == model.Id) .Include(x => x.Item) .Select(x => x.GetViewModel) .ToList(); @@ -39,6 +39,12 @@ namespace CarServiceDatabase.Implements .Include(x => x.Item) .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } + if (model.ItemId.HasValue) + { + return context.ItemsForRepair + .Include(x => x.Item) + .FirstOrDefault(x => x.ItemId == model.ItemId)?.GetViewModel; + } return null; } public ItemForRepairViewModel? Insert(ItemForRepairBindingModel model) diff --git a/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs index 489e044..bc699b6 100644 --- a/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs +++ b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs @@ -36,6 +36,8 @@ namespace CarServiceDatabase.Implements if (model.Id.HasValue) { return context.RepairRequests + .Include(x => x.Vehicle) + .ThenInclude(x => x.Customer) .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } return null; diff --git a/CarService/CarServiceDatabase/Implements/WorkInRequestStorage.cs b/CarService/CarServiceDatabase/Implements/WorkInRequestStorage.cs index 11de59c..2466945 100644 --- a/CarService/CarServiceDatabase/Implements/WorkInRequestStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkInRequestStorage.cs @@ -20,7 +20,8 @@ namespace CarServiceDatabase.Implements { using var context = new CarServiceDbContext(); return context.WorksInRequest - .Where(x => x.Id == model.Id) + .Include(x => x.Work) + .Where(x => x.RepairRequestId == model.Id) .Select(x => x.GetViewModel) .ToList(); } diff --git a/CarService/CarServiceDatabase/Models/RepairRequest.cs b/CarService/CarServiceDatabase/Models/RepairRequest.cs index 22789ae..cbe297a 100644 --- a/CarService/CarServiceDatabase/Models/RepairRequest.cs +++ b/CarService/CarServiceDatabase/Models/RepairRequest.cs @@ -51,7 +51,7 @@ namespace CarServiceDatabase.Models DateCreated = DateCreated, VehicleId = VehicleId, VehicleName = Vehicle.Name, - VehiclePlate = Vehicle.Plate, + VehiclePlate = Vehicle.Plate ?? "Отсутствует", VehicleVIN = Vehicle.VIN ?? "Отсутствует", CustomerName = Vehicle.Customer.Name + " " + Vehicle.Customer.Surname }; diff --git a/CarService/CarServiceDatabase/Models/WorkInRequest.cs b/CarService/CarServiceDatabase/Models/WorkInRequest.cs index 6cb636d..66e9719 100644 --- a/CarService/CarServiceDatabase/Models/WorkInRequest.cs +++ b/CarService/CarServiceDatabase/Models/WorkInRequest.cs @@ -55,7 +55,8 @@ namespace CarServiceDatabase.Models Count = Count, Cost = Cost, RepairRequestId = RepairRequestId, - WorkId = WorkId + WorkId = WorkId, + WorkName = Work.Name ?? string.Empty }; } } diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index ca432ef..4a31f6e 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -1,7 +1,6 @@ using CarServiceContracts.BindingModels; using CarServiceContracts.BusinessLogicsContracts; using CarServiceContracts.SearchModels; -using CarServiceDatabase.Models; using CarServiceWebApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -15,14 +14,18 @@ namespace CarServiceWebApp.Controllers private readonly IWorkerLogic _workerLogic; private readonly IItemLogic _itemLogic; private readonly IRepairRequestLogic _repairRequestLogic; + private readonly IItemForRepairLogic _itemForRepairLogic; + private readonly IWorkInRequestLogic _workInRequestLogic; - public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic, IRepairRequestLogic repairRequestLogic) + public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic, IRepairRequestLogic repairRequestLogic, IItemForRepairLogic itemForRepairLogic, IWorkInRequestLogic workInRequestLogic) { _logger = logger; _workLogic = workLogic; _workerLogic = workerLogic; _itemLogic = itemLogic; _repairRequestLogic = repairRequestLogic; + _itemForRepairLogic = itemForRepairLogic; + _workInRequestLogic = workInRequestLogic; } /// /// Главная страница @@ -249,6 +252,10 @@ namespace CarServiceWebApp.Controllers } return Redirect("~/Home/Items"); } + /// + /// Вывод списка заявок + /// + /// [HttpGet] public IActionResult RepairRequests() { @@ -264,6 +271,60 @@ namespace CarServiceWebApp.Controllers } return View(); } + [HttpGet] + public IActionResult RepairRequest(int Id) + { + ViewBag.Request = _repairRequestLogic.ReadElement(new() { Id = Id }); + var itemsForRepair = _itemForRepairLogic.ReadList(new() { Id = Id }); + ViewBag.ItemsForRepair = itemsForRepair; + if (itemsForRepair?.Count == 0) + { + ViewBag.Exception = "Пока нет затрат"; + } + return View(); + } + [HttpGet] + public IActionResult Attachment(int Id) + { + //добавляем информацию о заявке + ViewBag.Request = _repairRequestLogic.ReadElement(new() { Id = Id }); + //добавляем статьи затрат + ViewBag.Items = _itemLogic.ReadList(new() { Id = CurrentUser.UserId }); + return View(); + } + [HttpPost] + public IActionResult Attachment(int id, int selecteditem, int count) + { + var existingAttachment = _itemForRepairLogic.ReadElement(new() { ItemId = selecteditem }); + if (existingAttachment == null) + { + _itemForRepairLogic.Create(new() { ItemId = selecteditem, RepairRequestId = id, Count = count }); + } + else + { + existingAttachment.Count = count; + _itemForRepairLogic.Update(new() + { + Id = existingAttachment.Id, + Count = existingAttachment.Count, + ItemId = existingAttachment.ItemId, + RepairRequestId = existingAttachment.RepairRequestId + }); + } + return Redirect($"~/Home/RepairRequest/{id}"); + } + [HttpGet] + public IActionResult WorksInRequest(int Id) + { + ViewBag.Request = _repairRequestLogic.ReadElement(new() { Id = Id }); + var worksInRequest = _workInRequestLogic.ReadList(new() { Id = Id }); + ViewBag.WorksInRequest = worksInRequest; + if (worksInRequest?.Count == 0) + { + ViewBag.Exception = "Пока нет работ"; + } + return View(); + } /// /// Вывод ошибок /// diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index 1836894..fa9562c 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -17,6 +17,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); 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/Attachment.cshtml b/CarService/CarServiceWebApp/Views/Home/Attachment.cshtml new file mode 100644 index 0000000..5db52bc --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/Attachment.cshtml @@ -0,0 +1,14 @@ +@{ + ViewData["Title"] = "Запчасть для заявки"; +} +

Заявка № @ViewBag.Request.Id

+ +
+ + @foreach (var item in ViewBag.Items) + { +

@item.Name

+ } +

Количество

+
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml b/CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml new file mode 100644 index 0000000..0c8cdf9 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml @@ -0,0 +1,17 @@ +
+

Заявка № @ViewBag.Request.Id

+

Транспортное средство @ViewBag.Request.VehicleName

+

Клиент @ViewBag.Request.CustomerName

+

Затраты:

+ @if (ViewBag.ItemsForRepair.Count != 0) + { + @foreach (var item in ViewBag.ItemsForRepair) + { +

@(item.ItemName + " " + item.Count + "шт.")

+ } + } +
@ViewBag.Exception
+
+ Добавить +
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml b/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml index c0263f4..82d9cec 100644 --- a/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/RepairRequests.cshtml @@ -26,6 +26,8 @@ @request.VehicleVIN @request.VehiclePlate @request.CustomerName + Затраты + Работы } diff --git a/CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml b/CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml new file mode 100644 index 0000000..4568a01 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml @@ -0,0 +1,14 @@ +
+

Заявка № @ViewBag.Request.Id

+

Транспортное средство @ViewBag.Request.VehicleName

+

Клиент @ViewBag.Request.CustomerName

+

Работы:

+ @if (ViewBag.WorksInRequest.Count != 0) + { + @foreach (var work in ViewBag.WorksInRequest) + { +

@(work.WorkName + " " + work.Count + "шт.")

+ } + } +
@ViewBag.Exception
+
\ No newline at end of file