PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml

59 lines
1.9 KiB
Plaintext

@{
ViewData["Title"] = "Cooks";
}
<body>
<div class="container">
<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>
<table class="table">
<thead>
<tr>
<th>Номер</th>
<th>ФИО</th>
<th>Должность</th>
</tr>
</thead>
<tbody>
@foreach (var cook in ViewBag.Cooks)
{
<tr onclick="selectCook(this)">
<td>@cook.Id</td>
<td>@cook.FIO</td>
<td>@cook.Position</td>
</tr>
}
</tbody>
</table>
</div>
</body>
<form id="selectCookForm" method="post" action="/Home/DeleteCook">
<input type="hidden" id="CookId" name="CookId" value="" />
</form>
<style>
.selected-row {
background-color: lightgray;
}
</style>
<script>
function selectCook(row) {
var CookId = document.getElementById("CookId");
var previousValue = CookId.value;
var currentValue = row.cells[0].innerText;
if (previousValue === currentValue) {
CookId.value = "";
row.classList.remove("selected-row");
} else {
CookId.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>