diff --git a/VeterinaryView/VeterinaryContracts/StorageContracts/IMedicationStorage.cs b/VeterinaryView/VeterinaryContracts/StorageContracts/IMedicationStorage.cs index 65bae8e..dafe501 100644 --- a/VeterinaryView/VeterinaryContracts/StorageContracts/IMedicationStorage.cs +++ b/VeterinaryView/VeterinaryContracts/StorageContracts/IMedicationStorage.cs @@ -13,10 +13,11 @@ namespace VeterinaryContracts.StorageContracts { List GetFullList(); List GetFilteredList(MedicationSearchModel model); - List>>>> GetReportInfo(ListPurchasesSearchModel model); MedicationViewModel? GetElement(MedicationSearchModel model); MedicationViewModel? Insert(MedicationBindingModel model); MedicationViewModel? Update(MedicationBindingModel model); MedicationViewModel? Delete(MedicationBindingModel model); + List GetReportMedicationPurchasesList(ListPurchasesSearchModel model); + } } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs index ecb62af..464841d 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/MedicationStorage.cs @@ -83,7 +83,7 @@ namespace VeterinaryDatabaseImplement.Implements return null; } - public List>>>> GetReportInfo(ListPurchasesSearchModel model) + public List GetReportMedicationPurchasesList(ListPurchasesSearchModel model) { if (model.medicationsIds == null) { @@ -91,14 +91,14 @@ namespace VeterinaryDatabaseImplement.Implements } using var context = new VeterinaryDatabase(); return context.Medications - .Where(pet => model.medicationsIds.Contains(pet.Id)) - .Select(pet => new Tuple>>>(pet.GetViewModel, - context.VisitPets.Include(visit => visit.Visit) - .Include(visit => visit.Pet).Where(visit => pet.Id == visit.PetId). - Select(visit => new Tuple>(visit.Visit.GetViewModel, - context.Services.Include(x => x.Visits).Where(x => x.MedicineId == visit.Medicine.Id). - Select(x => x.Animal.GetViewModel).ToList())).ToList())).ToList(); - + .Where(medication => model.medicationsIds == null || model.medicationsIds.Contains(medication.Id)) + .Select(medication => new ReportPurchaseMedicationViewModel() + { + MedicationName = medication.MedicationName, + Purchases = context.Purchases.Include(purchase => purchase.Drug).ThenInclude(drug => drug.Medications) + .Where(purchase => purchase.Drug != null && purchase.Drug.Medications.Select(x => x.MedicationId).ToList().Contains(medication.Id)) + .Select(purchase => purchase.GetViewModel).ToList() + }).ToList(); } } }