2024-05-27 21:03:42 +04:00
|
|
|
@using Contracts.ViewModels;
|
|
|
|
@{
|
2024-04-30 00:42:26 +04:00
|
|
|
ViewData["Title"] = "CreateWorker";
|
|
|
|
}
|
2024-05-27 21:03:42 +04:00
|
|
|
@model WorkerViewModel;
|
2024-04-30 00:42:26 +04:00
|
|
|
<div class="text-center">
|
2024-05-27 21:03:42 +04:00
|
|
|
<h2 class="display-4">работник</h2>
|
2024-04-30 00:42:26 +04:00
|
|
|
</div>
|
2024-05-27 21:03:42 +04:00
|
|
|
<form id="workerForm" method="post">
|
|
|
|
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-4">Имя работника:</div>
|
|
|
|
<div class="col-8">
|
|
|
|
<input type="text" name="name" id="name" value="@Model.Name" />
|
|
|
|
<span id="nameError" class="text-danger"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-4">Дата рождения:</div>
|
|
|
|
<div class="col-8">
|
|
|
|
<input type="date" name="birthday" id="birthday" value="@Model.Birthday.ToString("yyyy-MM-dd")" />
|
|
|
|
<span id="birthdayError" class="text-danger"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-4">Специальность:</div>
|
|
|
|
<div class="col-8">
|
|
|
|
<input type="text" name="specialization" id="specialization" value="@Model.Specialization" />
|
|
|
|
<span id="specializationError" class="text-danger"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-4">Заработная плата:</div>
|
|
|
|
<div class="col-8">
|
|
|
|
<input type="text" name="salary" id="salary" value="@Model.Salary" />
|
|
|
|
<span id="salaryError" class="text-danger"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-8"></div>
|
|
|
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('#detailForm').submit(function (event) {
|
|
|
|
var name = $('#name').val();
|
|
|
|
var birthday = $('#birthday').val();
|
|
|
|
var specialization = $('#specialization').val();
|
|
|
|
var salary = $('#salary').val();
|
|
|
|
var isValid = true;
|
|
|
|
|
|
|
|
$('#nameError').text('');
|
|
|
|
$('#birthdayError').text('');
|
|
|
|
$('#specializationError').text('');
|
|
|
|
$('#salaryError').text('');
|
|
|
|
|
|
|
|
if (name.length < 2 || name.length > 50) {
|
|
|
|
$('#nameError').text('Имя работника должно быть от 2 до 50 символов.');
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Date.parse(birthday)) {
|
|
|
|
$('#birthdayError').text('Введите корректную дату рождения.');
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specialization.length < 2 || specialization.length > 50) {
|
|
|
|
$('#specializationError').text('Специальность должна быть от 2 до 50 символов.');
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(salary) || salary <= 0) {
|
|
|
|
$('#salaryError').text('Заработная плата должна быть положительным числом.');
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isValid) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|