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); + } } }); };