микрофикс и еще чет не помню
This commit is contained in:
parent
ca728baeca
commit
d3f9279552
@ -11,6 +11,7 @@ namespace CarCenterContracts.BindingModels
|
||||
public class PresaleBindingModel : IPresaleModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
public PresaleStatus PresaleStatus { get; set; } = PresaleStatus.Неизвестно;
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
@ -11,6 +11,7 @@ namespace CarCenterContracts.BindingModels
|
||||
public class RequestBindingModel : IRequestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
public int PresaleId { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public RequestTypes RequestType { get; set; } = RequestTypes.Неизвестно;
|
||||
|
@ -9,5 +9,7 @@ namespace CarCenterContracts.SearchModels
|
||||
public class PresaleSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? WorkerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ namespace CarCenterContracts.SearchModels
|
||||
public class RequestSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? WorkerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ namespace CarCenterContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int PresaleId { get; set; }
|
||||
[DisplayName("Описание работы")]
|
||||
public string PresaleDescription { get; set; } = string.Empty;
|
||||
[DisplayName("Описание пожелания")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
[DisplayName("Тип пожелания")]
|
||||
|
@ -15,6 +15,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
public class Presale : IPresaleModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
[Required]
|
||||
public PresaleStatus PresaleStatus { get; set; } = PresaleStatus.Неизвестно;
|
||||
[Required]
|
||||
@ -55,6 +56,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
Description = model.Description,
|
||||
Price = model.Price,
|
||||
DueTill = model.DueTill,
|
||||
WorkerId = model.WorkerId,
|
||||
Bundlings = model.PresaleBundlings.Select(x => new PresaleBundling
|
||||
{
|
||||
Bundling = context.Bundlings.First(y => y.Id == x.Key)
|
||||
|
@ -14,6 +14,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
public class Request : IRequestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
public int PresaleId { get; set; }
|
||||
[Required]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
@ -33,6 +34,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
PresaleId = model.PresaleId,
|
||||
Description = model.Description,
|
||||
RequestType = model.RequestType,
|
||||
WorkerId = model.WorkerId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -53,7 +55,6 @@ namespace CarCenterDatabaseImplement.Models
|
||||
Description = Description,
|
||||
RequestType = RequestType,
|
||||
PresaleId = PresaleId,
|
||||
PresaleDescription = Presale?.Description ?? string.Empty,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,98 +1,137 @@
|
||||
using CarCenterWorkerApp.Models;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using CarCenterWorkerApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using WorkerApp;
|
||||
|
||||
namespace CarCenterWorkerApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly WorkerData _data;
|
||||
public HomeController(ILogger<HomeController> logger, WorkerData data)
|
||||
{
|
||||
_logger = logger;
|
||||
_data = data;
|
||||
}
|
||||
private bool IsLoggedIn { get { return UserWorker.user != null; } }
|
||||
private int UserId { get { return UserWorker.user!.Id; } }
|
||||
public IActionResult IndexNonReg()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
return View();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
return RedirectToAction("IndexNonReg");
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
return View();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
var user = _data.Login(login, password);
|
||||
if (user != null)
|
||||
{
|
||||
UserWorker.user = user;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult Logout()
|
||||
{
|
||||
UserWorker.user = null;
|
||||
return RedirectToAction("IndexNonReg");
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(string name, string surname, string patronymic, string email, long phone, string password1, string password2)
|
||||
{
|
||||
if (password1 == password2 && _data.Register(new()
|
||||
{
|
||||
Email = email,
|
||||
Name = name,
|
||||
Password = password1,
|
||||
Surname = surname,
|
||||
Patronymic = patronymic,
|
||||
PhoneNumber = phone
|
||||
}))
|
||||
{
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult IndexRequest()
|
||||
{
|
||||
if (UserWorker.user != null)
|
||||
{
|
||||
var list = _data.GetRequests(UserWorker.user.Id);
|
||||
if (list != null)
|
||||
return View(list);
|
||||
return View(new List<RequestViewModel>());
|
||||
}
|
||||
return RedirectToAction("IndexNonReg");
|
||||
}
|
||||
[HttpPost]
|
||||
public void IndexRequest(int id)
|
||||
{
|
||||
if (UserWorker.user != null)
|
||||
{
|
||||
_data.DeleteRequest(id);
|
||||
}
|
||||
Response.Redirect("IndexRequest");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateRequest(int id)
|
||||
{
|
||||
var presales = _data.GetPresales(UserWorker.user!.Id);
|
||||
ViewBag.Presales = presales;
|
||||
if (id != 0)
|
||||
{
|
||||
var value = _data.GetRequest(id);
|
||||
if (value != null)
|
||||
return View(value);
|
||||
}
|
||||
return View(new RequestViewModel());
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult CreateRequest(RequestBindingModel model, int[] presalesIds)
|
||||
{
|
||||
var presales = _data.GetPresales(UserWorker.user!.Id);
|
||||
for (int i = 0; i < presalesIds.Length; i++)
|
||||
{
|
||||
var presale = presales!.FirstOrDefault(x => x.Id == presalesIds[i])!;
|
||||
model.RequestPresales[presalesIds[i]] = presale;
|
||||
sum += presale.Price;
|
||||
}
|
||||
if (model.Id == 0)
|
||||
{
|
||||
model.WorkerId = UserWorker.user!.Id;
|
||||
if (_data.CreateRequest(model))
|
||||
return RedirectToAction("IndexRequest");
|
||||
}
|
||||
else
|
||||
{
|
||||
model.WorkerId = UserWorker.user!.Id;
|
||||
if (_data.UpdateRequest(model))
|
||||
return RedirectToAction("IndexRequest");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Presales()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult PresaleCreate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult PresaleDelete()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult PresaleUpdate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Requests()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult RequestCreate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult RequestDelete()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult RequestUpdate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Orders()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult OrderCreate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult OrderDelete()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult OrderUpdate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ using CarCenterBusinessLogic.BusinessLogics;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterDatabaseImplement.Implements;
|
||||
|
||||
using WorkerApp;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
@ -27,6 +27,7 @@ builder.Services.AddTransient<IPresaleLogic, PresaleLogic>();
|
||||
builder.Services.AddTransient<IRequestLogic, RequestLogic>();
|
||||
builder.Services.AddTransient<IStorekeeperLogic, StorekeeperLogic>();
|
||||
builder.Services.AddTransient<IWorkerLogic, WorkerLogic>();
|
||||
builder.Services.AddTransient<WorkerData>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
@{
|
||||
ViewData["Title"] = "AddOrderCars";
|
||||
}
|
||||
<div class="text-center mb-5">
|
||||
<h2 class="display-4">Добавить машину в заказ</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">Заказ</div>
|
||||
<div class="col-8 ">
|
||||
<select id="orderId" name="orderId" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders,"Id"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">Машина</div>
|
||||
<div class="col-8">
|
||||
<select id="carId" name="carId" class="form-control" asp-items="@(new SelectList(@ViewBag.Cars,"Id"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2"><input type="submit" value="Добавить" class="btn btn-primary" /></div>
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2"><input type="button" value="Отменить" class="btn btn-secondary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -38,7 +38,41 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div>Комплектации</div>
|
||||
<div>Полжелания</div>
|
||||
<div class="table-responsive-lg">
|
||||
<table id="requestsTable" class="display">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID пожелания</th>
|
||||
<th> </th>
|
||||
<th>Удалить</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var request in ViewBag.Requests)
|
||||
{
|
||||
<tr data-request-id="@request.Value.Id">
|
||||
<td>
|
||||
<input type="hidden" name="requestIds" value="@request.Value.Id" />@request.Value.Id
|
||||
</td>
|
||||
<th> </th>
|
||||
<td><button type="button" class="deleteRequest" data-request-id="@request.Value.Id">Удалить</button></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<select id="requestSelect" class="form-control">
|
||||
<option value="">Выберите пожелания</option>
|
||||
@foreach (var request in ViewBag.AllRequests)
|
||||
{
|
||||
<option value="@request.Id" data-price="@request.Price">Пожелание @request.Id</option>
|
||||
}
|
||||
</select>
|
||||
<button type="button" id="addRequest" class="btn btn-secondary">Добавить пожелание</button>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div>Комлектации</div>
|
||||
<div class="table-responsive-lg">
|
||||
<table id="bundlingsTable" class="display">
|
||||
<thead>
|
||||
@ -115,6 +149,12 @@
|
||||
updateSum();
|
||||
});
|
||||
|
||||
$(document).on('click', '.deleteRequest', function () {
|
||||
var row = $(this).closest('tr');
|
||||
row.remove();
|
||||
updateSum();
|
||||
});
|
||||
|
||||
$('#addBundling').click(function () {
|
||||
var selectedBundling = $('#bundlingSelect option:selected');
|
||||
if (selectedBundling.val()) {
|
||||
@ -162,6 +202,51 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('#addPresale').click(function () {
|
||||
var selectedPresale = $('#presaleSelect option:selected');
|
||||
if (selectedPresale.val()) {
|
||||
var presaleId = selectedPresale.val();
|
||||
var exists = false;
|
||||
$('#presalesTable tbody tr').each(function () {
|
||||
if ($(this).data('presale-id') == presaleId) {
|
||||
exists = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (exists) {
|
||||
alert('Это пожелание уже добавлено.');
|
||||
return;
|
||||
}
|
||||
|
||||
var presaleName = selectedPresale.text();
|
||||
var presalePrice = selectedPresale.data('price');
|
||||
|
||||
var newRow = `
|
||||
<tr data-presale-id="${presaleId}">
|
||||
<td>
|
||||
<input type="hidden" name="presaleIds" value="${presaleId}" />
|
||||
${presaleId}
|
||||
</td>
|
||||
<th> </th>
|
||||
<td><button type="button" class="deletePresale" data-presale-id="${presaleId}">Удалить</button></td>
|
||||
</tr>
|
||||
`;
|
||||
$('#presalesTable tbody').append(newRow);
|
||||
|
||||
$('.deletePresale').off('click').on('click', function () {
|
||||
var row = $(this).closest('tr');
|
||||
row.remove();
|
||||
updateSum();
|
||||
});
|
||||
|
||||
$('#presaleSelect').val('');
|
||||
|
||||
updateSum();
|
||||
} else {
|
||||
alert('Выберите комплектацию для добавления');
|
||||
}
|
||||
});
|
||||
|
||||
$('#presaleForm').submit(function (event) {
|
||||
var PresaleStatus = $('#PresaleStatus').val();
|
||||
var Description = $('#Description').val();
|
||||
@ -179,6 +264,12 @@
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
var totalPresales = $('#presalesTable tbody tr').length;
|
||||
if (totalPresales == 0) {
|
||||
alert('Пожалуйста, добавьте хотя бы одно пожелание.');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
@ -30,18 +30,6 @@
|
||||
<span id="TypeError" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Предпродажная работа:</div>
|
||||
<div class="col-8">
|
||||
<select name="Presale" id="Presale">
|
||||
@foreach (var presale in ViewBag.Presales)
|
||||
{
|
||||
<option value="@presale.Description">Предпродажная работа @presale.Description</option>
|
||||
}
|
||||
</select>
|
||||
<span id="PresaleError" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
@ -54,11 +42,9 @@
|
||||
$('#requestForm').submit(function (event) {
|
||||
var Type = $('#Type').val();
|
||||
var Description = $('#Description').val();
|
||||
var Presale = $('#Presale').val();
|
||||
var isValid = true;
|
||||
$('#TypeError').text('');
|
||||
$('#DescriptionError').text('');
|
||||
$('#PresaleError').text('');
|
||||
|
||||
|
||||
if (!isValid) {
|
||||
|
@ -29,9 +29,6 @@
|
||||
<th>
|
||||
Описание
|
||||
</th>
|
||||
<th>
|
||||
Описание работы
|
||||
</th>
|
||||
<th>
|
||||
Тип пожелания
|
||||
</th>
|
||||
@ -53,9 +50,6 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Description)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.PresaleDescription)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.RequestType)
|
||||
</td>
|
||||
|
105
CarCenter/CarCenterWorkerApp/WorkerData.cs
Normal file
105
CarCenter/CarCenterWorkerApp/WorkerData.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
|
||||
namespace WorkerApp
|
||||
{
|
||||
public class WorkerData
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWorkerLogic _storekeeperLogic;
|
||||
private readonly IPresaleLogic _presaleLogic;
|
||||
private readonly IRequestLogic _requestLogic;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
public WorkerData(ILogger<WorkerData> logger, IWorkerLogic storekeeperLogic, IPresaleLogic presaleLogic, IRequestLogic requestLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_storekeeperLogic = storekeeperLogic;
|
||||
_presaleLogic = presaleLogic;
|
||||
_requestLogic = requestLogic;
|
||||
_orderLogic = orderLogic;
|
||||
}
|
||||
|
||||
public WorkerViewModel? Login(string email, string password)
|
||||
{
|
||||
return _storekeeperLogic.ReadElement(new()
|
||||
{
|
||||
Email = email,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
public bool Register(WorkerBindingModel model)
|
||||
{
|
||||
return _storekeeperLogic.Create(model);
|
||||
}
|
||||
public bool UpdateUser(WorkerBindingModel model)
|
||||
{
|
||||
return _storekeeperLogic.Update(model);
|
||||
}
|
||||
|
||||
public List<PresaleViewModel>? GetPresales(int userId)
|
||||
{
|
||||
return _presaleLogic.ReadList(new PresaleSearchModel() { WorkerId = userId });
|
||||
}
|
||||
public bool DeletePresale(int presaleId)
|
||||
{
|
||||
return _presaleLogic.Delete(new() { Id = presaleId });
|
||||
}
|
||||
public bool CreatePresale(PresaleBindingModel model)
|
||||
{
|
||||
return _presaleLogic.Create(model);
|
||||
}
|
||||
public bool UpdatePresale(PresaleBindingModel model)
|
||||
{
|
||||
return _presaleLogic.Update(model);
|
||||
}
|
||||
public PresaleViewModel? GetPresale(int id)
|
||||
{
|
||||
return _presaleLogic.ReadElement(new() { Id = id });
|
||||
}
|
||||
public List<RequestViewModel>? GetRequests(int userId)
|
||||
{
|
||||
return _requestLogic.ReadList(new RequestSearchModel() { WorkerId = userId });
|
||||
}
|
||||
public bool DeleteRequest(int presaleId)
|
||||
{
|
||||
return _requestLogic.Delete(new() { Id = presaleId });
|
||||
}
|
||||
public bool CreateRequest(RequestBindingModel model)
|
||||
{
|
||||
return _requestLogic.Create(model);
|
||||
}
|
||||
public bool UpdateRequest(RequestBindingModel model)
|
||||
{
|
||||
return _requestLogic.Update(model);
|
||||
}
|
||||
public RequestViewModel? GetRequest(int id)
|
||||
{
|
||||
return _requestLogic.ReadElement(new() { Id = id });
|
||||
}
|
||||
public List<OrderViewModel>? GetOrders(int userId)
|
||||
{
|
||||
return _orderLogic.ReadList(new() { WorkerId = userId });
|
||||
}
|
||||
public OrderViewModel? GetOrder(int id)
|
||||
{
|
||||
return _orderLogic.ReadElement(new() { Id = id });
|
||||
}
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
return _orderLogic.Create(model);
|
||||
}
|
||||
public bool UpdateOrder(OrderBindingModel model)
|
||||
{
|
||||
return _orderLogic.Update(model);
|
||||
}
|
||||
public bool DeleteOrder(int orderId)
|
||||
{
|
||||
return _orderLogic.Delete(new() { Id = orderId });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user