From ea42dc9fc4179f4aae0493e0b40983b727d7adba Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sat, 27 Apr 2024 17:03:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=90=D0=93=D0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 30 +++++++++++++++---- .../Views/Home/UpdateMedicine.cshtml | 2 +- .../Models/Medicine.cs | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 85468fe..96b8910 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -125,13 +125,22 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin [HttpPost] - public void CreateMedicine(string name, int price, List animals) + 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("Ошибка в введенных данных"); } @@ -144,7 +153,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin APIPharmacist.PostRequest("api/medicine/createmedicine", new MedicineBindingModel { MedicineName = name, - Price = price, + Price = Math.Round(_price, 2), PharmacistId = APIPharmacist.Pharmacist.Id, MedicineAnimals = a }) ; @@ -187,14 +196,23 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } [HttpPost] - public void UpdateMedicine(int medicine, string name, int price, + 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("Ошибка в введенных данных"); } @@ -207,7 +225,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin { Id = medicine, MedicineName = name, - Price = price, + Price = Math.Round(_price, 2), PharmacistId = APIPharmacist.Pharmacist.Id, MedicineAnimals = a }); diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml index 6c5a1b0..eb1724a 100644 --- a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml @@ -20,7 +20,7 @@
Цена:
-
+
Животные:
diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Medicine.cs b/VetClinic/VetClinicDataBaseImplement/Models/Medicine.cs index 5cc4e34..88b9b6f 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Medicine.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Medicine.cs @@ -80,7 +80,7 @@ namespace VetClinicDataBaseImplement.Models if (medicineAnimals != null && medicineAnimals.Count > 0) { context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec -=> !model.MedicineAnimals.ContainsKey(rec.AnimalId))); +=> !model.MedicineAnimals.ContainsKey(rec.MedicineId))); context.SaveChanges(); }