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