diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 1f6273d..68ce4cc 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,27 +117,45 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { return Redirect("~/Home/Enter"); } + ViewBag.Animals = APIPharmacist.GetRequest>($"api/animal/getanimallist"); + return View(); } [HttpPost] - public void CreateMedicine(string name, int price) + public void CreateMedicine(string name, string price, List animals) { if (APIPharmacist.Pharmacist == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - if (string.IsNullOrEmpty(name) || price <= 0) + double _price; + try + { + _price = Convert.ToDouble(price); + } + catch(Exception ex) { throw new Exception("Ошибка в введенных данных"); } + if (string.IsNullOrEmpty(name) || _price <= 0) + { + 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 + Price = Math.Round(_price, 2), + PharmacistId = APIPharmacist.Pharmacist.Id, + MedicineAnimals = a }) ; Response.Redirect("Index"); } @@ -172,28 +191,43 @@ 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/getanimallist"); return View(); } [HttpPost] - public void UpdateMedicine(int medicine, string name, int price, - Dictionary medicineAnimals = null) + public void UpdateMedicine(int medicine, string name, string price, + List animals) { if (APIPharmacist.Pharmacist == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - if (string.IsNullOrEmpty(name) || price <= 0) + double _price; + try + { + _price = Convert.ToDouble(price); + } + catch (Exception ex) { throw new Exception("Ошибка в введенных данных"); } + if (string.IsNullOrEmpty(name) || _price <= 0) + { + 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, + Price = Math.Round(_price, 2), PharmacistId = APIPharmacist.Pharmacist.Id, - MedicineAnimals = medicineAnimals + MedicineAnimals = a }); Response.Redirect("Index"); } @@ -205,7 +239,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } [HttpGet] - public Tuple? GetMedicine(int medicineId) + public Tuple>? GetMedicine(int medicineId) { if (APIPharmacist.Pharmacist == null) { @@ -216,16 +250,8 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { return default; } - string table = ""; - result.Item1.MedicineAnimals.Clear(); - for (int i = 0; i < result.Item2.Count; i++) - { - var animal = result.Item2[i]; - table += ""; - table += $"{animal}"; - table += ""; - } - return Tuple.Create(result.Item1, table); + + return result; } [HttpGet] diff --git a/VetClinic/PharmacistApp/PharmacistApp.csproj b/VetClinic/PharmacistApp/PharmacistApp.csproj index fbf47ba..5a850dc 100644 --- a/VetClinic/PharmacistApp/PharmacistApp.csproj +++ b/VetClinic/PharmacistApp/PharmacistApp.csproj @@ -16,7 +16,7 @@ - + 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..d1ba160 100644 --- a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml @@ -13,9 +13,6 @@
-
- -
Название:
@@ -23,20 +20,19 @@
Цена:
-
+
+
+
+
Животные:
+
+ +
- - - - - - - - - -
- Животное -
@@ -48,16 +44,22 @@