Compare commits

..

8 Commits

Author SHA1 Message Date
4eb1097562 Исправлены недочёты, все макеты открываются 2024-05-01 23:12:19 +04:00
gg12 darfren
2f2f6aa4bc Еще правки 2024-05-01 10:45:25 +04:00
gg12 darfren
0311309a63 Еще допиливаю 2024-04-29 22:52:25 +04:00
gg12 darfren
904264de3d Правлю 2024-04-29 22:29:35 +04:00
04961cbd72 Merge branch 'Worker' 2024-04-29 21:22:58 +04:00
gg12 darfren
f09946ecd5 Доделал визуал крудов (наверное) 2024-04-29 13:56:26 +04:00
gg12 darfren
0f1757fc1d Завтра доделаю 2024-04-28 21:05:43 +04:00
gg12 darfren
62570a8348 Сделал формочку услуги 2024-04-28 17:34:36 +04:00
38 changed files with 920 additions and 258 deletions

View File

@ -321,148 +321,270 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
return result;
}
//public IActionResult CreateService()
//{
// if (APIPharmacist.Pharmacist == null)
// {
// return Redirect("~/Home/Enter");
// }
// ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/animal/getmedicines");
public IActionResult Services()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
return
View(APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}"));
// return View();
//}
}
public IActionResult CreateService()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
return View();
}
//[HttpPost]
//public void CreateService(string name, string price, List<int> medicines)
//{
// if (APIPharmacist.Pharmacist == null)
// {
// throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
// }
// double _price;
// try
// {
// _price = Convert.ToDouble(price);
// }
// catch (Exception ex)
// {
// throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
// }
// if (string.IsNullOrEmpty(name) || _price <= 0)
// {
// throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
// }
// Dictionary<int, IMedicineModel> a = new Dictionary<int, IMedicineModel>();
// foreach (int medicine in medicines)
// {
// a.Add(medicine, new AnimalSearchModel { Id = medicine } as IMedicineModel);
// }
[HttpPost]
public void CreateService(string name, string price, List<int> medicines)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
StringBuilder st = new StringBuilder(price);
for (int i = 0; i < price.Length; i++)
{
if (price[i] == '.')
st[i] = ',';
}
price = st.ToString();
double _price;
try
{
_price = Convert.ToDouble(price);
}
catch (Exception ex)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
if (string.IsNullOrEmpty(name) || _price <= 0)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
Dictionary<int, IMedicineModel> a = new Dictionary<int, IMedicineModel>();
foreach (int medicine in medicines)
{
a.Add(medicine, new MedicineSearchModel { Id = medicine } as IMedicineModel);
}
// APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel
// {
// ServiceName = name,
// Price = Math.Round(_price, 2),
// PharmacistId = APIPharmacist.Pharmacist.Id,
// ServiceMedicines = a
// });
// Response.Redirect("Index");
//}
APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel
{
ServiceName = name,
Price = Math.Round(_price, 2),
PharmacistId = APIPharmacist.Pharmacist.Id,
ServiceMedicines = a
});
Response.Redirect("Index");
}
//public IActionResult DeleteMedicine()
//{
// if (APIPharmacist.Pharmacist == null)
// {
// return Redirect("~/Home/Enter");
// }
// ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}");
// return View();
//}
public IActionResult DeleteService()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
//[HttpPost]
//public void DeleteMedicine(int medicine)
//{
// if (APIPharmacist.Pharmacist == null)
// {
// throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
// }
// APIPharmacist.PostRequest("api/medicine/deletemedicine", new MedicineBindingModel
// {
// Id = medicine
// });
// Response.Redirect("Index");
//}
[HttpPost]
public void DeleteService(int service)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
APIPharmacist.PostRequest("api/service/deleteservice", new ServiceBindingModel
{
Id = service
});
Response.Redirect("Index");
}
//public IActionResult UpdateMedicine()
//{
// if (APIPharmacist.Pharmacist == null)
// {
// return Redirect("~/Home/Enter");
// }
// ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}");
// ViewBag.Animals = APIPharmacist.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist");
// return View();
//}
public IActionResult UpdateService()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
ViewBag.Medicines = APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
return View();
}
//[HttpPost]
//public void UpdateMedicine(int medicine, string name, string price,
// List<int> animals)
//{
// if (APIPharmacist.Pharmacist == null)
// {
// throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
// }
// double _price;
// try
// {
// _price = Convert.ToDouble(price);
// }
// catch (Exception ex)
// {
// throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
// }
// if (string.IsNullOrEmpty(name) || _price <= 0)
// {
// throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
// }
// Dictionary<int, IAnimalModel> a = new Dictionary<int, IAnimalModel>();
// foreach (int animal in animals)
// {
// a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel);
// }
// APIPharmacist.PostRequest("api/medicine/updatemedicine", new MedicineBindingModel
// {
// Id = medicine,
// MedicineName = name,
// Price = Math.Round(_price, 2),
// PharmacistId = APIPharmacist.Pharmacist.Id,
// MedicineAnimals = a
// });
// Response.Redirect("Index");
//}
[HttpPost]
public void UpdateService(int service, string name, string price,
List<int> medicines)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
StringBuilder st = new StringBuilder(price);
for (int i = 0; i < price.Length; i++)
{
if (price[i] == '.')
st[i] = ',';
}
price = st.ToString();
double _price;
try
{
_price = Convert.ToDouble(price);
}
catch (Exception ex)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
if (string.IsNullOrEmpty(name) || _price <= 0)
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
Dictionary<int, IMedicineModel> a = new Dictionary<int, IMedicineModel>();
foreach (int medicine in medicines)
{
a.Add(medicine, new MedicineSearchModel { Id = medicine } as IMedicineModel);
}
APIPharmacist.PostRequest("api/service/updateservice", new ServiceBindingModel
{
Id = service,
ServiceName = name,
Price = Math.Round(_price, 2),
PharmacistId = APIPharmacist.Pharmacist.Id,
ServiceMedicines = a
});
Response.Redirect("Index");
}
//[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
//public IActionResult Error()
//{
// return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
//}
[HttpGet]
public Tuple<ServiceViewModel, List<string>>? GetService(int serviceId)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIPharmacist.GetRequest<Tuple<ServiceViewModel, List<string>>>($"api/service/getservice?serviceid={serviceId}");
if (result == null)
{
return default;
}
//[HttpGet]
//public Tuple<MedicineViewModel, List<string>>? GetMedicine(int medicineId)
//{
// if (APIPharmacist.Pharmacist == null)
// {
// throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
// }
// var result = APIPharmacist.GetRequest<Tuple<MedicineViewModel, List<string>>>($"api/medicine/getmedicine?medicineid={medicineId}");
// if (result == null)
// {
// return default;
// }
return result;
}
// return result;
//}
public IActionResult Guidances()
{
if (APIPharmacist.Pharmacist == null)
{
return Redirect("~/Home/Enter");
}
var res = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
return
View(res);
}
[HttpGet]
public IActionResult CreateGuidance()
{
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
[HttpPost]
public void CreateGuidance(int service, string text)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(text))
{
throw new Exception("Рекомендация не может быть пустой");
}
APIPharmacist.PostRequest("api/guidance/createguidance", new
GuidanceBindingModel
{
ServiceId = service,
Text = text,
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult UpdateGuidance()
{
ViewBag.Services = APIPharmacist.GetRequest<List<ServiceViewModel>>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}");
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
[HttpPost]
public void UpdateGuidance(int guidance, int service, string text)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(text))
{
throw new Exception("Рекомендация не может быть пустой");
}
APIPharmacist.PostRequest("api/guidance/updateguidance", new
GuidanceBindingModel
{
Id = guidance,
ServiceId = service,
Text = text,
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult DeleteGuidance()
{
ViewBag.Guidances = APIPharmacist.GetRequest<List<GuidanceViewModel>>($"api/guidance/getguidances?pharmacistid={APIPharmacist.Pharmacist.Id}");
return View();
}
[HttpPost]
public void DeleteGuidance(int guidance)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIPharmacist.PostRequest("api/guidance/deleteguidance", new
GuidanceBindingModel
{
Id = guidance
});
Response.Redirect("Index");
}
[HttpGet]
public GuidanceViewModel GetGuidance(int guidanceId)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIPharmacist.GetRequest<GuidanceViewModel>($"api/guidance/getguidance?guidanceid={guidanceId}");
if (result == null)
{
return default;
}
return result;
}
}
}

View File

@ -0,0 +1,29 @@
@{
ViewData["Title"] = "CreateGuidance";
}
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services,"Id", "ServiceName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Текст:</div>
<div class="col-8">
<textarea id="text" name="text" rows="5" cols="80">
</textarea>
</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>

View File

@ -0,0 +1,39 @@
@{
ViewData["Title"] = "CreateService";
}
<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">
<input type="text" name="name" id="name" />
</div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8">
<input type="text" name="price" id="price" />
</div>
</div>
<div class="row">
<div class="col-4">Медикаменты:</div>
<div class="col-8">
<select name="medicines" class="form-control" multiple size="6" id="medicines">
@foreach (var medicine in ViewBag.Medicines)
{
<option value="@medicine.Id">@medicine.MedicineName</option>
}
</select>
</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>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteGuidance";
}
<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="guidance" name="guidance" class="form-control" asp-items="@(new SelectList(@ViewBag.Guidances, "Id", "Text"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>

View File

@ -1,5 +1,5 @@
@{
ViewData["Title"] = "Delete";
ViewData["Title"] = "DeleteMedicine";
}
<div class="text-center">
<h2 class="display-4">Удаление медикамента</h2>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteService";
}
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services, "Id", "ServiceName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>s

View File

@ -0,0 +1,63 @@
@using VetClinicContracts.ViewModels
@model List<GuidanceViewModel>
@{
ViewData["Title"] = "Guidances";
}
<div class="text-center">
<h1 class="display-4">Рекомендации</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateGuidance">Создать рекомендацию</a>
<a asp-action="UpdateGuidance">Обновить рекомендацию</a>
<a asp-action="DeleteGuidance">Удалить рекомендацию</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата
</th>
<th>
Услуга
</th>
<th>
Текст
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Date)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.ServiceName)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Text)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -22,7 +22,7 @@
<select name="animals" class="form-control" multiple size="5" id="animals">
@foreach (var animal in ViewBag.Animals)
{
<option value="@animal.Id" id="@animal.AnimalName">@animal.AnimalName</option>
<option value="@animal.Id" data-name="@animal.AnimalName">@animal.AnimalName</option>
}
</select>
</div>
@ -50,7 +50,7 @@
$('#price').val(result.item1.price);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
$(`option[data-name=${n}]`).attr("selected", "selected")
});
}

View File

@ -0,0 +1,56 @@
@using VetClinicContracts.ViewModels
@model List<ServiceViewModel>
@{
ViewData["Title"] = "Services";
}
<div class="text-center">
<h1 class="display-4">Услуги</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateService">Создать услугу</a>
<a asp-action="UpdateService">Обновить услугу</a>
<a asp-action="DeleteService">Удалить услугу</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
<th>
Цена
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.ServiceName)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Price)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,65 @@
@{
ViewData["Title"] = "UpdateGuidance";
}
<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="guidance" name="guidance" class="form-control" asp-items="@(new SelectList(@ViewBag.Guidances,"Id", "Text"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Услуга:</div>
<div class="col-8">
<select name="service" class="form-control" id="service">
@foreach (var service in ViewBag.Services)
{
<option value="@service.Id" id="@service.Id">@service.ServiceName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4">Текст:</div>
<div class="col-8">
<textarea id="text" name="text" rows="5" cols="80">
</textarea>
</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>
function check() {
var guidance = $('#guidance').val();
$("#service option:selected").removeAttr("selected");
if (guidance) {
$.ajax({
method: "GET",
url: "/Home/GetGuidance",
data: { guidanceId: guidance },
success: function (result) {
console.log(result.item2);
$('#text').val(result.text);
$(`option[data-name=${result.serviceId}]`).attr("selected", "selected")
}
});
};
}
check();
$('#guidance').on('change', function () {
check();
});
</script>

View File

@ -0,0 +1,71 @@
@using VetClinicContracts.ViewModels;
@{
ViewData["Title"] = "UpdateService";
}
<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="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services, "Id", "ServiceName"))"></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="text" id="price" name="price" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Медикаменты:</div>
<div class="col-8">
<select name="medicines" class="form-control" multiple size="5" id="medicines">
@foreach (var medicine in ViewBag.Medicines)
{
<option value="@medicine.Id" data-name="@medicine.MedicineName">@medicine.MedicineName</option>
}
</select>
</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 service = $('#service').val();
$("#medicines option:selected").removeAttr("selected");
if (service) {
$.ajax({
method: "GET",
url: "/Home/GetService",
data: { serviceId: service },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.serviceName);
$('#price').val(result.item1.price);
$.map(result.item2, function ( n ) {
console.log("#" + n);
$(`option[data-name=${n}]`).attr("selected", "selected")
});
}
});
};
}
check();
$('#service').on('change', function () {
check();
});
</script>
}

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - IceCreamShopClientApp</title>
<title>@ViewData["Title"] - PharmacistApp </title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@ -13,7 +13,7 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bgwhite border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" aspaction="Index">Магазин мороженного</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" aspaction="Index">Ветклиника</a>
<button class="navbar-toggler" type="button" datatoggle="collapse" data-target=".navbar-collapse" ariacontrols="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
@ -23,6 +23,12 @@
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Медикаменты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Services">Услуги</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Guidances">Рекомендации</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
@ -44,7 +50,7 @@
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2024 - Магазин мороженного - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
&copy; 2024 - Ветклиника - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
</div>
</footer>
<script src="~/js/site.js" asp-append-version="true"></script>

View File

@ -6,6 +6,7 @@ using VetClinicContracts.ViewModels;
using VetClinicDataModels.Models;
using System.Text;
using VetClinicContracts.SearchModels;
using System.IO.Pipelines;
namespace VetClinicAdminApp.Controllers
@ -18,7 +19,17 @@ namespace VetClinicAdminApp.Controllers
{
_logger = logger;
}
[HttpGet]
public IActionResult ServiceListReport()
{
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}");
return View();
}
[HttpGet]
public IActionResult Report()
{
return View();
}
public IActionResult Index()
{
if (APIAdmin.Admin == null)
@ -46,7 +57,7 @@ View(APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?admin
return Redirect("~/Home/Enter");
}
return
View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccinations?vaccinationId={APIAdmin.Admin.Id}"));
View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccinations?adminId={APIAdmin.Admin.Id}"));
}
@ -137,6 +148,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
{
return Redirect("~/Home/Enter");
}
ViewBag.Services = APIAdmin.GetRequest<List<ServiceViewModel>>($"api/service/getservices");
return View();
}
public IActionResult CreateAnimal()
@ -145,11 +157,12 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
{
return Redirect("~/Home/Enter");
}
ViewBag.Services = APIAdmin.GetRequest<List<ServiceViewModel>>($"api/service/getservices?adminid={APIAdmin.Admin.Id}");
return View();
}
public IActionResult CreateVaccination()
{
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>("api/animal/getanimallist");
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}");
return View();
}
@ -192,7 +205,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
Response.Redirect("IndexAnimals");
}
[HttpPost]
public void CreateVaccination(int animale, string name, double cost,DateTime date)
public void CreateVaccination(int animale, string name, string cost,DateTime date)
{
if (APIAdmin.Admin == null)
{
@ -202,15 +215,35 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
{
throw new Exception("Ошибка в введенных данных");
}
if (cost <= 0)
StringBuilder st = new StringBuilder(cost);
for (int i = 0; i < cost.Length; i++)
{
if (cost[i] == '.')
st[i] = ',';
}
cost = st.ToString();
double _cost;
try
{
_cost = Convert.ToDouble(cost);
}
catch (Exception ex)
{
throw new Exception("Ошибка в введенных данных");
}
if (_cost <= 0)
{
throw new Exception("Цена должна быть выше 0");
}
if (date == null)
{
throw new Exception("Выберите дату");
}
APIAdmin.PostRequest("api/vaccination/createvaccination", new VaccinationBindingModel
{
NameVaccination = name,
AnimalId = animale,
CostVaccination = cost,
CostVaccination = Math.Round(_cost, 2),
DateStamp = date
});
Response.Redirect("IndexVaccinations");
@ -292,7 +325,8 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
{
return Redirect("~/Home/Enter");
}
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>("api/visit/getvisits");
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?pharmacistid={APIAdmin.Admin.Id}");
ViewBag.Services = APIAdmin.GetRequest<List<ServiceViewModel>>($"api/service/getservices");
return View();
}
@ -322,6 +356,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
return Redirect("~/Home/Enter");
}
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}");
return View();
}
@ -429,6 +464,7 @@ View(APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccin
return Redirect("~/Home/Enter");
}
ViewBag.Vaccinations = APIAdmin.GetRequest<List<VaccinationViewModel>>($"api/vaccination/getvaccinations?adminid={APIAdmin.Admin.Id}");
ViewBag.Animals = APIAdmin.GetRequest<List<AnimalViewModel>>($"api/animal/getanimallist?adminid={APIAdmin.Admin.Id}");
return View();
}

View File

@ -16,7 +16,18 @@
<div class="row">
<div class="col-4">Дата:</div>
<div class="col-8">
<input type="datetime" id="datetime" name="date" />
<input type="date" id="date" name="date" />
</div>
</div>
<div class="row">
<div class="col-4">Услуги:</div>
<div class="col-8">
<select name="services" class="form-control" multiple size="6" id="services">
@foreach (var service in ViewBag.Services)
{
<option value="@service.Id">@service.ServiceName</option>
}
</select>
</div>
</div>
<div class="row">

View File

@ -20,7 +20,6 @@
<p>
<a asp-action="Update">Редактировать визит</a>
<a asp-action="Delete">Удалить визит</a>
<a asp-action="ServiceVisits">Связать визит и услуги</a>
</p>
<p>
<a asp-action="Create">Создать визит</a>

View File

@ -0,0 +1,59 @@
@{
ViewData["Title"] = "Report";
}
<div class="text-center">
<h1 class="display-4">Список визитов с расшифровкой по медикаментам и прививкам</h1>
</div>
<div class="text-center">
@{
// if (Model == null)
// {
// <h3 class="display-4">Авторизируйтесь!</h3>
// return;
// }
<div class="row mb-5">
<div class="col-4">Начальная дата:</div>
<div class="col-8">
<input type="date" id="startDate" name="startDate" class="form-control">
</div>
</div>
<div class="row mb-5">
<div class="col-4">Конечная дата:</div>
<div class="col-8">
<input type="date" id="endDate" name="endDate" class="form-control">
</div>
</div>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата
</th>
<th>
Визит
</th>
<th>
Медикамент
</th>
<th>
Прививка
</th>
</tr>
</thead>
<tbody>
будет заполняться вьюшками отчета
</tbody>
</table>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать отчет" class="btn btn-primary" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
</div>
}
</div>

View File

@ -0,0 +1,30 @@
@using VetClinicContracts.ViewModels;
@{
ViewData["Title"] = "ServiceListReport";
}
<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 name="animals" class="form-control" multiple size="5" id="animals">
@foreach (var animal in ViewBag.Animals)
{
<option value="@animal.Id">@animal.AnimalName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Word" class="btn btn-primary" /></div>
<div class="col-4"><input type="submit" value="Excel" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -1,65 +0,0 @@
@using VetClinicContracts.ViewModels;
@{
ViewData["Title"] = "ServiceVisits";
}
<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", "NameVisit"))"></select>
</div>
</div>
<input style = "visibility: hidden" type="text" name="name" id="name" class="form-control" />
<input style="visibility: hidden" type="datetime" id="datetime" name="date" class="form-control" />
<div class="row">
<div class="col-4">Услуги:</div>
<div class="col-8">
<select name="services" class="form-control" multiple size="5" id="services">
@foreach (var service in ViewBag.Services)
{
<option value="@service.Id" id="@service.ServicesName">@service.ServicesName</option>
}
</select>
</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 animal = $('#visit').val();
$("#services option:selected").removeAttr("selected");
if (animal) {
$.ajax({
method: "GET",
url: "/Home/GetVisit",
data: { animalId: animal },
success: function (result) {
console.log(result.item2);
$('#name').val(result.item1.visitName);
$('#date').val(result.item1.date);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#visit').on('change', function () {
check();
});
</script>
}

View File

@ -22,10 +22,20 @@
<div class="row">
<div class="col-4">Дата:</div>
<div class="col-8">
<input type="datetime" id="datetime" name="date" />
<input type="date" id="date" name="date" />
</div>
</div>
<div class="row">
<div class="col-4">Услуги:</div>
<div class="col-8">
<select name="services" class="form-control" multiple size="5" id="services">
@foreach (var services in ViewBag.Services)
{
<option value="@services.Id" data-name="@services.ServiceName">@services.ServiceName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
@ -46,6 +56,10 @@
success: function (result) {
$('#name').val(result.item1.vistName);
$('#date').val(result.item1.date);
$.map(result.item2, function (n) {
console.log("#" + n);
$(`option[data-name=${n}]`).attr("selected", "selected")
});
}
});
};

View File

@ -43,7 +43,7 @@
data: { animalId: animal },
success: function (result) {
$('#name').val(result.item1.animalName);
$('#family').val(result.item1.price);
$('#family').val(result.item1.family);
}
});
};

View File

@ -12,6 +12,17 @@
<select id="vaccination" name="vaccination" class="form-control" asp-items="@(new SelectList(@ViewBag.Vaccinations, "Id", "NameVaccination"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Животное:</div>
<div class="col-8">
<select name="animal" class="form-control" id="animal">
@foreach (var animal in ViewBag.Animals)
{
<option value="@animal.Id" id="@animal.Id">@animal.AnimalName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">
@ -44,13 +55,20 @@
if (snack) {
$.ajax({
method: "POST",
url: "/Home/GetAnimal",
data: { animal: animal },
url: "/Home/GetVaccination",
data: { vaccinationId: vaccinationId },
success: function (result) {
$("#animal").val(result);
$('#name').val(result.text);
$('#cost').val(result.text);
$('#date').val(result.date);
$(`option[data-name=${result.animalId}]`).attr("selected", "selected")
}
});
};
}
check();
$('#vaccination').on('change', function () {
check();
});
</script>

View File

@ -22,7 +22,7 @@
<select name="visits" class="form-control" multiple size="5" id="visits">
@foreach (var visit in ViewBag.Visits)
{
<option value="@visit.Id" id="@visit.NameVisit">@visit.NameVisit</option>
<option value="@visit.Id" data-name="@visit.NameVisit">@visit.NameVisit</option>
}
</select>
</div>

View File

@ -32,6 +32,12 @@
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="ServiceListReport">Выгрузка списка</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Report">Отчет</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>

View File

@ -11,7 +11,7 @@ namespace VetClinicContracts.BindingModels
{
public int Id { get; set; }
public string Text { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public int ServiceId { get; set; }
}
}

View File

@ -10,6 +10,7 @@ namespace VetClinicContracts.SearchModels
{
public int? Id { get; set; }
public string? Text { get; set; }
public int? PharmacistId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ServiceId { get; set; }

View File

@ -9,6 +9,7 @@ namespace VetClinicContracts.SearchModels
public class VaccinationSearchModel
{
public int? Id { get; set; }
public int? AdminId { get; set; }
public string? NameVaccination { get; set; }
public double? CostVaccination { get; set; }

View File

@ -25,7 +25,7 @@ namespace VetClinicDataBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Guidances.Include(x => x.Service).Where(x => (!model.Id.HasValue || model.Id == x.Id)
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
&& (!model.DateTo.HasValue || model.DateTo >= x.Date))
&& (!model.DateTo.HasValue || model.DateTo >= x.Date) && (!model.PharmacistId.HasValue || model.PharmacistId == x.Service.PharmacistId))
.Select(x => x.GetViewModel)
.ToList();
}
@ -33,7 +33,8 @@ namespace VetClinicDataBaseImplement.Implements
{
using var context = new VetClinicDatabase();
return context.Guidances.Include(x => x.Service).FirstOrDefault(x => (!model.Id.HasValue || model.Id == x.Id)
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (string.IsNullOrEmpty(model.Text) || model.Text == x.Text)
&& (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
&& (!model.DateTo.HasValue || model.DateTo >= x.Date))?.GetViewModel;
}
public GuidanceViewModel? Insert(GuidanceBindingModel model)
@ -51,21 +52,20 @@ namespace VetClinicDataBaseImplement.Implements
public GuidanceViewModel? Update(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Guidances
.Include(x => x.Service)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
var order = context.Guidances.Include(x => x.Service).FirstOrDefault(x => x.Id ==
model.Id);
if (order == null)
{
context.Guidances.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return null;
}
return null;
order.Update(context, model);
context.SaveChanges();
return order.GetViewModel;
}
public GuidanceViewModel? Delete(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Guidances.FirstOrDefault(rec => rec.Id ==
var element = context.Guidances.Include(x => x.Service).FirstOrDefault(rec => rec.Id ==
model.Id);
if (element != null)
{

View File

@ -25,7 +25,7 @@ namespace VetClinicDataBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Vaccinations.Include(x => x.Animal).Where(x => (!model.Id.HasValue || model.Id == x.Id)
&& (!model.AnimalId.HasValue || model.AnimalId == x.AnimalId) && (!model.DateFrom.HasValue || model.DateFrom <= x.DateStamp)
&& (!model.DateTo.HasValue || model.DateTo >= x.DateStamp))
&& (!model.DateTo.HasValue || model.DateTo >= x.DateStamp) && (!model.AdminId.HasValue || model.AdminId == x.Animal.AdminId))
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -93,10 +93,14 @@ namespace VetClinicDataBaseImplement.Models
{
var visitAnimals = context.VisitAnimals.Where(rec => rec.AnimalId == model.Id).ToList();
if (visitAnimals != null)
{ // удалили те, которых нет в модели
{
context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.VisitId)));
context.SaveChanges();
foreach (var visit in visitAnimals)
{
model.VisitAnimals.Remove(visit.VisitId);
}
context.SaveChanges();
}
var animal = context.Animals.First(x => x.Id == Id);
foreach (var pc in model.VisitAnimals)

View File

@ -36,7 +36,7 @@ namespace VetClinicDataBaseImplement.Models
};
}
public void Update(GuidanceBindingModel? model)
public void Update(VetClinicDatabase context, GuidanceBindingModel? model)
{
if (model == null)
{
@ -44,6 +44,8 @@ namespace VetClinicDataBaseImplement.Models
}
Text = model.Text;
Date = model.Date;
ServiceId = model.ServiceId;
Service = context.Services.FirstOrDefault(x => x.Id == model.ServiceId);
}
public GuidanceViewModel GetViewModel => new()

View File

@ -52,6 +52,8 @@ namespace VetClinicDataBaseImplement.Models
Id = model.Id,
ServiceName = model.ServiceName,
Price = model.Price,
PharmacistId = model.PharmacistId,
Pharmacist = context.Pharmacists.First(x => x.Id == model.PharmacistId),
Medicines = model.ServiceMedicines.Select(x => new
ServiceMedicine
{

View File

@ -95,7 +95,11 @@ namespace VetClinicDataBaseImplement.Models
{ // удалили те, которых нет в модели
context.ServiceVisits.RemoveRange(serviceVisits.Where(rec => !model.ServiceVisits.ContainsKey(rec.ServiceId)));
context.SaveChanges();
foreach (var service in serviceVisits)
{
model.ServiceVisits.Remove(service.ServiceId);
}
context.SaveChanges();
}
var visit = context.Visits.First(x => x.Id == Id);
foreach (var pc in model.ServiceVisits)

View File

@ -29,7 +29,7 @@ namespace VetClinicRestApi.Controllers
if (elem == null)
return null;
var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.NameVisit).ToList());
res.Item1.VisitAnimals = null;
res.Item1.VisitAnimals = null!;
return res;
}
catch (Exception ex)
@ -40,13 +40,17 @@ namespace VetClinicRestApi.Controllers
}
[HttpGet]
public List<AnimalViewModel>? GetAnimalList(int adminId)
public List<AnimalViewModel>? GetAnimalList(int? adminId = null)
{
try
{
var res = _animal.ReadList(new AnimalSearchModel { AdminId = adminId });
List<AnimalViewModel> res;
if (!adminId.HasValue)
res = _animal.ReadList(null);
else
res = _animal.ReadList(new AnimalSearchModel { AdminId = adminId });
foreach (var animal in res)
animal.VisitAnimals = null;
animal.VisitAnimals = null!;
return res;
}
catch (Exception ex)

View File

@ -21,20 +21,35 @@ namespace VetClinicRestApi.Controllers
_logger = logger;
_guidance = guidance;
}
[HttpGet]
public List<GuidanceViewModel>? GetGuidances(int serviceId)
public GuidanceViewModel GetGuidance(int guidanceId)
{
try
{
var elem = _guidance.ReadElement(new GuidanceSearchModel { Id = guidanceId });
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения рекомендации по id={Id}", guidanceId);
throw;
}
}
[HttpGet]
public List<GuidanceViewModel>? GetGuidances(int? pharmacistId = null)
{
try
{
if (!pharmacistId.HasValue)
return _guidance.ReadList(null);
return _guidance.ReadList(new GuidanceSearchModel
{
ServiceId = serviceId
PharmacistId = pharmacistId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка рекомендааций услуги id ={ Id}", serviceId);
_logger.LogError(ex, "Ошибка получения списка рекомендааций пользователя id ={ Id}", pharmacistId);
throw;
}
}

View File

@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicRestApi.Controllers
{
@ -28,7 +29,7 @@ namespace VetClinicRestApi.Controllers
if (elem == null)
return null;
var res = Tuple.Create(elem, elem.MedicineAnimals.Select(x => x.Value.AnimalName).ToList());
res.Item1.MedicineAnimals = null;
res.Item1.MedicineAnimals = null!;
return res;
}
catch (Exception ex)
@ -38,13 +39,17 @@ namespace VetClinicRestApi.Controllers
}
}
[HttpGet]
public List<MedicineViewModel>? GetMedicines(int pharmacistId)
public List<MedicineViewModel>? GetMedicines(int? pharmacistId = null)
{
try
{
var res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
List<MedicineViewModel> res;
if (!pharmacistId.HasValue)
res = _medicine.ReadList(null);
else
res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId });
foreach (var medicine in res)
medicine.MedicineAnimals = null;
medicine.MedicineAnimals = null!;
return res;
}
catch (Exception ex)

View File

@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicRestApi.Controllers
{
@ -27,7 +28,9 @@ namespace VetClinicRestApi.Controllers
var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.ServiceMedicines.Select(x => x.Value.MedicineName).ToList());
var res = Tuple.Create(elem, elem.ServiceMedicines.Select(x => x.Value.MedicineName).ToList());
res.Item1.ServiceMedicines = null!;
return res;
}
catch (Exception ex)
{
@ -36,11 +39,18 @@ namespace VetClinicRestApi.Controllers
}
}
[HttpGet]
public List<ServiceViewModel> GetServices(int pharmacistId)
public List<ServiceViewModel> GetServices(int? pharmacistId = null)
{
try
{
return _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId });
List<ServiceViewModel> res;
if (!pharmacistId.HasValue)
res = _service.ReadList(null);
else
res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId });
foreach (var service in res)
service.ServiceMedicines = null;
return res;
}
catch (Exception ex)
{
@ -67,7 +77,6 @@ namespace VetClinicRestApi.Controllers
{
try
{
model.ServiceMedicines = null!;
return _service.Update(model);
}
catch (Exception ex)

View File

@ -21,20 +21,36 @@ namespace VetClinicRestApi.Controllers
_logger = logger;
_vaccination = vaccination;
}
[HttpGet]
public List<VaccinationViewModel>? GetVaccinations(int animalId)
public VaccinationViewModel GetVaccination(int vaccinationId)
{
try
{
var elem = _vaccination.ReadElement(new VaccinationSearchModel { Id = vaccinationId });
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения прививки по id={Id}", vaccinationId);
throw;
}
}
[HttpGet]
public List<VaccinationViewModel>? GetVaccinations(int? adminld)
{
try
{
if (!adminld.HasValue)
return _vaccination.ReadList(null);
return _vaccination.ReadList(new VaccinationSearchModel
{
AnimalId = animalId
AdminId = adminld
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка привиовк животного id ={ Id}", animalId);
_logger.LogError(ex, "Ошибка получения списка прививок пользователя id ={ Id}", adminld);
throw;
}
}

View File

@ -39,18 +39,22 @@ namespace VetClinicRestApi.Controllers
}
}
[HttpGet]
public List<VisitViewModel> GetVisits(int adminId)
public List<VisitViewModel> GetVisits(int? adminId = null)
{
try
{
var res = _visit.ReadList(new VisitSearchModel { AdminId = adminId });
List<VisitViewModel> res;
if (!adminId.HasValue)
res = _visit.ReadList(null);
else
res = _visit.ReadList(new VisitSearchModel { AdminId = adminId });
foreach (var visit in res)
visit.ServiceVisits = null;
visit.ServiceVisits = null!;
return res;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка животного");
_logger.LogError(ex, "Ошибка получения списка визитов");
throw;
}
}