Merge branch 'Worker_Raspaev' into Storekeeper

This commit is contained in:
dasha 2023-04-02 17:43:33 +04:00
commit 6789b86723
29 changed files with 639 additions and 346 deletions

View File

@ -10,10 +10,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IBuildStorage _buildStorage; 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; _logger = logger;
_buildStorage = buildStorage; _buildStorage = buildStorage;
_componentStorage = componentStorage;
} }
public List<BuildViewModel>? ReadList(BuildSearchModel? model) public List<BuildViewModel>? ReadList(BuildSearchModel? model)
@ -106,7 +108,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
throw new ArgumentNullException("Некорректный идентификатор у сборки", nameof(model.Id)); 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 var element = _buildStorage.GetElement(new BuildSearchModel
{ {
BuildName = model.BuildName BuildName = model.BuildName

View File

@ -100,8 +100,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
throw new ArgumentNullException("Некорректный идентификатор у комментария", nameof(model.Id)); 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);
} }
} }
} }

View File

@ -121,7 +121,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); 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);
} }
} }
} }

View File

@ -82,6 +82,7 @@ namespace HardwareShopClientApp.Controllers
} }
if ((int)APIClient.User.Role == 1) if ((int)APIClient.User.Role == 1)
{ {
return RedirectToAction("MainWorker", "Worker");
return RedirectToAction("WorkerReport", "Worker"); return RedirectToAction("WorkerReport", "Worker");
} }
else else

View File

@ -17,11 +17,6 @@ namespace HardwareShopClientApp.Controllers
_logger = logger; _logger = logger;
} }
public IActionResult Builds()
{
return View();
}
public IActionResult Comments() public IActionResult Comments()
{ {
return View(); return View();
@ -40,18 +35,12 @@ namespace HardwareShopClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Purchases() public IActionResult Purchases()
{ {
//return View();
//string login = (string)TempData["UserId"];
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/client/getpurchases?UserId={APIClient.User.Id}")); return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/client/getpurchases?UserId={APIClient.User.Id}"));
} }
[HttpPost] [HttpPost]
public void Purchases(int id) public void Purchases(int id)
{ {
//return View();
//string login = (string)TempData["UserId"];
Response.Redirect("Purchase"); Response.Redirect("Purchase");
} }
@ -59,9 +48,6 @@ namespace HardwareShopClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Purchase() public IActionResult Purchase()
{ {
//return View();
//string login = (string)TempData["UserId"];
return View(); return View();
} }
@ -69,5 +55,30 @@ namespace HardwareShopClientApp.Controllers
{ {
return View(); 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();
}
} }
} }

View 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>

View File

@ -1,7 +1,10 @@
@{ @using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "Builds"; ViewData["Title"] = "Builds";
} }
@model List<BuildViewModel>
@section Header { @section Header {
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <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"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
</nav> </nav>
</header> </header>
} }
<form method="post" class="d-flex justify-content-evenly">
<div class=" col-sm-8">
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Сборки</h2>
</div> </div>
<form method="post" class="d-flex flex-column align-items-center"> <div class="text-center" name="id">
<div class="col-sm-3"> <table class="table">
<label class="form-label">Логин</label> <thead>
<input type="text" class="form-control" aria-describedby="emailHelp" name="login"> <tr>
<th>
Номер
</th>
<th>
Дата оплаты
</th>
<th>
Сумма
</th>
<th>
Статус
</th>
<th>
Логин пользователя
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> </div>
<div class="col-sm-3">
<label class="form-label">Почта</label>
<input type="text" class="form-control" name="email">
</div> </div>
<div class="col-sm-3"> <div class="text-center d-flex flex-column mt-5">
<label class="form-label">Пароль</label> <button type="submit" class="btn btn-primary btn-lg mb-5">Добавить</button>
<input type="password" class="form-control" name="password"> <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> </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>
<button type="submit" class="btn btn-primary mt-3 px-4">Submit</button>
</form> </form>

View File

@ -1,7 +1,10 @@
@{ @using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "Comments"; ViewData["Title"] = "Comments";
} }
@model List<CommentViewModel>
@section Header { @section Header {
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <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"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
</nav> </nav>
</header> </header>
} }
<form method="post" class="d-flex justify-content-evenly">
<div class=" col-sm-8">
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Сборки</h2>
</div> </div>
<form method="post" class="d-flex flex-column align-items-center"> <div class="text-center" name="id">
<div class="col-sm-3"> <table class="table">
<label class="form-label">Логин</label> <thead>
<input type="text" class="form-control" aria-describedby="emailHelp" name="login"> <tr>
<th>
Номер
</th>
<th>
Текст
</th>
<th>
Название сборки
</th>
<th>
Логин пользователя
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> </div>
<div class="col-sm-3">
<label class="form-label">Почта</label>
<input type="text" class="form-control" name="email">
</div> </div>
<div class="col-sm-3"> <div class="text-center d-flex flex-column mt-5">
<label class="form-label">Пароль</label> <button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
<input type="password" class="form-control" name="password"> <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>
<div class="col-sm-3">
<label class="form-label">Роль</label> <!-- Модальное окно -->
<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"> <select class="form-select" name="role">
<option value="1">Работник</option> <option value="1">Сборка 1</option>
<option value="2">Кладовщик</option> <option value="2">Сборка 2</option>
</select> </select>
</div> </div>
<button type="submit" class="btn btn-primary mt-3 px-4">Submit</button> <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> </form>

View File

@ -27,6 +27,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -30,6 +30,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -55,7 +58,7 @@
Цена Цена
</th> </th>
<th> <th>
Пользователь Логин пользователя
</th> </th>
<th> <th>
Количество Количество
@ -79,25 +82,25 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="col-sm-3"> <div>
<label class="form-label">Товар</label> <label class="form-label">Товар</label>
<select class="form-select" name="role"> <select class="form-select" name="role">
<option value="1">Товар 1</option> <option value="1">Товар 1</option>
<option value="2">Товар 2</option> <option value="2">Товар 2</option>
</select> </select>
</div> </div>
<div class="col-sm-3"> <div>
<label class="form-label">Количество</label> <label class="form-label">Количество</label>
<input type="number" class="form-control" name="count"> <input type="number" class="form-control" name="count">
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button> <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> </div>
</div> </div>

View File

@ -29,6 +29,9 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <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> </li>
</ul> </ul>
</div> </div>
@ -64,7 +67,7 @@
Статус Статус
</th> </th>
<th> <th>
Пользователь Логин пользователя
</th> </th>
</tr> </tr>
</thead> </thead>

View File

@ -28,6 +28,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="linkingBuild">linkingBuild</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -35,4 +38,14 @@
</header> </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>

View File

@ -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>

View File

@ -1,7 +1,11 @@
@{ @using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "listComponents"; ViewData["Title"] = "listComponents";
} }
@model List<PurchaseViewModel>
@section Header { @section Header {
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <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>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Worker" asp-action="WorkerReport">WorkerReport</a> <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> </li>
</ul> </ul>
</div> </div>
@ -33,30 +40,67 @@
</nav> </nav>
</header> </header>
} }
<form method="post" class="d-flex justify-content-evenly">
<div class=" col-sm-8">
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Покупки</h2>
</div> </div>
<form method="post" class="d-flex flex-column align-items-center"> <div class="text-center" name="id">
<div class="col-sm-3"> <table class="table">
<label class="form-label">Логин</label> <thead>
<input type="text" class="form-control" aria-describedby="emailHelp" name="login"> <tr>
<th>
Номер
</th>
<th>
Дата оплаты
</th>
<th>
Сумма
</th>
<th>
Статус
</th>
<th>
Логин пользователя
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> </div>
<div class="col-sm-3">
<label class="form-label">Почта</label>
<input type="text" class="form-control" name="email">
</div> </div>
<div class="col-sm-3"> <div class="text-center d-flex flex-column mt-5">
<label class="form-label">Пароль</label> <button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
<input type="password" class="form-control" name="password"> <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>
<div class="col-sm-3">
<label class="form-label">Роль</label> <!-- Модальное окно -->
<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"> <select class="form-select" name="role">
<option value="1">Работник</option> <option value="1">Покупка 1</option>
<option value="2">Кладовщик</option> <option value="2">Покупка 2</option>
</select> </select>
</div> </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> </form>

View File

@ -6,12 +6,12 @@ namespace HardwareShopContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public decimal Price { get; set; } public double Price { get; set; }
public string BuildName { get; set; } = string.Empty; public string BuildName { get; set; } = string.Empty;
public int UserId { get; set; } public int UserId { get; set; }
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; } public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
} }
} }

View File

@ -12,7 +12,7 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; } public int UserId { get; set; }
public Dictionary<int, (IComponentModel, int)> GoodComponents public Dictionary<int, (IComponentModel, int)> GoodsComponents
{ {
get; get;
set; set;

View File

@ -7,7 +7,7 @@ namespace HardwareShopContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public decimal Sum { get; set; } public double Sum { get; set; }
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
@ -15,8 +15,6 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; } public int UserId { get; set; }
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new(); public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
} }
} }

View File

@ -1,6 +1,7 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDataModels.Models;
namespace HardwareShopContracts.StoragesContracts namespace HardwareShopContracts.StoragesContracts
{ {

View File

@ -7,16 +7,17 @@ namespace HardwareShopContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Цена")] [DisplayName("Цена")]
public decimal Price { get; set; } public double Price { get; set; }
[DisplayName("Название компонента")] [DisplayName("Название компонента")]
public string BuildName { get; set; } = string.Empty; public string BuildName { get; set; } = string.Empty;
[DisplayName("Логин работника")] [DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty; public string UserLogin { get; set; } = string.Empty;
public int UserId { get; set; } public int UserId { get; set; }
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; } public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
} }
} }

View File

@ -17,7 +17,7 @@ namespace HardwareShopContracts.ViewModels
public int UserId { get; set; } public int UserId { get; set; }
[DisplayName("Логин работника")] [DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty; public string UserLogin { get; set; } = string.Empty;
} }
} }

View File

@ -8,7 +8,7 @@ namespace HardwareShopContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Цена")] [DisplayName("Цена")]
public decimal Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус покупки")] [DisplayName("Статус покупки")]
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
@ -18,11 +18,9 @@ namespace HardwareShopContracts.ViewModels
public int UserId { get; set; } public int UserId { get; set; }
[DisplayName("Логин работника")] [DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty; public string UserLogin { get; set; } = string.Empty;
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new(); public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
} }
} }

View File

@ -9,12 +9,12 @@ namespace HardwareShopDataModels.Models
{ {
public interface IBuildModel : IId public interface IBuildModel : IId
{ {
decimal Price { get; } double Price { get; }
string BuildName { get; } string BuildName { get; }
int UserId { get; } int UserId { get; }
Dictionary<int, (IComponentModel, int)>? BuildComponents { get; } Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
} }
} }

View File

@ -4,17 +4,14 @@ namespace HardwareShopDataModels.Models
{ {
public interface IPurchaseModel : IId public interface IPurchaseModel : IId
{ {
decimal Sum { get; } double Sum { get; }
PurchaseStatus PurchaseStatus { get; } PurchaseStatus PurchaseStatus { get; }
//через "?" обозначается что поле может быть null
DateTime? DatePurchase { get; } DateTime? DatePurchase { get; }
int UserId { get; } int UserId { get; }
Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; }
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; } Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
} }
} }

View File

@ -13,9 +13,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
return context.Builds return context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments)
.Include(x => x.User) .Include(x => x.User)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -24,17 +23,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<BuildViewModel> GetFilteredList(BuildSearchModel model) public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
{ {
if (!model.UserId.HasValue) if (string.IsNullOrEmpty(model.BuildName) && !model.UserId.HasValue)
{ {
return new(); return new();
} }
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
if (!string.IsNullOrEmpty(model.BuildName))
{
return context.Builds return context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments) .Include(x => x.BuildName.Contains(model.BuildName))
.Include(x => x.User) .ToList()
.Where(x => x.UserId == model.UserId) .Select(x => x.GetViewModel)
.ToList();
}
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.Include(x => x.UserId == model.UserId)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -48,9 +55,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
} }
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
return context.Builds return context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments)
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.Id == model.Id) .Where(x => x.Id == model.Id)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) ||
@ -61,7 +67,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public BuildViewModel? Insert(BuildBindingModel model) public BuildViewModel? Insert(BuildBindingModel model)
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
var newBuild = Build.Create(context, model); var newBuild = Build.Create(model);
if (newBuild == null) if (newBuild == null)
{ {
return null; return null;
@ -69,9 +75,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
context.Builds.Add(newBuild); context.Builds.Add(newBuild);
context.SaveChanges(); context.SaveChanges();
return context.Builds return context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments)
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.UserId == model.Id) .Where(x => x.UserId == model.Id)
.FirstOrDefault(x => x.Id == newBuild.Id) .FirstOrDefault(x => x.Id == newBuild.Id)
@ -85,9 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
try try
{ {
var build = context.Builds var build = context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments)
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.UserId == model.UserId) .Where(x => x.UserId == model.UserId)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);
@ -97,7 +101,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
} }
build.Update(model); build.Update(model);
context.SaveChanges(); context.SaveChanges();
build.UpdateComponents(context, model); build.UpdatePurchases(context, model);
transaction.Commit(); transaction.Commit();
return build?.GetViewModel; return build?.GetViewModel;
} }
@ -112,9 +116,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
var element = context.Builds var element = context.Builds
.Include(x => x.Components) .Include(x => x.Purchases)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Purchase)
.Include(x => x.Comments)
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.UserId == model.Id) .Where(x => x.UserId == model.Id)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);

View File

@ -21,7 +21,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<CommentViewModel> GetFilteredList(CommentSearchModel model) public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.BuildId.HasValue && !model.UserId.HasValue)
{ {
return new(); return new();
} }
@ -35,7 +35,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
return context.Comments return context.Comments
.Include(x => x.Build) .Include(x => x.Build)
.Include(x => x.User) .Include(x => x.User)

View File

@ -2,7 +2,9 @@
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDatabaseImplement.Models.Worker; using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HardwareShopDatabaseImplement.Implements.Worker namespace HardwareShopDatabaseImplement.Implements.Worker
@ -13,8 +15,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
return context.Purchases return context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -23,21 +25,15 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model) public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
if (model.UserId.HasValue) if (!model.UserId.HasValue)
{ {
return context.Purchases return new();
.Include(x => x.Builds)
.Include(x => x.Goods)
.Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
} }
return context.Purchases return context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.Id == model.Id) .Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -50,8 +46,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
} }
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
return context.Purchases return context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel; ?.GetViewModel;
@ -68,8 +64,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
context.Purchases.Add(newPurchase); context.Purchases.Add(newPurchase);
context.SaveChanges(); context.SaveChanges();
return context.Purchases return context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.FirstOrDefault(x => x.Id == newPurchase.Id) .FirstOrDefault(x => x.Id == newPurchase.Id)
?.GetViewModel; ?.GetViewModel;
@ -82,8 +78,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
try try
{ {
var purchase = context.Purchases var purchase = context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);
if (purchase == null) if (purchase == null)
@ -93,7 +89,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
purchase.Update(model); purchase.Update(model);
context.SaveChanges(); context.SaveChanges();
purchase.UpdateGoods(context, model); purchase.UpdateGoods(context, model);
purchase.UpdateBuilds(context, model);
transaction.Commit(); transaction.Commit();
return purchase.GetViewModel; return purchase.GetViewModel;
} }
@ -108,8 +103,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{ {
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
var element = context.Purchases var element = context.Purchases
.Include(x => x.Builds)
.Include(x => x.Goods) .Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User) .Include(x => x.User)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)

View File

@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
GoodName = model.GoodName, GoodName = model.GoodName,
Price = model.Price, Price = model.Price,
UserId = model.UserId, 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), Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2 Count = x.Value.Item2
@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
Price = Price, Price = Price,
UserId = UserId, UserId = UserId,
UserLogin = User.Login, UserLogin = User.Login,
GoodComponents = GoodsComponents GoodsComponents = GoodsComponents
}; };
public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model) public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model)
@ -91,18 +91,18 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
{ // удалили те, которых нет в модели { // удалили те, которых нет в модели
context.GoodsComponents context.GoodsComponents
.RemoveRange(goodComponents .RemoveRange(goodComponents
.Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId))); .Where(rec => !model.GoodsComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges(); context.SaveChanges();
// обновили количество у существующих записей // обновили количество у существующих записей
foreach (var updateComponent in goodComponents) foreach (var updateComponent in goodComponents)
{ {
updateComponent.Count = model.GoodComponents[updateComponent.ComponentId].Item2; updateComponent.Count = model.GoodsComponents[updateComponent.ComponentId].Item2;
model.GoodComponents.Remove(updateComponent.ComponentId); model.GoodsComponents.Remove(updateComponent.ComponentId);
} }
context.SaveChanges(); context.SaveChanges();
} }
var good = context.Goods.First(x => x.Id == Id); 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 context.GoodsComponents.Add(new GoodComponent
{ {

View File

@ -4,6 +4,7 @@ using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace HardwareShopDatabaseImplement.Models.Worker namespace HardwareShopDatabaseImplement.Models.Worker
{ {
@ -12,7 +13,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public decimal Price { get; set; } public double Price { get; set; }
[Required] [Required]
public string BuildName { get; set; } = string.Empty; public string BuildName { get; set; } = string.Empty;
@ -23,44 +24,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker
public virtual User User { get; set; } public virtual User User { get; set; }
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<Comment>? Comments { get; set; } public virtual List<Comment> Comments { get; set; } = new();
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<ComponentBuild>? Components { get; set; } public virtual List<ComponentBuild>? Components { get; set; }
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<PurchaseBuild>? Purchases { get; set; } public virtual List<PurchaseBuild> Purchases { get; set; } = new();
public Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
[NotMapped] [NotMapped]
public Dictionary<int, (IComponentModel, int)> BuildComponents public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
{ {
get 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() return new Build()
{ {
Id = model.Id, Id = model.Id,
Price = model.Price,
BuildName = model.BuildName, BuildName = model.BuildName,
UserId = model.UserId, 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, Price = Price,
UserLogin = User.Login, UserLogin = User.Login,
UserId = UserId, 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(); var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
if (buildComponents != null && buildComponents.Count > 0) 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(); context.SaveChanges();
// обновили количество у существующих записей // обновили количество у существующих записей
foreach (var updateComponent in buildComponents) foreach (var updateComponent in buildPurchases)
{ {
updateComponent.Count = model.BuildComponents[updateComponent.ComponentId].Item2; updateComponent.Count = model.BuildPurchases[updateComponent.PurchaseId].Item2;
model.BuildComponents.Remove(updateComponent.ComponentId); model.BuildPurchases.Remove(updateComponent.PurchaseId);
} }
context.SaveChanges(); context.SaveChanges();
} }
var build = context.Builds.First(x => x.Id == Id); 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, Build = build,
Component = context.Components.First(x => x.Id == dc.Key), Purchase = context.Purchases.First(x => x.Id == bp.Key),
Count = dc.Value.Item2 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(); context.SaveChanges();
} }
_buildComponents = null; _buildPurchases = null;
} }
public void UpdateSumPurchase(HardwareShopDatabase context, BuildBindingModel model)
{
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
}
} }
} }

View File

@ -14,7 +14,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public decimal Sum { get; set; } public double Sum { get; set; }
[Required] [Required]
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
@ -29,27 +29,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[ForeignKey("PurchaseId")] [ForeignKey("PurchaseId")]
public virtual List<PurchaseBuild>? Builds { get; set; } 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")] [ForeignKey("PurchaseId")]
public virtual List<PurchaseGood> Goods { get; set; } = new(); public virtual List<PurchaseGood> Goods { get; set; } = new();
public Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null; public Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
[NotMapped] [NotMapped]
public Dictionary<int, (IGoodModel, int)>? PurchaseGoods public Dictionary<int, (IGoodModel, int)> PurchaseGoods
{ {
get get
{ {
@ -70,16 +56,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker
PurchaseStatus = model.PurchaseStatus, PurchaseStatus = model.PurchaseStatus,
DatePurchase = model.DatePurchase, DatePurchase = model.DatePurchase,
UserId = model.UserId, 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 Goods = model.PurchaseGoods.Select(x => new PurchaseGood
{ {
Good = context.Goods.First(y => y.Id == x.Key), Good = context.Goods.First(y => y.Id == x.Key),
Count = x.Value.Item2 Count = x.Value.Item2
}).ToList() }).ToList(),
}; };
} }
@ -87,6 +68,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{ {
PurchaseStatus = model.PurchaseStatus; PurchaseStatus = model.PurchaseStatus;
DatePurchase = model.DatePurchase; DatePurchase = model.DatePurchase;
Sum = model.Sum;
} }
public PurchaseViewModel GetViewModel => new() public PurchaseViewModel GetViewModel => new()
@ -97,38 +79,9 @@ namespace HardwareShopDatabaseImplement.Models.Worker
DatePurchase = DatePurchase, DatePurchase = DatePurchase,
UserId = UserId, UserId = UserId,
UserLogin = User.Login, UserLogin = User.Login,
PurchaseBuilds = PurchaseBuilds,
PurchaseGoods = PurchaseGoods 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) public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model)
{ {
var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList(); var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList();