From 904264de3d237a80fc31848d0b5c8d03d5c9eb21 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Mon, 29 Apr 2024 22:29:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VetClinic/PharmacistApp/Controllers/HomeController.cs | 4 ++-- VetClinic/VetClinicDataBaseImplement/Models/Animal.cs | 8 ++++++-- VetClinic/VetClinicDataBaseImplement/Models/Visit.cs | 6 +++++- VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs | 4 ++-- .../VetClinicRestApi/Controllers/GuidanceController.cs | 2 -- .../VetClinicRestApi/Controllers/VaccinationController.cs | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index a149f3c..79aeded 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -275,7 +275,7 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin Dictionary a = new Dictionary(); foreach (int animal in animals) { - a.Add(animal, new AnimalSearchModel { Id = animal } as IAnimalModel); + a.Add(animal, new AnimalBindingModel { Id = animal } as IAnimalModel); } APIPharmacist.PostRequest("api/medicine/updatemedicine?isconnection=true", new MedicineBindingModel { @@ -376,7 +376,7 @@ View(APIPharmacist.GetRequest>($"api/service/getservices? Dictionary a = new Dictionary(); foreach (int medicine in medicines) { - a.Add(medicine, new AnimalSearchModel { Id = medicine } as IMedicineModel); + a.Add(medicine, new MedicineBindingModel { Id = medicine } as IMedicineModel); } APIPharmacist.PostRequest("api/service/createservice", new ServiceBindingModel diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs index 8221517..5439f72 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs @@ -93,10 +93,14 @@ namespace VetClinicDataBaseImplement.Models { var visitAnimals = context.VisitAnimals.Where(rec => rec.AnimalId == model.Id).ToList(); if (visitAnimals != null) - { // удалили те, которых нет в модели + { context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.VisitId))); context.SaveChanges(); - + foreach (var visit in visitAnimals) + { + model.VisitAnimals.Remove(visit.VisitId); + } + context.SaveChanges(); } var animal = context.Animals.First(x => x.Id == Id); foreach (var pc in model.VisitAnimals) diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs b/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs index 0741d33..cafd660 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Visit.cs @@ -95,7 +95,11 @@ namespace VetClinicDataBaseImplement.Models { // удалили те, которых нет в модели context.ServiceVisits.RemoveRange(serviceVisits.Where(rec => !model.ServiceVisits.ContainsKey(rec.ServiceId))); context.SaveChanges(); - + foreach (var service in serviceVisits) + { + model.ServiceVisits.Remove(service.ServiceId); + } + context.SaveChanges(); } var visit = context.Visits.First(x => x.Id == Id); foreach (var pc in model.ServiceVisits) diff --git a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs index 1e5c2f9..3dd7b53 100644 --- a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs +++ b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs @@ -29,7 +29,7 @@ namespace VetClinicRestApi.Controllers if (elem == null) return null; var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.NameVisit).ToList()); - res.Item1.VisitAnimals = null; + res.Item1.VisitAnimals = null!; return res; } catch (Exception ex) @@ -46,7 +46,7 @@ namespace VetClinicRestApi.Controllers { var res = _animal.ReadList(new AnimalSearchModel { AdminId = adminId }); foreach (var animal in res) - animal.VisitAnimals = null; + animal.VisitAnimals = null!; return res; } catch (Exception ex) diff --git a/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs index 9259487..d2f2833 100644 --- a/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs @@ -27,8 +27,6 @@ namespace VetClinicRestApi.Controllers try { var elem = _guidance.ReadElement(new GuidanceSearchModel { Id = guidanceId }); - if (elem == null) - return null; return elem; } catch (Exception ex) diff --git a/VetClinic/VetClinicRestApi/Controllers/VaccinationController.cs b/VetClinic/VetClinicRestApi/Controllers/VaccinationController.cs index 4cb75c7..f87ff8e 100644 --- a/VetClinic/VetClinicRestApi/Controllers/VaccinationController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/VaccinationController.cs @@ -23,10 +23,12 @@ namespace VetClinicRestApi.Controllers } [HttpGet] - public List? GetVaccinations(int animalId) + public List? GetVaccinations(int? animalId) { try { + if (!animalId.HasValue) + return _vaccination.ReadList(null); return _vaccination.ReadList(new VaccinationSearchModel { AnimalId = animalId