круд привязок и просмотр работ

This commit is contained in:
Мк Игорь 2023-05-25 16:55:46 +04:00
parent f0b5b4a6b7
commit f453017dbb
13 changed files with 130 additions and 6 deletions

View File

@ -3,5 +3,6 @@
public class ItemForRepairSearchModel
{
public int? Id { get; set; }
public int? ItemId { get; set; }
}
}

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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;

View File

@ -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();
}

View File

@ -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
};

View File

@ -55,7 +55,8 @@ namespace CarServiceDatabase.Models
Count = Count,
Cost = Cost,
RepairRequestId = RepairRequestId,
WorkId = WorkId
WorkId = WorkId,
WorkName = Work.Name ?? string.Empty
};
}
}

View File

@ -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<HomeController> logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic, IRepairRequestLogic repairRequestLogic)
public HomeController(ILogger<HomeController> 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;
}
/// <summary>
/// Главная страница
@ -249,6 +252,10 @@ namespace CarServiceWebApp.Controllers
}
return Redirect("~/Home/Items");
}
/// <summary>
/// Вывод списка заявок
/// </summary>
/// <returns></returns>
[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();
}
/// <summary>
/// Вывод ошибок
/// </summary>

View File

@ -17,6 +17,10 @@ builder.Services.AddTransient<IItemLogic, ItemLogic>();
builder.Services.AddTransient<IItemStorage, ItemStorage>();
builder.Services.AddTransient<IRepairRequestLogic, RepairRequestLogic>();
builder.Services.AddTransient<IRepairRequestStorage, RepairRequestStorage>();
builder.Services.AddTransient<IItemForRepairLogic, ItemForRepairLogic>();
builder.Services.AddTransient<IItemForRepairStorage, ItemForRepairStorage>();
builder.Services.AddTransient<IWorkInRequestLogic, WorkInRequestLogic>();
builder.Services.AddTransient<IWorkInRequestStorage, WorkInRequestStorage>();
var app = builder.Build();

View File

@ -0,0 +1,14 @@
@{
ViewData["Title"] = "Запчасть для заявки";
}
<h1>Заявка № @ViewBag.Request.Id</h1>
<form method="post">
<div hidden><input name="id" value="@ViewBag.Request.Id"/></div>
@foreach (var item in ViewBag.Items)
{
<p><input type="radio" id="@item.Id" name="selecteditem" value="@item.Id">@item.Name</p>
}
<p><input name="count" type="number">Количество</p>
<div><center><input type="submit" value="Добавить запчасть" class="btn btn-primary" /></center></div>
</form>

View File

@ -0,0 +1,17 @@
<div>
<h1>Заявка № @ViewBag.Request.Id</h1>
<p>Транспортное средство @ViewBag.Request.VehicleName</p>
<p>Клиент @ViewBag.Request.CustomerName</p>
<p>Затраты:</p>
@if (ViewBag.ItemsForRepair.Count != 0)
{
@foreach (var item in ViewBag.ItemsForRepair)
{
<p><div>@(item.ItemName + " " + item.Count + "шт.")</div></p>
}
}
<div>@ViewBag.Exception</div>
<form>
<a href ="/Home/Attachment/@ViewBag.Request.Id" class="btn btn-primary">Добавить</a>
</form>
</div>

View File

@ -26,6 +26,8 @@
<td>@request.VehicleVIN</td>
<td>@request.VehiclePlate</td>
<td>@request.CustomerName</td>
<td><a href="/Home/RepairRequest/@request.Id">Затраты</a></td>
<td><a href="/Home/WorksInRequest/@request.Id">Работы</a></td>
</tr>
}
</tbody>

View File

@ -0,0 +1,14 @@
<div>
<h1>Заявка № @ViewBag.Request.Id</h1>
<p>Транспортное средство @ViewBag.Request.VehicleName</p>
<p>Клиент @ViewBag.Request.CustomerName</p>
<p>Работы:</p>
@if (ViewBag.WorksInRequest.Count != 0)
{
@foreach (var work in ViewBag.WorksInRequest)
{
<p><div>@(work.WorkName + " " + work.Count + "шт.")</div></p>
}
}
<div>@ViewBag.Exception</div>
</div>