убрал лишние методы
This commit is contained in:
parent
c3c3770a20
commit
722ccfc36e
@ -100,30 +100,52 @@ namespace AdministratorApp.Controllers
|
||||
}
|
||||
return View(new CarSalesViewModel());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult CreateCarSales(int id, string brand, string model, double cost)
|
||||
public IActionResult CreateCarSales(CarSalesBindingModel model)
|
||||
{
|
||||
CarSalesBindingModel models = new CarSalesBindingModel();
|
||||
models.Id = id;
|
||||
models.CarBrand = brand;
|
||||
models.CarModel = model;
|
||||
models.CarCost = cost;
|
||||
if (models.Id == 0)
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
models.DateCreate = DateTime.Now;
|
||||
models.AdministratorId = UserAdministrator.admin!.Id;
|
||||
if (_data.CreateCarSale(models))
|
||||
return RedirectToAction("IndexCarSales");
|
||||
if (model.Id == 0)
|
||||
{
|
||||
model.DateCreate = DateTime.Now;
|
||||
model.AdministratorId = UserAdministrator.admin!.Id;
|
||||
if (_data.CreateCarSale(model))
|
||||
return RedirectToAction("IndexCarSales");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_data.UpdateCarSale(model))
|
||||
return RedirectToAction("IndexCarSales");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_data.UpdateCarSale(models))
|
||||
return RedirectToAction("IndexCarSales");
|
||||
}
|
||||
return View();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
//[HttpPost]
|
||||
//public IActionResult CreateCarSales(int id, string brand, string model, double cost)
|
||||
//{
|
||||
// CarSalesBindingModel models = new CarSalesBindingModel();
|
||||
// models.Id = id;
|
||||
// models.CarBrand = brand;
|
||||
// models.CarModel = model;
|
||||
// models.CarCost = cost;
|
||||
// if (models.Id == 0)
|
||||
// {
|
||||
// models.DateCreate = DateTime.Now;
|
||||
// models.AdministratorId = UserAdministrator.admin!.Id;
|
||||
// if (_data.CreateCarSale(models))
|
||||
// return RedirectToAction("IndexCarSales");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (_data.UpdateCarSale(models))
|
||||
// return RedirectToAction("IndexCarSales");
|
||||
// }
|
||||
// return View();
|
||||
//}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult IndexInspection()
|
||||
{
|
||||
@ -206,7 +228,10 @@ namespace AdministratorApp.Controllers
|
||||
{
|
||||
var value = _data.GetCompletions(id);
|
||||
if (value != null)
|
||||
{
|
||||
ViewBag.Cars = value.СompletionCars;
|
||||
return View(value);
|
||||
}
|
||||
}
|
||||
return View(new CompletionsViewModel());
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
@using CarCenterContracts.ViewModels;
|
||||
@{
|
||||
ViewData["Title"] = "CreateCar";
|
||||
ViewData["Title"] = "CreateCarSales";
|
||||
}
|
||||
@model CarSalesViewModel;
|
||||
<div class="text-center">
|
||||
@ -11,21 +11,21 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Бренд машины:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="brand" id="brand" value="@Model.CarBrand" />
|
||||
<span id="nameError" class="text-danger"></span>
|
||||
<input type="text" name="carbrand" id="carbrand" value="@Model.CarBrand" />
|
||||
<span id="brandError" 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.CarModel" />
|
||||
<span id="nameError" class="text-danger"></span>
|
||||
<input type="text" name="carmodel" id="carmodel" value="@Model.CarModel" />
|
||||
<span id="modelError" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Стоимость:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="cost" id="cost" value="@Model.CarCost" />
|
||||
<input type="text" name="carcost" id="carcost" value="@Model.CarCost" />
|
||||
<span id="costError" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
@ -39,9 +39,9 @@
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#CarForm').submit(function (event) {
|
||||
var brand = $('#brand').val();
|
||||
var model = $('#model').val();
|
||||
var cost = $('#cost').val();
|
||||
var brand = $('#carbrand').val();
|
||||
var model = $('#carmodel').val();
|
||||
var cost = $('#carcost').val();
|
||||
var isValid = true;
|
||||
|
||||
$('#brandError').text('');
|
||||
|
@ -3,13 +3,13 @@
|
||||
@model CompletionsViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "CreateProduction";
|
||||
ViewData["Title"] = "CreateCompletions";
|
||||
ViewBag.Cars = Model.СompletionCars;
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание комплектации</h2>
|
||||
</div>
|
||||
<form id="productionForm" method="post">
|
||||
<form id="CompletionsForm" method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название комплектации:</div>
|
||||
<div class="col-8">
|
||||
@ -29,23 +29,19 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Бренд</th>
|
||||
<th>Модель</th>
|
||||
<th>Стоимость</th>
|
||||
<th>Удалить</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var car in ViewBag.cars)
|
||||
@foreach (var car in ViewBag.Cars)
|
||||
{
|
||||
<tr data-car-id="@car.Value.Id">
|
||||
<td>
|
||||
<input type="hidden" name="carIds" value="@car.Value.Id" />
|
||||
@car.Value.CarBrand
|
||||
</td>
|
||||
<td>
|
||||
<input type="hidden" name="carIds" value="@car.Value.Id" />
|
||||
@car.Value.CarModel
|
||||
</td>
|
||||
|
||||
<td class="car-cost" data-cost="@car.Value.CarCost">@car.Value.CarCost</td>
|
||||
<td><button type="button" class="deletecar" data-car-id="@car.Value.Id">Удалить</button></td>
|
||||
</tr>
|
||||
@ -76,6 +72,88 @@
|
||||
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#carsTable').DataTable();
|
||||
function updateSum() {
|
||||
var sum = 0;
|
||||
$('#carsTable tbody tr').each(function () {
|
||||
var cost = $(this).find('.car-cost').data('cost');
|
||||
sum += parseFloat(cost);
|
||||
});
|
||||
$('#sum').val(sum.toFixed(2));
|
||||
}
|
||||
|
||||
$(document).on('click', '.deletecar', function () {
|
||||
var row = $(this).closest('tr');
|
||||
row.remove();
|
||||
updateSum();
|
||||
});
|
||||
|
||||
$('#addcar').click(function () {
|
||||
var selectedcar = $('#carSelect option:selected');
|
||||
if (selectedcar.val()) {
|
||||
var carId = selectedcar.val();
|
||||
var exists = false;
|
||||
$('#carsTable tbody tr').each(function () {
|
||||
if ($(this).data('car-id') == carId) {
|
||||
exists = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (exists) {
|
||||
alert('Эта машина уже добавлена.');
|
||||
return;
|
||||
}
|
||||
|
||||
var carName = selectedcar.text();
|
||||
var carCost = selectedcar.data('cost');
|
||||
|
||||
var newRow = `
|
||||
<tr data-car-id="${carId}">
|
||||
<td>
|
||||
<input type="hidden" name="carIds" value="${carId}" />
|
||||
${carName}
|
||||
</td>
|
||||
|
||||
<td class="car-cost" data-cost="${carCost}">${carCost}</td>
|
||||
<td><button type="button" class="deletecar" data-car-id="${carId}">Удалить</button></td>
|
||||
</tr>
|
||||
`;
|
||||
$('#carsTable tbody').append(newRow);
|
||||
|
||||
$('.deletecar').off('click').on('click', function () {
|
||||
var row = $(this).closest('tr');
|
||||
row.remove();
|
||||
updateSum();
|
||||
});
|
||||
|
||||
$('#carSelect').val('');
|
||||
|
||||
updateSum();
|
||||
} else {
|
||||
alert('Выберите машину для добавления');
|
||||
}
|
||||
});
|
||||
|
||||
$('#CompletionsForm').submit(function (event) {
|
||||
var title = $('#title').val();
|
||||
var isValid = true;
|
||||
|
||||
$('#titleError').text('');
|
||||
if (title.length < 2 || title.length > 50) {
|
||||
$('#titleError').text('Название должно быть от 2 до 50 символов.');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
var totalcars = $('#carsTable tbody tr').length;
|
||||
if (totalcars == 0) {
|
||||
alert('Пожалуйста, добавьте хотя бы одну деталь.');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
updateSum();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
@ -64,7 +64,10 @@
|
||||
<a asp-action="CreateCompletions" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
||||
<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>
|
||||
}
|
||||
|
@ -64,7 +64,10 @@
|
||||
<a asp-action="CreateInspection" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
||||
<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>
|
||||
}
|
||||
|
@ -103,39 +103,6 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddCarToCompletions(CopletionsSearchModel model, ICarSalesModel car)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddCarToCompletions. CompletionName:{CompletionName}.Id:{ Id}", model.СompletionName, model.Id);
|
||||
var element = _CompletionsStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddCarToCompletions element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddCarToCompletions find. Id:{Id}", element.Id);
|
||||
|
||||
element.СompletionCars[car.Id] = car;
|
||||
|
||||
_CompletionsStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
СompletionName = element.СompletionName,
|
||||
СompletionFeatures = element.СompletionFeatures,
|
||||
СompletionPrice = element.СompletionPrice,
|
||||
AdministratorId = element.AdministratorId,
|
||||
СompletionCars = element.СompletionCars,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CompletionsBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -91,40 +91,6 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool AddSaleToEmployee(EmployeeSearchModel model, ISaleModel Sale)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSaleToEmployee. EmployeeFIO:{EmployeeFIO}.Id:{ Id}", model.EmployeeFIO, model.Id);
|
||||
var element = _employeeStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddSaleToEmployee element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSaleToEmployee find. Id:{Id}", element.Id);
|
||||
|
||||
element.EmployeeSales[Sale.Id] = Sale;
|
||||
|
||||
_employeeStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
EmployeeFIO = element.EmployeeFIO,
|
||||
EmployeePost = element.EmployeePost,
|
||||
EmployeeSalary = element.EmployeeSalary,
|
||||
ManagerId = element.ManagerId,
|
||||
EmployeeSales = element.EmployeeSales,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool Update(EmployeeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -109,40 +109,6 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddCarToInspection(InspectionSearchModel model, ICarSalesModel car)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddCarToInspection. InspectionName:{InspectionName}.Id:{ Id}", model.InspectionName, model.Id);
|
||||
var element = _inspectionStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddCarToInspection element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddCarToInspection find. Id:{Id}", element.Id);
|
||||
|
||||
element.InspectionCars[car.Id] = car;
|
||||
|
||||
_inspectionStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
InspectionName = element.InspectionName,
|
||||
InspectionCost = element.InspectionCost,
|
||||
InspectionDate = element.InspectionDate,
|
||||
AdministratorId = element.AdministratorId,
|
||||
EmployeeId = element.EmployeeId,
|
||||
InspectionCars = element.InspectionCars
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(InspectionBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -21,40 +21,6 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
_managerLogic = ManagerLogic;
|
||||
}
|
||||
|
||||
public bool AddSaleToPreSaleWork(PreSaleWorkSearchModel model, ISaleModel Sale)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSaleToPreSaleWork. PreSaleWorkType:{PreSaleWorkType}.Id:{ Id}", model.PreSaleWorkType, model.Id);
|
||||
var element = _PreSaleWorkStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddSaleToPreSaleWork element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddSaleToPreSaleWork find. Id:{Id}", element.Id);
|
||||
|
||||
element.PreSaleWorkSales[Sale.Id] = Sale;
|
||||
|
||||
_PreSaleWorkStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
PreSaleWorkType = element.PreSaleWorkType,
|
||||
PreSaleWorkPrice = element.PreSaleWorkPrice,
|
||||
PreSaleWorkDate = element.PreSaleWorkDate,
|
||||
ManagerId = element.ManagerId,
|
||||
CompletionsId = element.CompletionsId,
|
||||
PreSaleWorkSales = element.PreSaleWorkSales
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(PreSaleWorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -17,6 +17,5 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
bool Create(CompletionsBindingModel model);
|
||||
bool Update(CompletionsBindingModel model);
|
||||
bool Delete(CompletionsBindingModel model);
|
||||
bool AddCarToCompletions(CopletionsSearchModel model, ICarSalesModel car);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model);
|
||||
EmployeeViewModel? ReadElement(EmployeeSearchModel model);
|
||||
bool AddSaleToEmployee(EmployeeSearchModel model, ISaleModel Sale);
|
||||
bool Create(EmployeeBindingModel model);
|
||||
bool Update(EmployeeBindingModel model);
|
||||
bool Delete(EmployeeBindingModel model);
|
||||
|
@ -17,6 +17,5 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
bool Create(InspectionBindingModel model);
|
||||
bool Update(InspectionBindingModel model);
|
||||
bool Delete(InspectionBindingModel model);
|
||||
bool AddCarToInspection(InspectionSearchModel model, ICarSalesModel car);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<PreSaleWorkViewModel>? ReadList(PreSaleWorkSearchModel? model);
|
||||
PreSaleWorkViewModel? ReadElement(PreSaleWorkSearchModel model);
|
||||
bool AddSaleToPreSaleWork(PreSaleWorkSearchModel model, ISaleModel Sale);
|
||||
bool Create(PreSaleWorkBindingModel model);
|
||||
bool Update(PreSaleWorkBindingModel model);
|
||||
bool Delete(PreSaleWorkBindingModel model);
|
||||
|
Loading…
Reference in New Issue
Block a user