From ba4fba5e1ad2793a6a676489a39432a5e5f82fde Mon Sep 17 00:00:00 2001 From: frog24 Date: Tue, 28 May 2024 18:38:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20=D0=BA?= =?UTF-8?q?=D1=80=D1=83=D0=B4=20=D0=B4=D0=BB=D1=8F=20=D0=B6=D0=B8=D0=B2?= =?UTF-8?q?=D0=BE=D1=82=D0=BD=D1=8B=D1=85=20(=D1=8F=20=D1=81=D0=B0=D0=BC?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BA=20=D0=B6=D0=B8=D0=B2=D0=BE=D1=82=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D1=83=D0=B6=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClientApp/Controllers/HomeController.cs | 85 ++++++++++++++++++- .../ClientApp/Views/Home/CreateAnimal.cshtml | 6 +- .../ClientApp/Views/Home/IndexAnimal.cshtml | 14 ++- .../ClientApp/Views/Home/UpdateAnimal.cshtml | 55 ++++++++++++ 4 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 Vetclinic/ClientApp/Views/Home/UpdateAnimal.cshtml diff --git a/Vetclinic/ClientApp/Controllers/HomeController.cs b/Vetclinic/ClientApp/Controllers/HomeController.cs index cd024b2..87040b3 100644 --- a/Vetclinic/ClientApp/Controllers/HomeController.cs +++ b/Vetclinic/ClientApp/Controllers/HomeController.cs @@ -69,7 +69,8 @@ namespace ClientApp.Controllers Response.Redirect("Enter"); return; } - public IActionResult IndexAnimal() + //=================ЖИВОТНЫЕ================= + public IActionResult IndexAnimal() { if (APIClient.Client == null) { @@ -79,8 +80,90 @@ namespace ClientApp.Controllers } public IActionResult CreateAnimal() { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpPost] + public void CreateAnimal(string name, int age, string species) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || age <= 0 || string.IsNullOrEmpty(species)) + { + throw new Exception("Ошибка в введённых данных"); + } + APIClient.PostRequest("api/animal/createanimal", new AnimalBindingModel + { + AnimalName = name, + Age = age, + Species = species, + ClientId = APIClient.Client.Id + }); + Response.Redirect("Index"); + } + public IActionResult UpdateAnimal() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Animals = APIClient.GetRequest>($"api/animal/getanimals?clientid={APIClient.Client.Id}"); return View(); } + [HttpPost] + public void UpdateAnimal(int pet, string name, int age, string species) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || age <= 0 || string.IsNullOrEmpty(species)) + { + throw new Exception("Ошибка введённых данных"); + } + APIClient.PostRequest("api/animal/updateanimal", new AnimalViewModel + { + Id = pet, + AnimalName = name, + Age = age, + Species = species, + }); + Response.Redirect("Index"); + } + [HttpGet] + public Tuple? GetAnimal(int animalId) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIClient.GetRequest>($"api/animal/getanimal?animalId={animalId}"); + if (result == null) + { + return default; + } + return result; + } + [HttpPost] + public void IndexAnimal(int id) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/animal/deleteanimal", new AnimalBindingModel + { + Id = id + }); + Response.Redirect("Index"); + } + + //=================ПОСЕЩЕНИЯ================= public IActionResult IndexDoctorVisit() { return View(new List()); diff --git a/Vetclinic/ClientApp/Views/Home/CreateAnimal.cshtml b/Vetclinic/ClientApp/Views/Home/CreateAnimal.cshtml index 5b913fc..e4ccf53 100644 --- a/Vetclinic/ClientApp/Views/Home/CreateAnimal.cshtml +++ b/Vetclinic/ClientApp/Views/Home/CreateAnimal.cshtml @@ -7,15 +7,15 @@
Кличка:
-
+
Вид:
-
+
Возраст:
-
+
diff --git a/Vetclinic/ClientApp/Views/Home/IndexAnimal.cshtml b/Vetclinic/ClientApp/Views/Home/IndexAnimal.cshtml index f8c5b58..eb8a899 100644 --- a/Vetclinic/ClientApp/Views/Home/IndexAnimal.cshtml +++ b/Vetclinic/ClientApp/Views/Home/IndexAnimal.cshtml @@ -20,6 +20,7 @@ }

Создать животное + Обновить животное

@@ -37,10 +38,7 @@ Возраст - @@ -61,10 +59,10 @@ @Html.DisplayFor(modelItem => item.Age) - } diff --git a/Vetclinic/ClientApp/Views/Home/UpdateAnimal.cshtml b/Vetclinic/ClientApp/Views/Home/UpdateAnimal.cshtml new file mode 100644 index 0000000..f88eed4 --- /dev/null +++ b/Vetclinic/ClientApp/Views/Home/UpdateAnimal.cshtml @@ -0,0 +1,55 @@ +@{ + ViewData["Title"] = "UpdateAnimal"; +} +
+

Редактирование животного

+
+ +
+
Животное:
+
+ +
+
+
+
Кличка:
+
+
+
+
Вид:
+
+
+
+
Возраст:
+
+
+
+
+
+
+ + +@section Scripts + { + +}
- Изменить деталь - - Удалить деталь + Удалить животное
- Изменить - - Удалить + + + +