все сделано, осталось отчеты и почта, сущности товарища исвязать их

This commit is contained in:
Леонид Малафеев 2024-05-28 22:04:05 +04:00
parent 749f04230f
commit 734af235ad
13 changed files with 407 additions and 134 deletions

View File

@ -12,7 +12,6 @@ namespace CarCenterContracts.BindingModels
{
public int Id { get; set; }
public int StorekeeperId { get; set; }
public int OrderId { get; set; }
public CarBrand CarBrand { get; set; } = CarBrand.Неизвестно;
public string Model { get; set; } = string.Empty;
public CarClass CarClass { get; set; } = CarClass.Неизвестно;

View File

@ -15,11 +15,7 @@ namespace CarCenterContracts.ViewModels
public int? OrderId { get; set; }
[DisplayName("ФИО покупателя")]
public string BuyerFCS { get; set; } = string.Empty;
[DisplayName("Цена особенности")]
public double FeaturePrice { get; set; }
public int StorekeeperId { get; set; }
[DisplayName("Имя кладовщика")]
public string StorekeeperName { get; set; } = string.Empty;
[DisplayName("Марка")]
public CarBrand CarBrand { get; set; }
[DisplayName("Модель")]

View File

@ -43,7 +43,7 @@ namespace CarCenterDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Id.HasValue)
else if (model.StorekeeperId.HasValue)
{
return context.Cars
.Where(x => x.StorekeeperId == model.StorekeeperId)
@ -52,7 +52,6 @@ namespace CarCenterDatabaseImplement.Implements
.Include(x => x.Feature)
.Include(x => x.Order)
.Include(x => x.Storekeeper)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace CarCenterDatabaseImplement.Migrations
{
[DbContext(typeof(CarCenterDatabase))]
[Migration("20240528143805_InitialCreate3")]
partial class InitialCreate3
[Migration("20240528175849_Initia8")]
partial class Initia8
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -76,7 +76,7 @@ namespace CarCenterDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<int>("OrderId")
b.Property<int?>("OrderId")
.HasColumnType("integer");
b.Property<double>("Price")
@ -363,9 +363,7 @@ namespace CarCenterDatabaseImplement.Migrations
b.HasOne("CarCenterDatabaseImplement.Models.Order", "Order")
.WithMany("Cars")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OrderId");
b.HasOne("CarCenterDatabaseImplement.Models.Storekeeper", "Storekeeper")
.WithMany("Cars")

View File

@ -6,7 +6,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace CarCenterDatabaseImplement.Migrations
{
public partial class InitialCreate3 : Migration
public partial class Initia8 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@ -174,7 +174,6 @@ namespace CarCenterDatabaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StorekeeperId = table.Column<int>(type: "integer", nullable: false),
OrderId = table.Column<int>(type: "integer", nullable: false),
FeatureId = table.Column<int>(type: "integer", nullable: true),
CarBrand = table.Column<int>(type: "integer", nullable: false),
Model = table.Column<string>(type: "text", nullable: false),
@ -182,7 +181,8 @@ namespace CarCenterDatabaseImplement.Migrations
Year = table.Column<int>(type: "integer", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
VINnumber = table.Column<long>(type: "bigint", nullable: false),
FeatureID = table.Column<int>(type: "integer", nullable: false)
FeatureID = table.Column<int>(type: "integer", nullable: false),
OrderId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
@ -196,8 +196,7 @@ namespace CarCenterDatabaseImplement.Migrations
name: "FK_Cars_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
table.ForeignKey(
name: "FK_Cars_Storekeepers_StorekeeperId",
column: x => x.StorekeeperId,

View File

@ -74,7 +74,7 @@ namespace CarCenterDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<int>("OrderId")
b.Property<int?>("OrderId")
.HasColumnType("integer");
b.Property<double>("Price")
@ -361,9 +361,7 @@ namespace CarCenterDatabaseImplement.Migrations
b.HasOne("CarCenterDatabaseImplement.Models.Order", "Order")
.WithMany("Cars")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OrderId");
b.HasOne("CarCenterDatabaseImplement.Models.Storekeeper", "Storekeeper")
.WithMany("Cars")

View File

@ -17,7 +17,6 @@ namespace CarCenterDatabaseImplement.Models
{
public int Id { get; private set; }
public int StorekeeperId { get; set; }
public int OrderId { get; set; }
public int? FeatureId { get; set; }
[Required]
public CarBrand CarBrand { get; set; } = CarBrand.Неизвестно;
@ -35,7 +34,7 @@ namespace CarCenterDatabaseImplement.Models
public int FeatureID { get; set; }
public virtual Storekeeper Storekeeper { get; set; }
public virtual Feature Feature { get; set; }
public virtual Order Order { get; set; }
public virtual Order? Order { get; set; }
private Dictionary<int, IBundlingModel>? _carBundlings = null;
[ForeignKey("CarId")]
@ -63,7 +62,6 @@ namespace CarCenterDatabaseImplement.Models
Id = model.Id,
StorekeeperId = model.StorekeeperId,
FeatureId = model.FeatureID,
OrderId = model.OrderId,
CarBrand = model.CarBrand,
Model = model.Model,
CarClass = model.CarClass,
@ -101,7 +99,6 @@ namespace CarCenterDatabaseImplement.Models
}
StorekeeperId = model.StorekeeperId;
FeatureId = model.FeatureID;
OrderId = model.OrderId;
CarBrand = model.CarBrand;
Model = model.Model;
CarClass = model.CarClass;
@ -114,9 +111,6 @@ namespace CarCenterDatabaseImplement.Models
{
Id = Id,
StorekeeperId = StorekeeperId,
StorekeeperName = Storekeeper?.Name ?? string.Empty,// не понял че было
FeaturePrice = Feature?.Price ?? 0,
OrderId = OrderId,
BuyerFCS = Order?.BuyerFCS ?? string.Empty,
CarBrand = CarBrand,
Model = Model,

View File

@ -1,12 +1,14 @@
using CarCenterContracts.BindingModels;
using CarCenterContracts.ViewModels;
using CarCenterStorekeeperApp.Models;
using ImplementerApp;
using StorekeeperApp;
using Microsoft.AspNetCore.Mvc;
using StorekeeperApp;
using System.Diagnostics;
using System.IO;
using System.Numerics;
using ImplementerApp;
using CarCenterDataModels.Enums;
namespace CarCenterStorekeeperApp.Controllers
{
@ -168,6 +170,79 @@ namespace CarCenterStorekeeperApp.Controllers
}
return View();
}
[HttpGet]
public IActionResult IndexCar()
{
if (UserStorekeeper.user != null)
{
var productions = _data.GetCars(UserStorekeeper.user.Id);
return View(productions);
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexCar(int id)
{
_data.DeleteCar(id);
return RedirectToAction("IndexCar");
}
[HttpGet]
public IActionResult CreateCar(int id)
{
var bundlings = _data.GetBundlings(UserStorekeeper.user!.Id);
var features = _data.GetFeatures(UserStorekeeper.user!.Id);
ViewBag.AllBundlings = bundlings;
ViewBag.Features = features;
if (id != 0)
{
var value = _data.GetCar(id);
if (value != null)
return View(value);
}
return View(new CarViewModel());
}
[HttpPost]
public IActionResult CreateCar(int id, int year, long VINnumber, CarBrand CarBrand, CarClass CarClass, int FeatureId, string Model, int[] bundlingIds)
{
CarBindingModel model = new CarBindingModel();
model.Id = id;
model.Year = year;
model.VINnumber = VINnumber;
model.CarBrand = CarBrand;
model.CarClass = CarClass;
model.FeatureID = FeatureId;
model.Model = Model;
model.StorekeeperId = UserStorekeeper.user!.Id;
var bundlings = _data.GetBundlings(UserStorekeeper.user!.Id);
double sum = 0;
for (int i = 0; i < bundlingIds.Length; i++)
{
var bundling = bundlings!.FirstOrDefault(x => x.Id == bundlingIds[i])!;
model.CarBundlings[bundlingIds[i]] = bundling;
sum += bundling.Price;
}
model.Price = sum;
bool changed = false;
if (model.CarBundlings.Count > 0)
{
if (id != 0)
{
changed = _data.UpdateCar(model);
}
else
{
changed = _data.CreateCar(model);
}
}
if (changed)
return RedirectToAction("IndexCar");
else
{
ViewBag.AllBundlings = bundlings;
return View(model);
}
}
[HttpGet]
public IActionResult Privacy()
{

View File

@ -12,13 +12,15 @@ namespace StorekeeperApp
private readonly IStorekeeperLogic _storekeeperLogic;
private readonly IBundlingLogic _bundlingLogic;
private readonly IFeatureLogic _featureLogic;
private readonly ICarLogic _carLogic;
public StorekeeperData(ILogger<StorekeeperData> logger, IStorekeeperLogic storekeeperLogic, IBundlingLogic bundlingLogic, IFeatureLogic featureLogic)
public StorekeeperData(ILogger<StorekeeperData> logger, IStorekeeperLogic storekeeperLogic, IBundlingLogic bundlingLogic, IFeatureLogic featureLogic, ICarLogic carLogic)
{
_logger = logger;
_storekeeperLogic = storekeeperLogic;
_bundlingLogic = bundlingLogic;
_featureLogic = featureLogic;
_carLogic = carLogic;
}
public StorekeeperViewModel? Login(string email, string password)
@ -78,7 +80,26 @@ namespace StorekeeperApp
{
return _featureLogic.ReadElement(new() { Id = id });
}
public List<CarViewModel>? GetCars(int userId)
{
return _carLogic.ReadList(new() { StorekeeperId = userId });
}
public CarViewModel? GetCar(int id)
{
return _carLogic.ReadElement(new() { Id = id });
}
public bool CreateCar(CarBindingModel model)
{
return _carLogic.Create(model);
}
public bool UpdateCar(CarBindingModel model)
{
return _carLogic.Update(model);
}
public bool DeleteCar(int carId)
{
return _carLogic.Delete(new() { Id = carId });
}
}
}

View File

@ -1,102 +0,0 @@
@using CarCenterContracts.ViewModels
@model List<CarViewModel>
@{
ViewData["Title"] = "Cars";
}
<div class="text-center">
<h1 class="display-4">Машины</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h2 class="display-4">Надо войти в аккаунт.</h2>
return;
}
<p>
<a class="text-decoration-none me-3 text-black h5" asp-action="Create">Создать машину</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="Update">Изменить машину</a>
<a class="text-decoration-none text-black h5" asp-action="Delete">Удалить машину</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер заказа
</th>
<th>
Покупатель
</th>
<th>
Цена особенности
</th>
<th>
Имя кладовщика
</th>
<th>
Марка
</th>
<th>
Модель
</th>
<th>
Класс
</th>
<th>
Год выпуска
</th>
<th>
Вин-номер
</th>
<th>
Цена
</th>
<th>
Комплектации
</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => car.OrderId)
</td>
<td>
@Html.DisplayFor(modelItem => car.BuyerFCS)
</td>
<td>
@Html.DisplayFor(modelItem => car.FeaturePrice)
</td>
<td>
@Html.DisplayFor(modelItem => car.StorekeeperName)
</td>
<td>
@Html.DisplayFor(modelItem => car.CarBrand)
</td>
<td>
@Html.DisplayFor(modelItem => car.Model)
</td>
<td>
@Html.DisplayFor(modelItem => car.CarClass)
</td>
<td>
@Html.DisplayFor(modelItem => car.Year)
</td>
<td>
@Html.DisplayFor(modelItem => car.VINnumber)
</td>
<td>
@Html.DisplayFor(modelItem => car.Price)
</td>
<td>
@Html.DisplayFor(modelItem => car.CarBundlings)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,213 @@
@using CarCenterContracts.ViewModels;
@using CarCenterDataModels.Enums;
@model CarViewModel
@{
ViewData["Title"] = "CreateCar";
ViewBag.Bundlings = Model.CarBundlings;
}
<div class="text-center">
<h2 class="display-4">Создание автомобиля</h2>
</div>
<form id="carForm" method="post">
<div class="row">
<div class="col-4">Марка:</div>
<div class="col-8">
<select name="CarBrand" id="CarBrand" value="@Model.CarBrand">
@foreach (var value in Enum.GetValues(typeof(CarBrand)))
{
<option value="@value">@value</option>
}
</select>
<span id="CarBrandError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Модель:</div>
<div class="col-8">
<input type="text" name="Model" id="Model" value="@Model.Model" />
<span id="ModelError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Класс:</div>
<div class="col-8">
<select name="CarClass" id="CarClass" value="@Model.CarClass">
@foreach (var value in Enum.GetValues(typeof(CarClass)))
{
<option value="@value">@value</option>
}
</select>
<span id="CarClassError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Год выпуска:</div>
<div class="col-8">
<input type="text" name="Year" id="Year" value="@Model.Year" />
<span id="YearError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">ВИН-номер:</div>
<div class="col-8">
<input type="text" name="VINnumber" id="VINnumber" value="@Model.VINnumber" />
<span id="VINnumberError" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-4">Особенность:</div>
<div class="col-8">
<select name="FeatureId" id="FeatureId">
@foreach (var feature in ViewBag.Features)
{
<option value="@feature.Id">Особенность @feature.Id</option>
}
</select>
<span id="FeatureIdError" class="text-danger"></span>
</div>
</div>
<div class="container">
<div>Детали</div>
<div class="table-responsive-lg">
<table id="bundlingsTable" class="display">
<thead>
<tr>
<th>ID комплектации</th>
<th> </th>
<th>Стоимость</th>
<th> </th>
<th>Удалить</th>
</tr>
</thead>
<tbody>
@foreach (var bundling in ViewBag.Bundlings)
{
<tr data-bundling-id="@bundling.Value.Id">
<td>
<input type="hidden" name="bundlingIds" value="@bundling.Value.Id" />@bundling.Value.Id
</td>
<th> </th>
<td class="bundling-price" data-price="@bundling.Value.Price">@bundling.Value.Price</td>
<th> </th>
<td><button type="button" class="deleteBundling" data-bundling-id="@bundling.Value.Id">Удалить</button></td>
</tr>
}
</tbody>
</table>
</div>
<select id="bundlingSelect" class="form-control">
<option value="">Выберите комплектацию</option>
@foreach (var bundling in ViewBag.AllBundlings)
{
<option value="@bundling.Id" data-price="@bundling.Price">Комплектация @bundling.Id</option>
}
</select>
<button type="button" id="addBundling" class="btn btn-secondary">Добавить комплектацию</button>
</div>
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8"><input type="text" id="sum" name="sum" readonly /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function () {
function updateSum() {
var sum = 0;
$('#bundlingsTable tbody tr').each(function () {
var price = $(this).find('.bundling-price').data('price');
sum += parseFloat(price);
});
$('#sum').val(sum.toFixed(2));
}
$(document).on('click', '.deleteBundling', function () {
var row = $(this).closest('tr');
row.remove();
updateSum();
});
$('#addBundling').click(function () {
var selectedBundling = $('#bundlingSelect option:selected');
if (selectedBundling.val()) {
var bundlingId = selectedBundling.val();
var exists = false;
$('#bundlingsTable tbody tr').each(function () {
if ($(this).data('bundling-id') == bundlingId) {
exists = true;
return false;
}
});
if (exists) {
alert('Эта комплектация уже добавлена.');
return;
}
var bundlingName = selectedBundling.text();
var bundlingPrice = selectedBundling.data('price');
var newRow = `
<tr data-bundling-id="${bundlingId}">
<td>
<input type="hidden" name="bundlingIds" value="${bundlingId}" />
${bundlingId}
</td>
<th> </th>
<td class="bundling-price" data-price="${bundlingPrice}">${bundlingPrice}</td>
<th> </th>
<td><button type="button" class="deleteBundling" data-bundling-id="${bundlingId}">Удалить</button></td>
</tr>
`;
$('#bundlingsTable tbody').append(newRow);
$('.deleteBundling').off('click').on('click', function () {
var row = $(this).closest('tr');
row.remove();
updateSum();
});
$('#bundlingSelect').val('');
updateSum();
} else {
alert('Выберите комплектацию для добавления');
}
});
$('#carForm').submit(function (event) {
var CarBrand = $('#CarBrand').val();
var FeatureID = $('#FeatureID').val();
var CarClass = $('#CarClass').val();
var Model = $('#Model').val();
var VINnumber = $('#VINnumber').val();
var Year = $('#Year').val();
var isValid = true;
$('#CarBrandError').text('');
$('#CarClassError').text('');
$('#ModelError').text('');
$('#VINnumberError').text('');
$('#YearError').text('');
var totalBundlings = $('#bundlingsTable tbody tr').length;
if (totalBundlings == 0) {
alert('Пожалуйста, добавьте хотя бы одну комплектацию.');
isValid = false;
}
if (!isValid) {
event.preventDefault();
}
});
updateSum();
});
</script>

View File

@ -7,6 +7,7 @@
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexBundling">Комплектации</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexFeature">Особенности</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexCar">Автомобили</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
@* <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportsMenu">Меню отчетов</a> *@
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logout">Выйти</a>

View File

@ -0,0 +1,82 @@
@using CarCenterContracts.ViewModels;
@model List<CarViewModel>
@{
ViewData["Title"] = "Cars";
}
<div class="text-center">
<h1 class="display-4">Автомобили</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateCar" asp-route-id="0">Создать автомобиль</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Марка
</th>
<th>
Модель
</th>
<th>
Класс
</th>
<th>
ВИН-номер
</th>
<th>
Изменить автомобиль
</th>
<th>
Удалить автомобиль
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.CarBrand)
</td>
<td>
@Html.DisplayFor(modelItem => item.Model)
</td>
<td>
@Html.DisplayFor(modelItem => item.CarClass)
</td>
<td>
@Html.DisplayFor(modelItem => item.VINnumber)
</td>
<td>
<a asp-action="CreateCar" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<form method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>
</td>
</tr>
}
</tbody>
</table>
}
</div>