using SchoolBusinessLogics.OfficePackage; using SchoolContracts.BindingModels; using SchoolContracts.BusinessLogicContracts; using SchoolContracts.StoragesContracts; namespace SchoolBusinessLogics.BusinessLogics; public class ReportLogic : IReportLogic { private readonly AbstractSaveToWord _saveToWord; private readonly IDisciplineStorage _disciplineStorage; private readonly IStudentStorage _studentStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly IAccountStorage _accountStorage; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(AbstractSaveToWord saveToWord, IDisciplineStorage disciplineStorage, AbstractSaveToExcel saveToExcel, IAccountStorage accountStorage, AbstractSaveToPdf saveToPdf, IStudentStorage studentStorage) { _accountStorage = accountStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _disciplineStorage = disciplineStorage; _saveToPdf = saveToPdf; _studentStorage = studentStorage; } public void SaveDisciplinesToWord(ReportBindingModel option) { _saveToWord.CreateDoc(new() { FileName = option.FileName, Stream = option.Stream, Title = "Список дисциплин вместе с клиентами", ReportObjects = _disciplineStorage.GetFilteredList(new() { ClientsIds = option.Ids?.ToList() }) .Select(x => (object)x).ToList(), }); } public void SaveDisciplinesToExcel(ReportBindingModel option) { var ids = option.Ids?.ToList(); _saveToExcel.CreateReportDisciplines(new() { FileName = option.FileName, Stream = option.Stream, Title = "Список дисциплин вместе с клиентами", ReportObjects = _disciplineStorage.GetFilteredList(new() { StudentsIds = ids }) .Select(x => (object)x).ToList(), Headers = new() { "Дисциплина", "Дата создания", "Дата прохождения" } }); } public void SendAccountsToEmail(ReportDateRangeBindingModel option, string email) { var accounts = _accountStorage.GetFilteredList(new() { DateFrom = option.DateFrom, DateTo = option.DateTo, }); option.Stream = new MemoryStream(); _saveToPdf.CreateDocForAccounts(new() { DateFrom = option.DateFrom, DateTo = option.DateTo, Stream = option.Stream, Title = "Данные по клиентом с накопительными счетами за период", ReportObjects = accounts.Select(x => (object)x).ToList() }); } public void SaveClientsToWord(ReportBindingModel option) { _saveToWord.CreateDoc(new() { FileName = option.FileName, Stream = option.Stream, Title = "Список клиентов вместе с их дисциплинами", ReportObjects = _clientStorage.GetFilteredList(new() { DisciplinesIds = option.Ids?.ToList() }) .Select(x => (object)x).ToList(), }); } public void SaveClientsToExcel(ReportBindingModel option) { _saveToExcel.CreateReportClients(new() { FileName = option.FileName, Stream = option.Stream, Title = "Список клиентов вместе с их дисциплинами", ReportObjects = _clientStorage.GetFilteredList(new() { DisciplinesIds = option.Ids?.ToList() }) .Select(x => (object)x).ToList(), Headers = new() { "Клиент", "Дата", "Дисциплина", "Курс" } }); } public void SendRequirementsToEmail(ReportDateRangeBindingModel option, string email) { var dicscipline = _disciplineStorage.GetFilteredList(new() { DateFrom = option.DateFrom, DateTo = option.DateTo, }); option.Stream = new MemoryStream(); _saveToPdf.CreateDocForDisciplines(new() { DateFrom = option.DateFrom, DateTo = option.DateTo, Stream = option.Stream, Title = "Данные по дисциплинам с требованиями за период", ReportObjects = dicscipline.Select(x => (object)x).ToList() }); } }