using DocumentFormat.OpenXml.EMMA; using DocumentFormat.OpenXml.Presentation; using VeterinaryBusinessLogic.OfficePackage; using VeterinaryBusinessLogic.OfficePackage.HelperModels; using VeterinaryContracts.BindingModels; using VeterinaryContracts.BusinessLogicContracts; using VeterinaryContracts.SearchModels; using VeterinaryContracts.StorageContracts; using VeterinaryContracts.ViewModels; using VeterinaryDatabaseImplement.Implements; namespace VeterinaryBusinessLogic.BusinessLogic { public class ReportLogicOwner : IReportLogicOwner { private readonly IPetStorage _petStorage; private readonly AbstractSaveToExcelOwner _saveToExcel; private readonly AbstractSaveToWordOwner _saveToWord; private readonly AbstractSaveToPdfOwner _saveToPdf; public ReportLogicOwner(IPetStorage petStorage, AbstractSaveToExcelOwner saveToExcel, AbstractSaveToWordOwner saveToWord, AbstractSaveToPdfOwner saveToPdf) { _petStorage = petStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } public List GetPetServices(ReportServicesBindingModel model) { //List ans = new(); //List response = _serviceStorage.GetReportServices(new ReportPetsSearchModel { servicesIds = services }); //List respons = _petStorage.GetReportServices(new ReportServicesSearchModel { petsIds = pets }); //foreach (var service in response) //{ // Dictionary counter = new(); // foreach (var visit in service.Services) // { // foreach (var pet in visit.ServiceMedications) // { // if (!counter.ContainsKey(pet.Id)) // counter.Add(pet.Id, (pet, 1)); // else // { // counter[pet.Id] = (counter[pet.Id].Item1, counter[pet.Id].Item2 + 1); // } // } // } // List res = new(); // foreach (var cnt in counter) // { // if (cnt.Value.Item2 != service.Count) // continue; // res.Add(cnt.Value.Item1); // } // ans.Add(new ReportPetsViewModel // { // ServiceName = service.Item1.ServiceName, // Animals = res // }); //} //return ans; return _petStorage.GetReportServices(new() { petsIds = model.Pets }); } public List GetVisitsDrugs(ReportVisitsDrugsBindingModel model) { return _petStorage.GetReportVisitsDrugs(new() { DateFrom = model.DateFrom, DateTo = model.DateTo }); } public void SaveServicesToExcelFile(ReportServicesBindingModel model) { _saveToExcel.CreateReport(new ExcelInfoOwner { FileName = model.FileName, Title = "Список услуг по животным", PetServices = GetPetServices(model) }); } public void SaveServicesToWordFile(ReportServicesBindingModel model) { _saveToWord.CreateDoc(new WordInfoOwner { FileName = model.FileName, Title = "Список услуг по животным", PetServices = GetPetServices(model) }); } public void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Список визитов", DateFrom = model.DateFrom!, DateTo = model.DateTo!, ReportVisitsDrugs = GetVisitsDrugs(model) }); } } }