From 51b0308ea8229b1bd2fb7ff5cde67860efce9020 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sun, 28 Apr 2024 15:11:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 114 +++++++++++++----- .../Views/Home/CreateMedicine.cshtml | 11 -- .../PharmacistApp/Views/Home/Index.cshtml | 1 + .../Views/Home/MedicineAnimals.cshtml | 65 ++++++++++ .../Views/Home/UpdateMedicine.cshtml | 15 --- .../Implements/MedicineStorage.cs | 3 +- .../Controllers/MedicineController.cs | 4 +- 7 files changed, 156 insertions(+), 57 deletions(-) create mode 100644 VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 68ce4cc..31e494c 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -1,6 +1,8 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using NPOI.SS.UserModel; using PharmacistApp.Models; using System.Diagnostics; +using System.Text; using VetClinicContracts.BindingModels; using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; @@ -45,12 +47,12 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception(" email, "); + throw new Exception("Введите email, пароль и ФИО"); } APIPharmacist.PostRequest("api/pharmacist/updatedata", new PharmacistBindingModel @@ -77,13 +79,13 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { - throw new Exception(" email "); + throw new Exception("Введите email и пароль"); } APIPharmacist.Pharmacist = APIPharmacist.GetRequest($"api/pharmacist/login?email={email}&password={password}"); if (APIPharmacist.Pharmacist == null) { - throw new Exception(" /"); + throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } @@ -98,7 +100,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { - throw new Exception(" , "); + throw new Exception("Введите логин, пароль и ФИО"); } APIPharmacist.PostRequest("api/pharmacist/register", new PharmacistBindingModel @@ -117,20 +119,25 @@ 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, string price, List animals) + public void CreateMedicine(string name, string price) { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + 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 { @@ -138,24 +145,18 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } catch(Exception ex) { - throw new Exception(" "); + 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); + throw new Exception("Ошибка в введенных данных"); } APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel { MedicineName = name, Price = Math.Round(_price, 2), - PharmacistId = APIPharmacist.Pharmacist.Id, - MedicineAnimals = a + PharmacistId = APIPharmacist.Pharmacist.Id }) ; Response.Redirect("Index"); } @@ -175,7 +176,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } APIPharmacist.PostRequest("api/medicine/deletemedicine", new MedicineBindingModel { @@ -191,18 +192,23 @@ 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, string price, - List animals) + public void UpdateMedicine(int medicine, string name, string price) { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + 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 { @@ -210,18 +216,68 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } catch (Exception ex) { - throw new Exception(" "); + throw new Exception("Ошибка в введенных данных"); } if (string.IsNullOrEmpty(name) || _price <= 0) { - throw new Exception(" "); + throw new Exception("Ошибка в введенных данных"); + } + APIPharmacist.PostRequest("api/medicine/updatemedicine?isconnection=false", new MedicineBindingModel + { + Id = medicine, + MedicineName = name, + Price = Math.Round(_price, 2), + PharmacistId = APIPharmacist.Pharmacist.Id, + }); + Response.Redirect("Index"); + } + + public IActionResult MedicineAnimals() + { + if (APIPharmacist.Pharmacist == null) + { + 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 MedicineAnimals(int medicine, string name, string price, + List animals) + { + 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 a = new Dictionary(); foreach (int animal in animals) { a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel); } - APIPharmacist.PostRequest("api/medicine/updatemedicine", new MedicineBindingModel + APIPharmacist.PostRequest("api/medicine/updatemedicine?isconnection=true", new MedicineBindingModel { Id = medicine, MedicineName = name, @@ -243,7 +299,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } var result = APIPharmacist.GetRequest>>($"api/medicine/getmedicine?medicineid={medicineId}"); if (result == null) @@ -259,7 +315,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { if (APIPharmacist.Pharmacist == null) { - throw new Exception(" ? "); + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } var result = APIPharmacist.GetRequest($"api/animal/getanimal?animalid={animalId}"); return result; diff --git a/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml index 29a5a91..9a31add 100644 --- a/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/CreateMedicine.cshtml @@ -18,17 +18,6 @@ -
-
Животные:
-
- -
-
diff --git a/VetClinic/PharmacistApp/Views/Home/Index.cshtml b/VetClinic/PharmacistApp/Views/Home/Index.cshtml index c22cc21..2489fd4 100644 --- a/VetClinic/PharmacistApp/Views/Home/Index.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/Index.cshtml @@ -17,6 +17,7 @@ Создать медикамент Обновить медикамент Удалить медикамент + Связать медикаменты и животных

diff --git a/VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml b/VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml new file mode 100644 index 0000000..d7054a9 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/MedicineAnimals.cshtml @@ -0,0 +1,65 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "MedicineAnimals"; +} + +
+

Связывание медикамента и животного

+
+ +
+
Медикамент:
+
+ +
+
+ + +
+
Животные:
+
+ +
+
+
+
+
+
+ + +@section Scripts +{ + +} \ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml index d1ba160..e4878ed 100644 --- a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml @@ -22,17 +22,6 @@
Цена:
-
-
Животные:
-
- -
-
@@ -54,10 +43,6 @@ console.log(result.item2); $('#name').val(result.item1.medicineName); $('#price').val(result.item1.price); - $.map(result.item2, function ( n ) { - console.log("#" + n); - $("#" + n).attr("selected", "selected") - }); } }); diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs index 4b8b2d7..f88e57e 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs @@ -77,7 +77,8 @@ namespace VetClinicDataBaseImplement.Implements } medicine.Update(model); context.SaveChanges(); - medicine.UpdateAnimals(context, model); + if(model.MedicineAnimals != null) + medicine.UpdateAnimals(context, model); transaction.Commit(); return medicine.GetViewModel; } diff --git a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs index ee75164..2591766 100644 --- a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs @@ -68,10 +68,12 @@ namespace VetClinicRestApi.Controllers } [HttpPost] - public bool UpdateMedicine(MedicineBindingModel model) + public bool UpdateMedicine(bool isConnection, MedicineBindingModel model) { try { + if (!isConnection) + model.MedicineAnimals = null!; return _medicine.Update(model); } catch (Exception ex)