доработки связей

This commit is contained in:
goldfest 2024-05-28 22:41:52 +04:00
parent 6daea90ac0
commit ab84581418
14 changed files with 110 additions and 8 deletions

View File

@ -33,6 +33,9 @@
<th>
Модель машины
</th>
<th>
Стоимость машины
</th>
<th>
Изменить машину
</th>

View File

@ -36,6 +36,12 @@
<th>
Дата осмотра
</th>
<th>
Сотрудник
</th>
<th>
Привязка сотрудника к осмотру
</th>
<th>
Изменить осмотр
</th>
@ -60,6 +66,12 @@
<td>
@Html.DisplayFor(modelItem => item.InspectionDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeName)
</td>
<td>
<a asp-action="InspectionEmployeeAdd" asp-route-id="@item.Id" class="btn btn-primary">Привязать сотрудника</a>
</td>
<td>
<a asp-action="CreateInspection" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>

View File

@ -0,0 +1,32 @@
@using CarCenterContracts.ViewModels
@model List<EmployeeViewModel>
@{
ViewData["Title"] = "Inspection-Add-Employee";
}
<div class="text-center">
<h1 class="display-4">Осмотр - @ViewBag.Inspection.InspectionName</h1>
</div>
<div class="container">
<h1>Список сотрудников</h1>
<div class="row">
@foreach (var employee in Model)
{
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">@employee.EmployeeFIO</h5>
<form asp-action="InspectionEmployeeAdd" method="post">
<input type="hidden" name="InspectionId" value="@ViewBag.Inspection.Id" />
<input type="hidden" name="EmployeeId" value="@employee.Id" />
<button type="submit" class="btn btn-primary">Выбрать</button>
</form>
</div>
</div>
</div>
}
</div>
</div>

View File

@ -12,7 +12,7 @@ namespace CarCenterContracts.BindingModels
public int Id { get; set; }
public string InspectionName { get; set; } = string.Empty;
public double InspectionCost { get; set; }
public DateTime? InspectionDate { get; set; }
public DateTime? InspectionDate { get; set; } = DateTime.Now;
public int AdministratorId { get; set; }
public int? EmployeeId { get; set; }
public Dictionary<int, ICarSalesModel> InspectionCars { get; set; } = new();

View File

@ -7,7 +7,7 @@ namespace CarCenterContracts.BindingModels
public int Id { get; set; }
public string PreSaleWorkType { get; set; } = string.Empty;
public double PreSaleWorkPrice { get; set; }
public DateTime? PreSaleWorkDate { get; set; }
public DateTime? PreSaleWorkDate { get; set; } = DateTime.Now;
public int ManagerId { get; set; }
public int? CompletionsId { get; set; }
public Dictionary<int, ISaleModel> PreSaleWorkSales { get; set; } = new();

View File

@ -6,5 +6,7 @@
public string? EmployeeFIO { get; set; }
public int? ManagerId { get; set; }
public int? SaleId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -9,7 +9,7 @@ namespace CarCenterDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter2;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);

View File

@ -29,15 +29,15 @@ namespace CarCenterDataBaseImplement.Implements
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (!model.ManagerId.HasValue && !model.SaleId.HasValue)
if (!model.ManagerId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{
return new();
}
using var context = new CarCenterDataBase();
if (model.SaleId.HasValue)
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).Where(x => x.ManagerId == model.ManagerId).Where(x => x.Sales.FirstOrDefault(y => y.SaleId == model.SaleId) != null).Include(x => x.Manager).Select(x => x.GetViewModel).ToList();
if (model.DateFrom.HasValue)
return context.Employees.Where(x => x.ManagerId == model.ManagerId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
else
return context.Employees.Include(x => x.Sales).ThenInclude(x => x.Sale).Where(x => x.ManagerId == model.ManagerId).Select(x => x.GetViewModel).ToList();
return context.Employees.Where(x => x.ManagerId == model.ManagerId).Select(x => x.GetViewModel).ToList();
}
public List<EmployeeViewModel> GetFullList()

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CarCenterDataBaseImplement.Migrations
{
[DbContext(typeof(CarCenterDataBase))]
[Migration("20240528154442_InitialCreate")]
[Migration("20240528181101_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -150,6 +150,9 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");

View File

@ -99,6 +99,7 @@ namespace CarCenterDataBaseImplement.Migrations
EmployeeFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
EmployeePost = table.Column<string>(type: "nvarchar(max)", nullable: false),
EmployeeSalary = table.Column<double>(type: "float", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
ManagerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>

View File

@ -147,6 +147,9 @@ namespace CarCenterDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");

View File

@ -18,6 +18,8 @@ namespace CarCenterDataBaseImplement.Models
[Required]
public double EmployeeSalary { get; set; }
[Required]
public DateTime DateCreate { get; set; } = DateTime.Now;
public int ManagerId { get; private set; }

View File

@ -36,6 +36,12 @@
<th>
Дата предпродажной работы
</th>
<th>
Комплектация
</th>
<th>
Привязка комплектации к предпродажной работе
</th>
<th>
Изменить предпродажную работу
</th>
@ -60,6 +66,12 @@
<td>
@Html.DisplayFor(modelItem => item.PreSaleWorkDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.CompletionName)
</td>
<td>
<a asp-action="PreSaleWorkCompletionsAdd" asp-route-id="@item.Id" class="btn btn-primary">Привязать комплектацию</a>
</td>
<td>
<a asp-action="CreatePreSaleWork" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>

View File

@ -0,0 +1,32 @@
@using CarCenterContracts.ViewModels
@model List<CompletionsViewModel>
@{
ViewData["Title"] = "PreSaleWork-Add-Completion";
}
<div class="text-center">
<h1 class="display-4">Предпродажная работа - @ViewBag.PreSaleWork.PreSaleWorkType</h1>
</div>
<div class="container">
<h1>Список комплектаций</h1>
<div class="row">
@foreach (var Completions in Model)
{
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">@Completions.СompletionName</h5>
<form asp-action="PreSaleWorkCompletionsAdd" method="post">
<input type="hidden" name="PreSaleWorkId" value="@ViewBag.PreSaleWork.Id" />
<input type="hidden" name="CompletionsId" value="@Completions.Id" />
<button type="submit" class="btn btn-primary">Выбрать</button>
</form>
</div>
</div>
</div>
}
</div>
</div>