﻿@using VeterinaryContracts.ViewModels;

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

<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="medication" name="medication" class="form-control" asp-items="@(new SelectList(@ViewBag.Medications, "Id", "MedicationName"))"></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-4">Цена:</div>
		<div class="col-8"><input type="number" id="price" name="price" 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 medication = $('#medication').val();
			if (medication) {
				$.ajax({
					method: "GET",
					url: "/Home/GetMedication",
					data: { medicationId: medication },
					success: function (result) {
						$('#name').val(result.item1.medicationName);
						$('#price').val(result.item1.price);
					}
				});
			};
		}
		check();
		$('#medication').on('change', function () {
			check();
		});
	</script>
}