2023-04-09 19:05:54 +04:00
|
|
|
@{
|
2023-05-17 17:02:26 +04:00
|
|
|
ViewData["Title"] = "Products";
|
2023-04-09 19:05:54 +04:00
|
|
|
}
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
2023-05-17 17:02:26 +04:00
|
|
|
<h2>Список список продуктов</h2>
|
|
|
|
<a type="button" class="btn btn-success" href="/Home/CreateCook">Добавить продукт</a>
|
|
|
|
<button type="submit" class="btn btn-danger" form="selectCookForm">Удалить продукт</button>
|
|
|
|
<a type="button" class="btn btn-warning" href="/Home/UpdateCook">Обновить продукт</a>
|
2023-04-09 19:05:54 +04:00
|
|
|
<table class="table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Номер</th>
|
2023-05-17 17:02:26 +04:00
|
|
|
<th>Название</th>
|
2023-04-09 19:05:54 +04:00
|
|
|
<th>Цена</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2023-05-17 17:02:26 +04:00
|
|
|
@foreach (var cook in ViewBag.Cooks)
|
2023-04-09 19:05:54 +04:00
|
|
|
{
|
2023-05-17 17:02:26 +04:00
|
|
|
<tr onclick="selectCook(this)">
|
|
|
|
<td>@cook.Id</td>
|
|
|
|
<td>@cook.Name</td>
|
|
|
|
<td>@cook.Price</td>
|
|
|
|
</tr>
|
2023-04-09 19:05:54 +04:00
|
|
|
}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2023-05-17 17:02:26 +04:00
|
|
|
</body>
|
|
|
|
<form id="selectCookForm" method="post" action="/Home/DeleteCook">
|
|
|
|
<input type="hidden" id="ProductId" name="ProductId" value="" />
|
|
|
|
</form>
|
|
|
|
<style>
|
|
|
|
.selected-row {
|
|
|
|
background-color: lightgray;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
function selectCook(row) {
|
|
|
|
var ProductId = document.getElementById("ProductId");
|
|
|
|
var previousValue = ProductId.value;
|
|
|
|
var currentValue = row.cells[0].innerText;
|
|
|
|
|
|
|
|
if (previousValue === currentValue) {
|
|
|
|
ProductId.value = "";
|
|
|
|
row.classList.remove("selected-row");
|
|
|
|
} else {
|
|
|
|
ProductId.value = currentValue;
|
|
|
|
|
|
|
|
var rows = document.getElementsByTagName("tr");
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
rows[i].classList.remove("selected-row");
|
|
|
|
}
|
|
|
|
|
|
|
|
row.classList.add("selected-row");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|