круд привязок и просмотр работ
This commit is contained in:
parent
f0b5b4a6b7
commit
f453017dbb
@ -3,5 +3,6 @@
|
|||||||
public class ItemForRepairSearchModel
|
public class ItemForRepairSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public int? ItemId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,6 @@ namespace CarServiceContracts.ViewModels
|
|||||||
public decimal Cost { get; set; }
|
public decimal Cost { get; set; }
|
||||||
public int RepairRequestId { get; set; }
|
public int RepairRequestId { get; set; }
|
||||||
public int WorkId { get; set; }
|
public int WorkId { get; set; }
|
||||||
|
public string WorkName { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace CarServiceDatabase.Implements
|
|||||||
{
|
{
|
||||||
using var context = new CarServiceDbContext();
|
using var context = new CarServiceDbContext();
|
||||||
return context.ItemsForRepair
|
return context.ItemsForRepair
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.RepairRequestId == model.Id)
|
||||||
.Include(x => x.Item)
|
.Include(x => x.Item)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -39,6 +39,12 @@ namespace CarServiceDatabase.Implements
|
|||||||
.Include(x => x.Item)
|
.Include(x => x.Item)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
.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;
|
return null;
|
||||||
}
|
}
|
||||||
public ItemForRepairViewModel? Insert(ItemForRepairBindingModel model)
|
public ItemForRepairViewModel? Insert(ItemForRepairBindingModel model)
|
||||||
|
@ -36,6 +36,8 @@ namespace CarServiceDatabase.Implements
|
|||||||
if (model.Id.HasValue)
|
if (model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return context.RepairRequests
|
return context.RepairRequests
|
||||||
|
.Include(x => x.Vehicle)
|
||||||
|
.ThenInclude(x => x.Customer)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -20,7 +20,8 @@ namespace CarServiceDatabase.Implements
|
|||||||
{
|
{
|
||||||
using var context = new CarServiceDbContext();
|
using var context = new CarServiceDbContext();
|
||||||
return context.WorksInRequest
|
return context.WorksInRequest
|
||||||
.Where(x => x.Id == model.Id)
|
.Include(x => x.Work)
|
||||||
|
.Where(x => x.RepairRequestId == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace CarServiceDatabase.Models
|
|||||||
DateCreated = DateCreated,
|
DateCreated = DateCreated,
|
||||||
VehicleId = VehicleId,
|
VehicleId = VehicleId,
|
||||||
VehicleName = Vehicle.Name,
|
VehicleName = Vehicle.Name,
|
||||||
VehiclePlate = Vehicle.Plate,
|
VehiclePlate = Vehicle.Plate ?? "Отсутствует",
|
||||||
VehicleVIN = Vehicle.VIN ?? "Отсутствует",
|
VehicleVIN = Vehicle.VIN ?? "Отсутствует",
|
||||||
CustomerName = Vehicle.Customer.Name + " " + Vehicle.Customer.Surname
|
CustomerName = Vehicle.Customer.Name + " " + Vehicle.Customer.Surname
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,8 @@ namespace CarServiceDatabase.Models
|
|||||||
Count = Count,
|
Count = Count,
|
||||||
Cost = Cost,
|
Cost = Cost,
|
||||||
RepairRequestId = RepairRequestId,
|
RepairRequestId = RepairRequestId,
|
||||||
WorkId = WorkId
|
WorkId = WorkId,
|
||||||
|
WorkName = Work.Name ?? string.Empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using CarServiceContracts.BindingModels;
|
using CarServiceContracts.BindingModels;
|
||||||
using CarServiceContracts.BusinessLogicsContracts;
|
using CarServiceContracts.BusinessLogicsContracts;
|
||||||
using CarServiceContracts.SearchModels;
|
using CarServiceContracts.SearchModels;
|
||||||
using CarServiceDatabase.Models;
|
|
||||||
using CarServiceWebApp.Models;
|
using CarServiceWebApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -15,14 +14,18 @@ namespace CarServiceWebApp.Controllers
|
|||||||
private readonly IWorkerLogic _workerLogic;
|
private readonly IWorkerLogic _workerLogic;
|
||||||
private readonly IItemLogic _itemLogic;
|
private readonly IItemLogic _itemLogic;
|
||||||
private readonly IRepairRequestLogic _repairRequestLogic;
|
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;
|
_logger = logger;
|
||||||
_workLogic = workLogic;
|
_workLogic = workLogic;
|
||||||
_workerLogic = workerLogic;
|
_workerLogic = workerLogic;
|
||||||
_itemLogic = itemLogic;
|
_itemLogic = itemLogic;
|
||||||
_repairRequestLogic = repairRequestLogic;
|
_repairRequestLogic = repairRequestLogic;
|
||||||
|
_itemForRepairLogic = itemForRepairLogic;
|
||||||
|
_workInRequestLogic = workInRequestLogic;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Главная страница
|
/// Главная страница
|
||||||
@ -249,6 +252,10 @@ namespace CarServiceWebApp.Controllers
|
|||||||
}
|
}
|
||||||
return Redirect("~/Home/Items");
|
return Redirect("~/Home/Items");
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод списка заявок
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult RepairRequests()
|
public IActionResult RepairRequests()
|
||||||
{
|
{
|
||||||
@ -264,6 +271,60 @@ namespace CarServiceWebApp.Controllers
|
|||||||
}
|
}
|
||||||
return View();
|
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>
|
||||||
/// Вывод ошибок
|
/// Вывод ошибок
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -17,6 +17,10 @@ builder.Services.AddTransient<IItemLogic, ItemLogic>();
|
|||||||
builder.Services.AddTransient<IItemStorage, ItemStorage>();
|
builder.Services.AddTransient<IItemStorage, ItemStorage>();
|
||||||
builder.Services.AddTransient<IRepairRequestLogic, RepairRequestLogic>();
|
builder.Services.AddTransient<IRepairRequestLogic, RepairRequestLogic>();
|
||||||
builder.Services.AddTransient<IRepairRequestStorage, RepairRequestStorage>();
|
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();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
14
CarService/CarServiceWebApp/Views/Home/Attachment.cshtml
Normal file
14
CarService/CarServiceWebApp/Views/Home/Attachment.cshtml
Normal 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>
|
17
CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml
Normal file
17
CarService/CarServiceWebApp/Views/Home/RepairRequest.cshtml
Normal 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>
|
@ -26,6 +26,8 @@
|
|||||||
<td>@request.VehicleVIN</td>
|
<td>@request.VehicleVIN</td>
|
||||||
<td>@request.VehiclePlate</td>
|
<td>@request.VehiclePlate</td>
|
||||||
<td>@request.CustomerName</td>
|
<td>@request.CustomerName</td>
|
||||||
|
<td><a href="/Home/RepairRequest/@request.Id">Затраты</a></td>
|
||||||
|
<td><a href="/Home/WorksInRequest/@request.Id">Работы</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
14
CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml
Normal file
14
CarService/CarServiceWebApp/Views/Home/WorksInRequest.cshtml
Normal 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>
|
Loading…
Reference in New Issue
Block a user