using DocumentFormat.OpenXml.Office2021.DocumentTasks; using SchoolAgainStudyBusinessLogic.OfficePackage; using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.SearchModel; using SchoolAgainStudyContracts.StorageContracts; using SchoolAgainStudyContracts.ViewModel; using SchoolAgainStudyDataBaseImplements.Models; using SchoolAgainStudyDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SchoolAgainStudyBusinessLogic.BusinessLogic { public class ReportLogic : IReportLogic { private readonly IInterestStorage _interestStorage; private readonly IMaterialStorage _materialStorage; private readonly IProductStorage _productStorage; private readonly IDiyStorage _diyStorage; private readonly ITaskStorage _taskStorage; private readonly ILessonStorage _lessonStorage; private readonly AbstractSaveToExcelTeacher _saveToExcelTeacher; private readonly AbstractSaveToWordTeacher _saveToWordTeacher; private readonly AbstractSaveToPdfTeacher _saveToPdfTeacher; private readonly AbstractSaveToExcelStudent _saveToExcelStudent; private readonly AbstractSaveToWordStudent _saveToWordStudent; private readonly AbstractSaveToPdfStudent _saveToPdfStudent; public ReportLogic(IInterestStorage interestStorage, IMaterialStorage materialStorage, IProductStorage productStorage, IDiyStorage diyStorage, ITaskStorage taskStorage, ILessonStorage lessonStorage, AbstractSaveToExcelTeacher saveToExcelTeacher, AbstractSaveToWordTeacher saveToWordTeacher, AbstractSaveToPdfTeacher saveToPdfTeacher, AbstractSaveToExcelStudent saveToExcelStudent, AbstractSaveToWordStudent saveToWordStudent, AbstractSaveToPdfStudent saveToPdfStudent) { _interestStorage = interestStorage; _materialStorage = materialStorage; _productStorage = productStorage; _diyStorage = diyStorage; _taskStorage = taskStorage; _lessonStorage = lessonStorage; _saveToExcelTeacher = saveToExcelTeacher; _saveToWordTeacher = saveToWordTeacher; _saveToPdfTeacher = saveToPdfTeacher; _saveToExcelStudent = saveToExcelStudent; _saveToWordStudent = saveToWordStudent; _saveToPdfStudent = saveToPdfStudent; } public List GetDiyMaterial(ReportBindingModel model) { var tasks = _taskStorage.GetFilteredList(new TaskSearchModel{ TeacherId=model.TeacherId }); var diys = _diyStorage.GetFullList(); var list = new List(); foreach (MaterialViewModel material in model.Materials) { var record = new ReportDiyMaterialViewModel { Title = material.Title }; foreach(TaskViewModel task in tasks) { if (task.TaskMaterials.ContainsKey(material.Id)) { foreach(DiyViewModel diy in diys) { if (diy.TaskId == task.Id) record.Diys.Add(diy.Title); } } } list.Add(record); } return list; } public List GetInterestLesson(ReportBindingModel model) { var products = _productStorage.GetFilteredList(new ProductSearchModel { StudentId = model.StudentId }); var lessons = _lessonStorage.GetFullList(); var list = new List(); foreach(InterestViewModel interest in model.Interests) { var record = new ReportInterestLessonViewModel { Title = interest.Title }; foreach(ProductViewModel product in products) { if (product.ProductInterests.ContainsKey(interest.Id)) { foreach(LessonViewModel lesson in lessons) { if(lesson.ProductId == product.Id) { record.Lessons.Add(lesson.Title); } } } } list.Add(record); } return list; } public List GetInterests(ReportBindingModel model) { var interests = _interestStorage.GetFilteredList(new InterestSearchModel { StudentId = model.StudentId }); var products = _productStorage.GetFilteredList(new ProductSearchModel { StudentId = model.StudentId, DateFrom = model.DateFrom, DateTo = model.DateTo }); var diys = _diyStorage.GetFilteredList(new DiySearchModel { StudentId = model.StudentId, DateFrom = model.DateFrom, DateTo = model.DateTo }); var list = new List(); foreach (ProductViewModel product in products) { foreach (DiyViewModel diy in diys) { foreach (int interestProduct in product.ProductInterests.Keys) { if (diy.DiyInterests.ContainsKey(interestProduct)) { list.Add(new ReportInterestViewModel { InterestTitle = interests.FirstOrDefault(x => x.Id == interestProduct).ToString(), ProductTitle = product.Title, DateCreateProduct = product.DateCreate, DiyTitle = diy.Title, DateCreateDiy = diy.DateCreate }); } } } } return list; } public List GetLessonTask(ReportBindingModel model) { var tasks = _taskStorage.GetFilteredList(new TaskSearchModel { TeacherId = model.TeacherId, DateFrom = model.DateFrom, DateTo = model.DateTo }); var lessons = _lessonStorage.GetFilteredList(new LessonSearchModel { TeacherId = model.TeacherId, DateFrom = model.DateFrom, DateTo = model.DateTo }); var list = new List(); foreach (TaskViewModel task in tasks) { foreach(LessonViewModel lesson in lessons) { foreach (int materialTask in task.TaskMaterials.Keys) { if (lesson.LessonMaterials.ContainsKey(materialTask)) { list.Add(new ReportLessonTaskViewModel { TitleLesson = lesson.Title, TitleTask = task.Title, DateEventLesson = lesson.DateEvent, DateIssueTask = task.DateIssue }); break; } } } } return list; } public void SaveDiyMaterialToExcelFile(ReportBindingModel model) { _saveToExcelTeacher.CreateReport(new ExcelInfoTeacher { FileName = model.FileName, Title = "Список поделок по материалам", DiyMaterials = GetDiyMaterial(model) }); } public void SaveDiyMaterialToWordFile(ReportBindingModel model) { _saveToWordTeacher.CreateDoc(new WordInfoTeacher { FileName = model.FileName, Title = "Список поделок по материалам", DiyMaterials = GetDiyMaterial(model) }); } public void SaveInterestLessonToExcelFile(ReportBindingModel model) { _saveToExcelStudent.CreateReport(new ExcelInfoStudent { FileName = model.FileName, Title = "Список занятий по интресам", InterestLessons = GetInterestLesson(model) }); } public void SaveInterestLessonToWordFile(ReportBindingModel model) { _saveToWordStudent.CreateDoc(new WordInfoStudent { FileName = model.FileName, Title = "Список занятий по интресам", InterestLessons = GetInterestLesson(model) }); } public void SaveInterestsToPdfFile(ReportBindingModel model) { _saveToPdfStudent.CreateDoc(new PdfInfoStudent { FileName = model.FileName, Title = "Список интересов", DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), Interests = GetInterests(model) }); } public void SaveLessonTaskToPdfFile(ReportBindingModel model) { _saveToPdfTeacher.CreateDoc(new PdfInfoTeacher { FileName = model.FileName, Title = "Список заданий и занятий со сохожими материалами", DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), LessonTasks = GetLessonTask(model) }); } } }