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