﻿@using VeterinaryContracts.ViewModels;

@{
	ViewData["Title"] = "UpdateVisit";
}

<div class="text-center">
	<h2 class="display-4">Редактирование визита</h2>
</div>
<form method="post">
	<div class="row">
		<div class="col-4">Визит:</div>
		<div class="col-8">
			<select id="visit" name="visit" class="form-control" asp-items="@(new SelectList(@ViewBag.Visits, "Id", "VisitName"))"></select>
		</div>
	</div>
	<div class="row">
		<div class="col-4">Название:</div>
		<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></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>

@section Scripts
	{
	<script>
		function check() {
			var visit = $('#visit').val();
			if (visit) {
				$.ajax({
					method: "GET",
					url: "/Home/GetVisit",
					data: { visitId: visit },
					success: function (result) {
						$('#name').val(result.item1.visitName);
					}
				});
			};
		}
		check();
		$('#visit').on('change', function () {
			check();
		});
	</script>
}