From 915a947704e2a2381be0d3dcfd987a4c36985df7 Mon Sep 17 00:00:00 2001 From: goblinrf Date: Fri, 26 Apr 2024 20:38:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=BE=D0=B2=D1=83?= =?UTF-8?q?=D1=8E=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 2 +- .../BindingModels/AnimalBindingModel.cs | 3 - .../SearchModels/AnimalSearchModel.cs | 4 - .../ViewModels/AnimalViewModel.cs | 4 +- .../Implements/AnimalStorage.cs | 13 --- .../Models/Animal.cs | 92 +------------------ .../Models/Vaccination.cs | 4 +- .../Models/IAnimalModel.cs | 3 - .../VetClinicRestApi/VetClinicRestApi.csproj | 1 - 9 files changed, 7 insertions(+), 119 deletions(-) diff --git a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs index 97c4d2d..b07b269 100644 --- a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs +++ b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs @@ -23,7 +23,7 @@ namespace VetClinicAdminApp.Controllers return Redirect("~/Home/Enter"); } - return View(APIAdmin.GetRequest>($"api/main/getorders?clientId={APIAdmin.Admin.Id}")); + return View(APIAdmin.GetRequest>($"api/main/getorders?visitId={APIAdmin.Admin.Id}")); } [HttpGet] diff --git a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs index 5515709..e7e48eb 100644 --- a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs @@ -11,10 +11,7 @@ namespace VetClinicContracts.BindingModels { public int Id { get; set; } public int AdminId { get; set; } - public int VaccinationId { get; set; } - public Dictionary VisitAnimals { get; set; } = new(); - public Dictionary MedicineAnimals { get; set; } = new(); public string AnimalName { get; set; } = string.Empty; public string? Family { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs index aabd0bb..161b126 100644 --- a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs @@ -11,10 +11,6 @@ namespace VetClinicContracts.SearchModels { public int? Id { get; set; } public int? AdminId { get; set; } - - public Dictionary Visits { get; set; } = new(); - public Dictionary Medicines { get; set; } = new(); - public string? AnimalName { get; set; } public string? Family { get; set; } diff --git a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs index a244d0c..2185243 100644 --- a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs @@ -12,9 +12,7 @@ namespace VetClinicContracts.ViewModels { public int Id { get; set; } public int AdminId { get; set; } - public int VaccinationId { get; set; } - public Dictionary VisitAnimals { get; set; } = new(); - public Dictionary MedicineAnimals { get; set; } = new(); + [DisplayName("Имя животного")] public string AnimalName { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs index 4c72d69..51cae3c 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/AnimalStorage.cs @@ -15,10 +15,7 @@ namespace VetClinicBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Animals - .Include(x => x.Vaccinations) .Include(x => x.Admin) - .Include(x => x.Visits) - .ThenInclude(x => x.Visit) .Select(x => x.GetViewModel) .ToList(); } @@ -32,9 +29,6 @@ namespace VetClinicBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Animals .Include(x => x.Admin) - .Include(x => x.Vaccinations) - .Include(x => x.Visits) - .ThenInclude(x => x.Visit) .Where(x => x.AnimalName.Contains(model.AnimalName)) .ToList() .Select(x => x.GetViewModel).ToList(); @@ -48,9 +42,6 @@ namespace VetClinicBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Animals .Include(x => x.Admin) - .Include(x => x.Vaccinations) - .Include(x => x.Visits) - .ThenInclude(x => x.Visit) .Include(x => x.Vaccinations) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.AnimalName) && x.AnimalName == model.AnimalName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } @@ -80,7 +71,6 @@ namespace VetClinicBaseImplement.Implements } animal.Update(model); context.SaveChanges(); - animal.UpdateVisits(context, model); transaction.Commit(); return animal.GetViewModel; } @@ -94,14 +84,11 @@ namespace VetClinicBaseImplement.Implements { using var context = new VetClinicDatabase(); var element = context.Animals - .Include(x => x.Visits) - .ThenInclude(x => x.Visit) .Include(x => x.Vaccinations) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.Animals.Remove(element); context.SaveChanges(); return element.GetViewModel; diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs index db49a49..b6ab1dc 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Animal.cs @@ -18,13 +18,7 @@ namespace VetClinicDataBaseImplement.Models public int Id { get; set; } [Required] public int AdminId { get; set; } - [Required] - public int VaccinationId { get; set; } - [Required] - public Dictionary? _visitAnimals = null; - [Required] - public Dictionary? _medicineAnimals = null; [Required] public string AnimalName { get; set; } = string.Empty; @@ -43,32 +37,7 @@ namespace VetClinicDataBaseImplement.Models [ForeignKey("AnimalId")] public virtual List Medicines { get; set; } = new(); - [NotMapped] - public Dictionary VisitAnimals - { - get - { - if (_visitAnimals == null) - { - _visitAnimals = Visits.ToDictionary(recPC => recPC.VisitId, recPC => - recPC.Visit as IVisitModel); - } - return _visitAnimals; - } - } - [NotMapped] - public Dictionary MedicineAnimals - { - get - { - if (_medicineAnimals == null) - { - _medicineAnimals = Medicines.ToDictionary(recPC => recPC.MedicineId, recPC => - recPC.Medicine as IMedicineModel); - } - return _medicineAnimals; - } - } + public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model) { if (model == null) @@ -79,18 +48,9 @@ namespace VetClinicDataBaseImplement.Models { Id = model.Id, AdminId = model.AdminId, - VaccinationId = model.VaccinationId, AnimalName = model.AnimalName, Family = model.Family, - Visits = model.VisitAnimals.Select(x => new VisitAnimal - { - Visit = context.Visits.First(y => y.Id == x.Key) - }).ToList(), - Medicines = model.MedicineAnimals.Select(x => new MedicineAnimal - { - Medicine = context.Medicines.First(y => y.Id == x.Key) - }).ToList(), - + }; } public void Update(AnimalBindingModel? model) @@ -105,57 +65,11 @@ namespace VetClinicDataBaseImplement.Models public AnimalViewModel GetViewModel => new() { Id = Id, - VisitAnimals = VisitAnimals, AdminId = AdminId, - VaccinationId = VaccinationId, AnimalName = AnimalName, - MedicineAnimals = MedicineAnimals, Family = Family }; - public void UpdateVisits(VetClinicDatabase context, AnimalBindingModel model) - { - 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(); - - } - var animal = context.Animals.First(x => x.Id == Id); - foreach (var pc in model.VisitAnimals) - { - context.VisitAnimals.Add(new VisitAnimal - { - Animal = animal, - Visit = context.Visits.First(x => x.Id == pc.Key), - - }); - context.SaveChanges(); - } - _visitAnimals = null; - } - public void UpdateMedicines(VetClinicDatabase context, AnimalBindingModel model) - { - var medicineAnimals = context.MedicineAnimals.Where(rec => rec.AnimalId == model.Id).ToList(); - if (medicineAnimals != null) - { // удалили те, которых нет в модели - context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec => !model.MedicineAnimals.ContainsKey(rec.MedicineId))); - context.SaveChanges(); - - } - var animal = context.Animals.First(x => x.Id == Id); - foreach (var pc in model.VisitAnimals) - { - context.MedicineAnimals.Add(new MedicineAnimal - { - Animal = animal, - Medicine = context.Medicines.First(x => x.Id == pc.Key), - - }); - context.SaveChanges(); - } - _medicineAnimals = null; - } + } } diff --git a/VetClinic/VetClinicDataBaseImplement/Models/Vaccination.cs b/VetClinic/VetClinicDataBaseImplement/Models/Vaccination.cs index 9186a80..506a9ba 100644 --- a/VetClinic/VetClinicDataBaseImplement/Models/Vaccination.cs +++ b/VetClinic/VetClinicDataBaseImplement/Models/Vaccination.cs @@ -37,7 +37,7 @@ namespace VetClinicDataBaseImplement.Models NameVaccination = model.NameVaccination, CostVaccination = model.CostVaccination, DateStamp = model.DateStamp, - Animal = context.Animals.FirstOrDefault(x => x.Id == model.AnimalId), + }; } @@ -52,7 +52,7 @@ namespace VetClinicDataBaseImplement.Models DateStamp = model.DateStamp; } - + public VaccinationViewModel GetViewModel => new() { AnimalId = AnimalId, diff --git a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs index 6484cc5..7882938 100644 --- a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs @@ -9,9 +9,6 @@ namespace VetClinicDataModels.Models public interface IAnimalModel : IId { int AdminId { get; } - Dictionary VisitAnimals { get; } - - Dictionary MedicineAnimals { get; } string AnimalName { get; } string? Family { get; } } diff --git a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj index 64d63a7..52c3669 100644 --- a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj +++ b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj @@ -16,7 +16,6 @@ -