From eba96483b430a5c6f4d10dc0ca3cd58a74a12ac2 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Thu, 2 May 2024 18:00:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=BE=20=D0=BF=D0=B8=D0=BF=D0=B5?= =?UTF-8?q?=D1=86=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B8=D1=89=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicPharmacist.cs | 26 ++++++++++--------- .../SearchModels/ListAnimalsSearchModel.cs | 13 ++++++++++ .../StoragesContracts/IServiceStorage.cs | 2 ++ .../Implements/ServiceStorage.cs | 17 ++++++++++++ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 VetClinic/VetClinicContracts/SearchModels/ListAnimalsSearchModel.cs diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs index 7c45c75..e94c885 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs @@ -32,34 +32,36 @@ namespace VetClinicBusinessLogic.BusinessLogics public List GetServiceAnimals(List services) { + List ans = new(); - foreach(var service in services) + List>>>> response = + _serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services}); + + foreach (var service in response) { - var medicines = _medicineStorage.GetFilteredList(new MedicineSearchModel { ServiceId = service }); - Dictionary counter = new(); - foreach(var medicine in medicines) + Dictionary counter = new(); + foreach (var medicine in service.Item2) { - var animals = _animalStorage.GetFilteredList(new AnimalSearchModel { MedicineId = medicine.Id }); - foreach(var animal in animals) + foreach (var animal in medicine.Item2) { if (!counter.ContainsKey(animal.Id)) - counter.Add(animal.Id, 1); + counter.Add(animal.Id, (animal, 1)); else { - counter[animal.Id]++; + counter[animal.Id] = (counter[animal.Id].Item1, counter[animal.Id].Item2 + 1); } } } List res = new(); - foreach(var cnt in counter) + foreach (var cnt in counter) { - if (cnt.Value != medicines.Count) + if (cnt.Value.Item2 != service.Item2.Count) continue; - res.Add(_animalStorage.GetElement(new AnimalSearchModel { Id = cnt.Key })); + res.Add(cnt.Value.Item1); } ans.Add(new ListAnimalsViewModel { - ServiceName = _serviceStorage.GetElement(new ServiceSearchModel { Id = service}).ServiceName, + ServiceName = service.Item1.ServiceName, Animals = res }); } diff --git a/VetClinic/VetClinicContracts/SearchModels/ListAnimalsSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/ListAnimalsSearchModel.cs new file mode 100644 index 0000000..b692deb --- /dev/null +++ b/VetClinic/VetClinicContracts/SearchModels/ListAnimalsSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicContracts.SearchModels +{ + public class ListAnimalsSearchModel + { + public List? servicesIds { get; set; } + } +} diff --git a/VetClinic/VetClinicContracts/StoragesContracts/IServiceStorage.cs b/VetClinic/VetClinicContracts/StoragesContracts/IServiceStorage.cs index f94ac6f..7c9f75f 100644 --- a/VetClinic/VetClinicContracts/StoragesContracts/IServiceStorage.cs +++ b/VetClinic/VetClinicContracts/StoragesContracts/IServiceStorage.cs @@ -13,9 +13,11 @@ namespace VetClinicContracts.StoragesContracts { List GetFullList(); List GetFilteredList(ServiceSearchModel model); + public List>>>> GetReportInfo(ListAnimalsSearchModel model); ServiceViewModel? GetElement(ServiceSearchModel model); ServiceViewModel? Insert(ServiceBindingModel model); ServiceViewModel? Update(ServiceBindingModel model); ServiceViewModel? Delete(ServiceBindingModel model); + } } diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs index 39961dc..025f0d4 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs @@ -67,6 +67,23 @@ namespace VetClinicDataBaseImplement.Implements context.SaveChanges(); return newService.GetViewModel; } + public List>>>> GetReportInfo(ListAnimalsSearchModel model) + { + if (model.servicesIds == null) + { + return new(); + } + using var context = new VetClinicDatabase(); + return context.Services + .Where(service => model.servicesIds.Contains(service.Id)) + .Select(service => new Tuple>>>(service.GetViewModel, + context.ServiceMedicines.Include(medicine => medicine.Medicine) + .Include(medicine => medicine.Service).Where(medicine => service.Id == medicine.ServiceId). + Select(medicine => new Tuple>(medicine.Medicine.GetViewModel, + context.MedicineAnimals.Include(x => x.Animal).Where(x => x.MedicineId == medicine.Medicine.Id). + Select(x => x.Animal.GetViewModel).ToList())).ToList())).ToList(); + + } public ServiceViewModel? Update(ServiceBindingModel model) { using var context = new VetClinicDatabase();