From 7d8ea70e32e86990b606794cbd3f955913f3d12b Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sat, 27 Apr 2024 11:28:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B6=D0=B4=D1=83=20=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=20=D0=B6=D0=B8=D0=B2=D0=BE?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 24 +++++++++++--- .../Views/Home/CreateMedicine.cshtml | 11 +++++++ .../Views/Home/UpdateMedicine.cshtml | 33 ++++++++++--------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 1f6273d..0edecba 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using PharmacistApp.Models; using System.Diagnostics; using VetClinicContracts.BindingModels; +using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; using VetClinicDataBaseImplement.Models; using VetClinicDataModels.Models; @@ -116,13 +117,15 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { return Redirect("~/Home/Enter"); } + ViewBag.Animals = APIPharmacist.GetRequest>($"api/animal/getanimals"); + return View(); } [HttpPost] - public void CreateMedicine(string name, int price) + public void CreateMedicine(string name, int price, List animals) { if (APIPharmacist.Pharmacist == null) { @@ -132,11 +135,18 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); } + Dictionary a = new Dictionary(); + foreach (int animal in animals) + { + a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel); + } + APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel { MedicineName = name, Price = price, - PharmacistId = APIPharmacist.Pharmacist.Id + PharmacistId = APIPharmacist.Pharmacist.Id, + MedicineAnimals = a }) ; Response.Redirect("Index"); } @@ -172,12 +182,13 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin return Redirect("~/Home/Enter"); } ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}"); + ViewBag.Animals = APIPharmacist.GetRequest>($"api/animal/getanimals"); return View(); } [HttpPost] public void UpdateMedicine(int medicine, string name, int price, - Dictionary medicineAnimals = null) + List animals) { if (APIPharmacist.Pharmacist == null) { @@ -187,13 +198,18 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); } + Dictionary a = new Dictionary(); + 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 = price, PharmacistId = APIPharmacist.Pharmacist.Id, - MedicineAnimals = medicineAnimals + MedicineAnimals = a }); Response.Redirect("Index"); } diff --git a/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml index 9a31add..29a5a91 100644 --- a/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml @@ -18,6 +18,17 @@ +
+
Животные:
+
+ +
+
diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml index b389ecb..8f327cf 100644 --- a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml @@ -25,21 +25,16 @@
Цена:
- - - - - - - - - -
- Животное -
-
-
+
Животные:
+
+ +
@@ -56,7 +51,15 @@ success: function (result) { $('#name').val(result.item1.medicineName); $('#price').val(result.item1.price); - $('#table-elements').html(result.item2); + $('#animals-elements').html + @foreach (var animal in ViewBag.Animals) + { + $($"#select option[value={animal.Id}]").prop('selected', false); + } + @foreach (var animal in result.Item2) + { + $($"#select option[value={animal.id}]").prop('selected', true); + } } }); };