Merge branch 'Worker_Raspaev' into Storekeeper
This commit is contained in:
commit
6789b86723
@ -10,10 +10,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBuildStorage _buildStorage;
|
||||
public BuildLogic(ILogger<BuildLogic> logger, IBuildStorage buildStorage)
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public BuildLogic(ILogger<BuildLogic> logger, IBuildStorage buildStorage, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_buildStorage = buildStorage;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
|
||||
public List<BuildViewModel>? ReadList(BuildSearchModel? model)
|
||||
@ -106,7 +108,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у сборки", nameof(model.Id));
|
||||
}
|
||||
_logger.LogInformation("Build. BuildName:{BuildName}. Price:{Price}. Id:{Id}", model.BuildName, model.Price, model.Id);
|
||||
_logger.LogInformation("Build. UserId:{UserId}. BuildName:{BuildName}. Price:{Price}. Id:{Id}", model.UserId, model.BuildName, model.Price, model.Id);
|
||||
var element = _buildStorage.GetElement(new BuildSearchModel
|
||||
{
|
||||
BuildName = model.BuildName
|
||||
|
@ -100,8 +100,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у комментария", nameof(model.Id));
|
||||
}
|
||||
if (model.UserId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.UserId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Comment. BuildId:{BuildId}. Id:{Id}", model.BuildId, model.Id);
|
||||
_logger.LogInformation("Comment. UserId:{UserId}. BuildId:{BuildId}. Id:{Id}", model.UserId, model.BuildId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -121,7 +121,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Purchase. PurchaseID:{Id}. Sum:{ Sum}", model.Id, model.Sum);
|
||||
_logger.LogInformation("Purchase. UserId:{UserId}. PurchaseID:{Id}. Sum:{ Sum}", model.UserId, model.Id, model.Sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ namespace HardwareShopClientApp.Controllers
|
||||
}
|
||||
if ((int)APIClient.User.Role == 1)
|
||||
{
|
||||
return RedirectToAction("MainWorker", "Worker");
|
||||
return RedirectToAction("WorkerReport", "Worker");
|
||||
}
|
||||
else
|
||||
|
@ -17,11 +17,6 @@ namespace HardwareShopClientApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Builds()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Comments()
|
||||
{
|
||||
return View();
|
||||
@ -40,18 +35,12 @@ namespace HardwareShopClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Purchases()
|
||||
{
|
||||
//return View();
|
||||
//string login = (string)TempData["UserId"];
|
||||
|
||||
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/client/getpurchases?UserId={APIClient.User.Id}"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Purchases(int id)
|
||||
{
|
||||
//return View();
|
||||
//string login = (string)TempData["UserId"];
|
||||
|
||||
Response.Redirect("Purchase");
|
||||
}
|
||||
|
||||
@ -59,9 +48,6 @@ namespace HardwareShopClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Purchase()
|
||||
{
|
||||
//return View();
|
||||
//string login = (string)TempData["UserId"];
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -69,5 +55,30 @@ namespace HardwareShopClientApp.Controllers
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Builds()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Builds(int id)
|
||||
{
|
||||
Response.Redirect("Build");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Build()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult linkingBuild()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
78
HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml
Normal file
78
HardwareShop/HardwareShopClientApp/Views/Worker/Build.cshtml
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
|
||||
@using HardwareShopContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "Build";
|
||||
}
|
||||
|
||||
@model List<ComponentViewModel>
|
||||
|
||||
@section Header {
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Purchases">Purchases</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Builds">Builds</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Comments">Comments</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="listComponents">listComponents</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<form class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Комплектующие</h2>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Название сборки</label>
|
||||
<input type="text" class="form-control" name="buildName">
|
||||
</div>
|
||||
|
||||
<div class="text-center" name="id">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Комплектующее
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
<th>
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Save</button>
|
||||
</form>
|
||||
|
@ -1,7 +1,10 @@
|
||||
@{
|
||||
@using HardwareShopContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "Builds";
|
||||
}
|
||||
|
||||
@model List<BuildViewModel>
|
||||
|
||||
@section Header {
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
@ -27,36 +30,52 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Регистрация</h2>
|
||||
</div>
|
||||
<form method="post" class="d-flex flex-column align-items-center">
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Логин</label>
|
||||
<input type="text" class="form-control" aria-describedby="emailHelp" name="login">
|
||||
<form method="post" class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Сборки</h2>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Почта</label>
|
||||
<input type="text" class="form-control" name="email">
|
||||
<div class="text-center" name="id">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Дата оплаты
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Пароль</label>
|
||||
<input type="password" class="form-control" name="password">
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Роль</label>
|
||||
<select class="form-select" name="role">
|
||||
<option value="1">Работник</option>
|
||||
<option value="2">Кладовщик</option>
|
||||
</select>
|
||||
<div class="text-center d-flex flex-column mt-5">
|
||||
<button type="submit" class="btn btn-primary btn-lg mb-5">Добавить</button>
|
||||
<button type="submit" class="btn btn-primary btn-lg mb-5">Изменить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Привязать сборку</button>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Submit</button>
|
||||
|
||||
</form>
|
||||
</form>
|
||||
|
@ -1,7 +1,10 @@
|
||||
@{
|
||||
@using HardwareShopContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "Comments";
|
||||
}
|
||||
|
||||
@model List<CommentViewModel>
|
||||
|
||||
@section Header {
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
@ -27,36 +30,76 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Регистрация</h2>
|
||||
</div>
|
||||
<form method="post" class="d-flex flex-column align-items-center">
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Логин</label>
|
||||
<input type="text" class="form-control" aria-describedby="emailHelp" name="login">
|
||||
<form method="post" class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Сборки</h2>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Почта</label>
|
||||
<input type="text" class="form-control" name="email">
|
||||
<div class="text-center" name="id">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
<th>
|
||||
Название сборки
|
||||
</th>
|
||||
<th>
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Пароль</label>
|
||||
<input type="password" class="form-control" name="password">
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Роль</label>
|
||||
<div class="text-center d-flex flex-column mt-5">
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||
</div>
|
||||
|
||||
<!-- Модальное окно -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Комментарий</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<label class="form-label">Сборка</label>
|
||||
<select class="form-select" name="role">
|
||||
<option value="1">Работник</option>
|
||||
<option value="2">Кладовщик</option>
|
||||
<option value="1">Сборка 1</option>
|
||||
<option value="2">Сборка 2</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Submit</button>
|
||||
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<label class="form-label">Текст</label>
|
||||
<input type="text" class="form-control" name="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -27,6 +27,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -30,6 +30,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -55,7 +58,7 @@
|
||||
Цена
|
||||
</th>
|
||||
<th>
|
||||
Пользователь
|
||||
Логин пользователя
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
@ -79,25 +82,25 @@
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Заголовок модального окна</h5>
|
||||
<h5 class="modal-title" id="exampleModalLabel">Товар</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<label class="form-label">Товар</label>
|
||||
<select class="form-select" name="role">
|
||||
<option value="1">Товар 1</option>
|
||||
<option value="2">Товар 2</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<label class="form-label">Количество</label>
|
||||
<input type="number" class="form-control" name="count">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary">Сохранить изменения</button>
|
||||
<button type="button" class="btn btn-primary">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -29,6 +29,9 @@
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -37,7 +40,7 @@
|
||||
</header>
|
||||
}
|
||||
<form method="post" class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Покупки</h2>
|
||||
</div>
|
||||
@ -64,7 +67,7 @@
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Пользователь
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -28,6 +28,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -35,4 +38,14 @@
|
||||
</header>
|
||||
}
|
||||
|
||||
<form method="post" class="d-flex flex-column align-items-center">
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">С</label>
|
||||
<input type="date" class="form-control" name="dateFrom">
|
||||
<label class="form-label">По</label>
|
||||
<input type="date" class="form-control" name="dateTo">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Вывод на страницу</button>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Отправить на почту</button>
|
||||
|
||||
</form>
|
@ -0,0 +1,116 @@
|
||||
|
||||
|
||||
@using HardwareShopContracts.ViewModels
|
||||
@{
|
||||
ViewData["Title"] = "linkingBuild";
|
||||
}
|
||||
|
||||
@model List<GoodViewModel>
|
||||
|
||||
@section Header {
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Purchases">Purchases</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Builds">Builds</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="Comments">Comments</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="listComponents">listComponents</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<form class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Выбранные покупки</h2>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label">Сборка</label>
|
||||
<select class="form-select" name="role">
|
||||
<option value="1">Сборка 1</option>
|
||||
<option value="2">Сборка 2</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="text-center" name="id">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Комплектующее
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
<th>
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center d-flex flex-column mt-5">
|
||||
<button type="submit" class="btn btn-primary btn-lg mb-5">Save</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||
</div>
|
||||
|
||||
<!-- Модальное окно -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Покупка</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<label class="form-label">Покупка</label>
|
||||
<select class="form-select" name="purchase">
|
||||
<option value="1">Покупка 1</option>
|
||||
<option value="2">Покупка 2</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label">Количество</label>
|
||||
<input type="number" class="form-control" name="count">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -1,7 +1,11 @@
|
||||
@{
|
||||
@using HardwareShopContracts.ViewModels
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "listComponents";
|
||||
}
|
||||
|
||||
@model List<PurchaseViewModel>
|
||||
|
||||
@section Header {
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
@ -26,6 +30,9 @@
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -33,30 +40,67 @@
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Регистрация</h2>
|
||||
</div>
|
||||
<form method="post" class="d-flex flex-column align-items-center">
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Логин</label>
|
||||
<input type="text" class="form-control" aria-describedby="emailHelp" name="login">
|
||||
<form method="post" class="d-flex justify-content-evenly">
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Покупки</h2>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Почта</label>
|
||||
<input type="text" class="form-control" name="email">
|
||||
<div class="text-center" name="id">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Дата оплаты
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Логин пользователя
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Пароль</label>
|
||||
<input type="password" class="form-control" name="password">
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="form-label">Роль</label>
|
||||
<div class="text-center d-flex flex-column mt-5">
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Сохранить в doc формате</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Сохранить в xls формате</button>
|
||||
</div>
|
||||
|
||||
<!-- Модальное окно -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Комментарий</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
<label class="form-label">Покупка</label>
|
||||
<select class="form-select" name="role">
|
||||
<option value="1">Работник</option>
|
||||
<option value="2">Кладовщик</option>
|
||||
<option value="1">Покупка 1</option>
|
||||
<option value="2">Покупка 2</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3 px-4">Submit</button>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary">Добавить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -6,12 +6,12 @@ namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; }
|
||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
||||
public Dictionary<int, (IComponentModel, int)> GoodsComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -7,7 +7,7 @@ namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public decimal Sum { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
||||
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
|
||||
|
||||
@ -15,8 +15,6 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
|
||||
|
||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDataModels.Models;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
|
@ -7,16 +7,17 @@ namespace HardwareShopContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public decimal Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
[DisplayName("Название компонента")]
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Логин работника")]
|
||||
[DisplayName("Логин пользователя")]
|
||||
public string UserLogin { get; set; } = string.Empty;
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; }
|
||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace HardwareShopContracts.ViewModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
[DisplayName("Логин работника")]
|
||||
[DisplayName("Логин пользователя")]
|
||||
public string UserLogin { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace HardwareShopContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public decimal Sum { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус покупки")]
|
||||
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
|
||||
@ -18,11 +18,9 @@ namespace HardwareShopContracts.ViewModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
[DisplayName("Логин работника")]
|
||||
[DisplayName("Логин пользователя")]
|
||||
public string UserLogin { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
|
||||
|
||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ namespace HardwareShopDataModels.Models
|
||||
{
|
||||
public interface IBuildModel : IId
|
||||
{
|
||||
decimal Price { get; }
|
||||
double Price { get; }
|
||||
|
||||
string BuildName { get; }
|
||||
|
||||
int UserId { get; }
|
||||
|
||||
Dictionary<int, (IComponentModel, int)>? BuildComponents { get; }
|
||||
Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,17 +4,14 @@ namespace HardwareShopDataModels.Models
|
||||
{
|
||||
public interface IPurchaseModel : IId
|
||||
{
|
||||
decimal Sum { get; }
|
||||
double Sum { get; }
|
||||
|
||||
PurchaseStatus PurchaseStatus { get; }
|
||||
|
||||
//через "?" обозначается что поле может быть null
|
||||
DateTime? DatePurchase { get; }
|
||||
|
||||
int UserId { get; }
|
||||
|
||||
Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; }
|
||||
|
||||
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.User)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -24,17 +23,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
|
||||
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
|
||||
{
|
||||
if (!model.UserId.HasValue)
|
||||
if (string.IsNullOrEmpty(model.BuildName) && !model.UserId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (!string.IsNullOrEmpty(model.BuildName))
|
||||
{
|
||||
return context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.BuildName.Contains(model.BuildName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Builds
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.UserId == model.UserId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -48,9 +55,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) ||
|
||||
@ -61,7 +67,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
public BuildViewModel? Insert(BuildBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var newBuild = Build.Create(context, model);
|
||||
var newBuild = Build.Create(model);
|
||||
if (newBuild == null)
|
||||
{
|
||||
return null;
|
||||
@ -69,9 +75,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
context.Builds.Add(newBuild);
|
||||
context.SaveChanges();
|
||||
return context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.Id)
|
||||
.FirstOrDefault(x => x.Id == newBuild.Id)
|
||||
@ -85,9 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
try
|
||||
{
|
||||
var build = context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
@ -97,7 +101,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
}
|
||||
build.Update(model);
|
||||
context.SaveChanges();
|
||||
build.UpdateComponents(context, model);
|
||||
build.UpdatePurchases(context, model);
|
||||
transaction.Commit();
|
||||
return build?.GetViewModel;
|
||||
}
|
||||
@ -112,9 +116,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Builds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Include(x => x.Comments)
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.Id)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
@ -21,7 +21,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
|
||||
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.BuildId.HasValue && !model.UserId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
@ -35,7 +35,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.Include(x => x.User)
|
||||
|
@ -2,7 +2,9 @@
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using HardwareShopDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
@ -13,8 +15,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -23,21 +25,15 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (model.UserId.HasValue)
|
||||
if (!model.UserId.HasValue)
|
||||
{
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return new();
|
||||
}
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -50,8 +46,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -68,8 +64,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
context.Purchases.Add(newPurchase);
|
||||
context.SaveChanges();
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newPurchase.Id)
|
||||
?.GetViewModel;
|
||||
@ -82,8 +78,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
try
|
||||
{
|
||||
var purchase = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (purchase == null)
|
||||
@ -93,7 +89,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
purchase.Update(model);
|
||||
context.SaveChanges();
|
||||
purchase.UpdateGoods(context, model);
|
||||
purchase.UpdateBuilds(context, model);
|
||||
transaction.Commit();
|
||||
return purchase.GetViewModel;
|
||||
}
|
||||
@ -108,8 +103,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
|
@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
GoodName = model.GoodName,
|
||||
Price = model.Price,
|
||||
UserId = model.UserId,
|
||||
Components = model.GoodComponents.Select(x => new GoodComponent
|
||||
Components = model.GoodsComponents.Select(x => new GoodComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
Price = Price,
|
||||
UserId = UserId,
|
||||
UserLogin = User.Login,
|
||||
GoodComponents = GoodsComponents
|
||||
GoodsComponents = GoodsComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model)
|
||||
@ -91,18 +91,18 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
{ // удалили те, которых нет в модели
|
||||
context.GoodsComponents
|
||||
.RemoveRange(goodComponents
|
||||
.Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId)));
|
||||
.Where(rec => !model.GoodsComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in goodComponents)
|
||||
{
|
||||
updateComponent.Count = model.GoodComponents[updateComponent.ComponentId].Item2;
|
||||
model.GoodComponents.Remove(updateComponent.ComponentId);
|
||||
updateComponent.Count = model.GoodsComponents[updateComponent.ComponentId].Item2;
|
||||
model.GoodsComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var good = context.Goods.First(x => x.Id == Id);
|
||||
foreach (var gc in model.GoodComponents)
|
||||
foreach (var gc in model.GoodsComponents)
|
||||
{
|
||||
context.GoodsComponents.Add(new GoodComponent
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
@ -12,7 +13,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public decimal Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
[Required]
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
@ -23,44 +24,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
public virtual User User { get; set; }
|
||||
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<Comment>? Comments { get; set; }
|
||||
public virtual List<Comment> Comments { get; set; } = new();
|
||||
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<ComponentBuild>? Components { get; set; }
|
||||
|
||||
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<PurchaseBuild>? Purchases { get; set; }
|
||||
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
|
||||
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||
public Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_buildComponents == null)
|
||||
if (_buildPurchases == null)
|
||||
{
|
||||
_buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count));
|
||||
_buildPurchases = Purchases.ToDictionary(recBP => recBP.PurchaseId, recBP => (recBP.Purchase as IPurchaseModel, recBP.Count));
|
||||
}
|
||||
return _buildComponents;
|
||||
return _buildPurchases;
|
||||
}
|
||||
}
|
||||
|
||||
public static Build Create(HardwareShopDatabase context, BuildBindingModel model)
|
||||
public static Build Create(BuildBindingModel model)
|
||||
{
|
||||
return new Build()
|
||||
{
|
||||
Id = model.Id,
|
||||
Price = model.Price,
|
||||
BuildName = model.BuildName,
|
||||
UserId = model.UserId,
|
||||
Components = model.BuildComponents.Select(x => new ComponentBuild
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
@ -77,38 +71,52 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
Price = Price,
|
||||
UserLogin = User.Login,
|
||||
UserId = UserId,
|
||||
BuildComponents = BuildComponents
|
||||
BuildPurchases = BuildPurchases,
|
||||
};
|
||||
|
||||
public void UpdateComponents(HardwareShopDatabase context, BuildBindingModel model)
|
||||
public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model)
|
||||
{
|
||||
var buildComponents = context.ComponentsBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
||||
if (buildComponents != null && buildComponents.Count > 0)
|
||||
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
||||
if (buildPurchases != null && buildPurchases.Count > 0)
|
||||
{ // удалили те в бд, которых нет в модели
|
||||
context.ComponentsBuilds.RemoveRange(buildComponents.Where(rec => !model.BuildComponents.ContainsKey(rec.ComponentId)));
|
||||
context.PurchasesBuilds.RemoveRange(buildPurchases.Where(rec => !model.BuildPurchases.ContainsKey(rec.PurchaseId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in buildComponents)
|
||||
foreach (var updateComponent in buildPurchases)
|
||||
{
|
||||
updateComponent.Count = model.BuildComponents[updateComponent.ComponentId].Item2;
|
||||
model.BuildComponents.Remove(updateComponent.ComponentId);
|
||||
updateComponent.Count = model.BuildPurchases[updateComponent.PurchaseId].Item2;
|
||||
model.BuildPurchases.Remove(updateComponent.PurchaseId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var build = context.Builds.First(x => x.Id == Id);
|
||||
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
|
||||
foreach (var dc in model.BuildComponents)
|
||||
foreach (var bp in model.BuildPurchases)
|
||||
{
|
||||
context.ComponentsBuilds.Add(new ComponentBuild
|
||||
context.PurchasesBuilds.Add(new PurchaseBuild
|
||||
{
|
||||
Build = build,
|
||||
Component = context.Components.First(x => x.Id == dc.Key),
|
||||
Count = dc.Value.Item2
|
||||
Purchase = context.Purchases.First(x => x.Id == bp.Key),
|
||||
Count = bp.Value.Item2
|
||||
});
|
||||
var purchase = context.Purchases.First(x => x.Id == bp.Key);
|
||||
if (purchase != null)
|
||||
{
|
||||
purchase.Sum += bp.Value.Item2* build.Price;
|
||||
}
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
_buildComponents = null;
|
||||
_buildPurchases = null;
|
||||
}
|
||||
|
||||
|
||||
public void UpdateSumPurchase(HardwareShopDatabase context, BuildBindingModel model)
|
||||
{
|
||||
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public decimal Sum { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
||||
[Required]
|
||||
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
|
||||
@ -29,27 +29,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseBuild>? Builds { get; set; }
|
||||
|
||||
public Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseBuilds == null)
|
||||
{
|
||||
_purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildId, recPB => (recPB.Build as IBuildModel, recPB.Count));
|
||||
}
|
||||
return _purchaseBuilds;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IGoodModel, int)>? PurchaseGoods
|
||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -70,16 +56,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
PurchaseStatus = model.PurchaseStatus,
|
||||
DatePurchase = model.DatePurchase,
|
||||
UserId = model.UserId,
|
||||
Builds = model.PurchaseBuilds.Select(x => new PurchaseBuild
|
||||
{
|
||||
Build = context.Builds.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
Goods = model.PurchaseGoods.Select(x => new PurchaseGood
|
||||
{
|
||||
Good = context.Goods.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -87,6 +68,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
PurchaseStatus = model.PurchaseStatus;
|
||||
DatePurchase = model.DatePurchase;
|
||||
Sum = model.Sum;
|
||||
}
|
||||
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
@ -97,38 +79,9 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
DatePurchase = DatePurchase,
|
||||
UserId = UserId,
|
||||
UserLogin = User.Login,
|
||||
PurchaseBuilds = PurchaseBuilds,
|
||||
PurchaseGoods = PurchaseGoods
|
||||
};
|
||||
|
||||
public void UpdateBuilds(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseId == model.Id).ToList();
|
||||
if (purchaseBuilds != null && purchaseBuilds.Count > 0)
|
||||
{
|
||||
context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildId)));
|
||||
context.SaveChanges();
|
||||
foreach (var updateBuild in purchaseBuilds)
|
||||
{
|
||||
updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2;
|
||||
model.PurchaseBuilds.Remove(updateBuild.BuildId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var purchase = context.Purchases.First(x => x.Id == Id);
|
||||
foreach (var dc in model.PurchaseBuilds)
|
||||
{
|
||||
context.PurchasesBuilds.Add(new PurchaseBuild
|
||||
{
|
||||
Purchase = purchase,
|
||||
Build = context.Builds.First(x => x.Id == dc.Key),
|
||||
Count = dc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_purchaseBuilds = null;
|
||||
}
|
||||
|
||||
public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList();
|
||||
|
Loading…
Reference in New Issue
Block a user