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