From 117f273224a358febc595fdc27443acbaf5e08c4 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 1 May 2024 20:40:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A3=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BC=D1=83=D1=82=D0=B8=D0=BB=D1=81=D1=8F=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D1=83=D0=B4=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 142 ++++++++++++++++++ .../HelperEnums/ExcelStyleInfoType.cs | 9 ++ .../HelperEnums/PdfParagraphAlignmentType.cs | 9 ++ .../HelperEnums/WordJustificationType.cs | 8 + .../HelperModels/ExcelCellParameters.cs | 13 ++ .../OfficePackage/HelperModels/ExcelInfo.cs | 18 +++ .../HelperModels/ExcelMergeParameters.cs | 9 ++ .../OfficePackage/HelperModels/PdfInfo.cs | 13 ++ .../HelperModels/PdfParagraph.cs | 11 ++ .../HelperModels/PdfRowParameters.cs | 11 ++ .../OfficePackage/HelperModels/WordInfo.cs | 13 ++ .../HelperModels/WordParagraph.cs | 8 + .../HelperModels/WordTextProperties.cs | 11 ++ .../UniversityBusinessLogic.csproj | 7 +- .../BindingModels/ReportBindingModel.cs | 7 - .../BusinessLogicsContracts/IReportLogic.cs | 19 ++- .../SearchModels/DisciplineSearchModel.cs | 2 + .../SearchModels/StudentSearchModel.cs | 1 - .../StorageContracts/IDisciplineStorage.cs | 1 + .../ViewModels/ReportDisciplineViewModel.cs | 15 ++ .../ViewModels/ReportTeacherViewModel.cs | 14 ++ .../Implements/DisciplineStorage.cs | 75 +++++++-- .../Implements/StudentStorage.cs | 1 + .../Models/Discipline.cs | 1 + 24 files changed, 388 insertions(+), 30 deletions(-) create mode 100644 University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 University/UniversityBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs create mode 100644 University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..973c501 --- /dev/null +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,142 @@ +using AbstractLawFirmContracts.ViewModels; +using System.Reflection; +using UniversityBusinessLogics.OfficePackage; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StorageContracts; + +namespace UniversityBusinessLogics.BusinessLogics; + +public class ReportLogic : IReportLogic +{ + public List GetDisciplines(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + /*private readonly AbstractSaveToWord _saveToWord; +private readonly AbstractSaveToExcel _saveToExcel; +private readonly AbstractSaveToPdf _saveToPdf;*/ + + private readonly ITeacherStorage _teacherStorage; + private readonly IDisciplineStorage _disciplineStorage; + private readonly IStudentStorage _studentStorage; + private readonly IStatementStorage _statementStorage; + private readonly IPlanOfStudyStorage _planOfStudyStorage; + public List GetTeachers() + { + var teachers = _teacherStorage.GetFullList(); + + // Создаем список для результатов + var result = new List(); + + foreach (var teacher in teachers) + { + // Получаем список дисциплин, связанных с учителем + var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel + { + TeacherId = teacher.Id, + }); + + // Получаем список студентов, связанных с дисциплинами + var students = new List<(string Student, string PhoneNumber)>(); + foreach (var discipline in disciplines) + { + var studentDisciplines = _disciplineStorage.GetStudentsForDiscipline(new DisciplineSearchModel + { + Id = discipline.Id, + }); + + foreach (var studentDiscipline in studentDisciplines) + { + var studentList = _studentStorage.GetFilteredList(new StudentSearchModel + { + Id = studentDiscipline.Id, + }); + foreach(var st in studentList){ + students.Add((st.Name, st.PhoneNumber)); + } + } + } + + // Добавляем учителя и его студентов в результат + result.Add(new ReportTeacherViewModel + { + TeacherName = teacher.Name, + Students = students.Distinct().ToList() // Убираем дубликаты, если они есть + }); + } + + return result; + } + + public List GetDisciplines(ReportDateRangeBindingModel model) + { + var disciplines = _disciplineStorage.GetFullList(); + + var reportDisciplineViewModels = new List(); + + foreach (var discipline in disciplines) + { + // Получаем список студентов, связанных с дисциплинами + var studentDisciplines = _disciplineStorage.GetStudentsForDiscipline(new DisciplineSearchModel + { + Id = discipline.Id, + }); + + var planOfStudys = new List(); + foreach (var studentDiscipline in studentDisciplines) + { + var student = _studentStorage.GetElement(new StudentSearchModel + { + Id = studentDiscipline.Id, + }); + + if (student != null) + { + var planOfStudy = _planOfStudyStorage.GetElement(new PlanOfStudySearchModel + { + Id = student.PlanOfStudyId, + }); + + if (planOfStudy != null) + { + planOfStudys.Add(planOfStudy.Profile); + } + } + } + + // Получаем список заявлений преподавателя в указанном диапазоне дат + var statements = _statementStorage.GetFilteredList(new StatementSearchModel + { + TeacherId = discipline.TeacherId + }); + + // Создаем ReportDisciplineViewModel и добавляем его в список + reportDisciplineViewModels.Add(new ReportDisciplineViewModel + { + DisciplineName = discipline.Name, + PlanOfStudys = planOfStudys.Distinct().ToList(), // Убираем дубликаты, если они есть + Statements = statements.Select(s => s.Name).ToList() + }); + } + + return reportDisciplineViewModels; + } + + public void SaveTeachersToExcel(ReportBindingModel option) + { + throw new NotImplementedException(); + } + + public void SaveTeachersToWord(ReportBindingModel option) + { + throw new NotImplementedException(); + } + + public void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..512b9c9 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,9 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBroder + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..5a09062 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,9 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Rigth + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..72cfdad --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,8 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..87fb289 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,13 @@ +using UniversityBusinessLogics.OfficePackage.HelperEnums; + +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + public uint RowIndex { get; set; } + public string Text { get; set; } = string.Empty; + public string CellReference => $"{ColumnName}{RowIndex}"; + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..92064ba --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,18 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string? FileName { get; set; } + + public Stream? Stream { get; set; } + + public string Title { get; set; } = string.Empty; + public List ReportObjects + { + get; + set; + } = new(); + + public List Headers { get; set; } = new(); + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..e638ca4 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,9 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + public string CellToName { get; set; } = string.Empty; + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..fe872e8 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,13 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string? FileName { get; set; } + public Stream? Stream { get; set; } + + public string Title { get; set; } = string.Empty; + public DateOnly DateFrom { get; set; } + public DateOnly DateTo { get; set; } + public List ReportObjects { get; set; } = new(); + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..d4df81c --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,11 @@ +using UniversityBusinessLogics.OfficePackage.HelperEnums; + +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..3cc200e --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,11 @@ +using UniversityBusinessLogics.OfficePackage.HelperEnums; + +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..29cdf35 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,13 @@ + + +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class WordInfo + { + public string? FileName { get; set; } + public Stream? Stream { get; set; } + + public string Title { get; set; } = string.Empty; + public List ReportObjects { get; set; } = new(); + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..a56541e --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,8 @@ +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..2a4789c --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,11 @@ +using UniversityBusinessLogics.OfficePackage.HelperEnums; + +namespace UniversityBusinessLogics.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/University/UniversityBusinessLogic/UniversityBusinessLogic.csproj b/University/UniversityBusinessLogic/UniversityBusinessLogic.csproj index 6ae889b..bad8818 100644 --- a/University/UniversityBusinessLogic/UniversityBusinessLogic.csproj +++ b/University/UniversityBusinessLogic/UniversityBusinessLogic.csproj @@ -10,8 +10,9 @@ - - - + + + + diff --git a/University/UniversityContracts/BindingModels/ReportBindingModel.cs b/University/UniversityContracts/BindingModels/ReportBindingModel.cs index 1635afb..42bea2f 100644 --- a/University/UniversityContracts/BindingModels/ReportBindingModel.cs +++ b/University/UniversityContracts/BindingModels/ReportBindingModel.cs @@ -1,15 +1,8 @@ namespace UniversityContracts.BindingModels; -/// -/// Опции для сохранения отчета, при сохранении указать одно из двух -/// public class ReportBindingModel { public string? FileName { get; set; } public Stream? Stream { get; set; } - - /// - /// Массив айдишников по которым происходит выборка - /// public int[]? Ids { get; set; } } \ No newline at end of file diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 799ca5a..3d32280 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -1,4 +1,5 @@ -using System; +using AbstractLawFirmContracts.ViewModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,14 +10,16 @@ namespace UniversityContracts.BusinessLogicContracts { public interface IReportLogic { - void SaveDisciplinesToWord(ReportBindingModel option); + /// + /// Часть кладовщика + /// + /// + /// + List GetTeachers(); + List GetDisciplines(ReportBindingModel model); + void SaveTeachersToWord(ReportBindingModel option); - void SaveDisciplinesToExcel(ReportBindingModel option); - - void SendAccountsToEmail(ReportDateRangeBindingModel option, string email); - void SaveClientsToWord(ReportBindingModel option); - - void SaveClientsToExcel(ReportBindingModel option); + void SaveTeachersToExcel(ReportBindingModel option); void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email); } diff --git a/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs index 7b22b8d..e2b387c 100644 --- a/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs +++ b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs @@ -13,5 +13,7 @@ namespace UniversityContracts.SearchModels public int? TeacherId { get; set; } public string? Name { get; set; } public string? Description { get; set; } + public DateOnly? DateFrom { get; set; } + public DateOnly? DateTo { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/StudentSearchModel.cs b/University/UniversityContracts/SearchModels/StudentSearchModel.cs index 64577d9..cafc103 100644 --- a/University/UniversityContracts/SearchModels/StudentSearchModel.cs +++ b/University/UniversityContracts/SearchModels/StudentSearchModel.cs @@ -7,6 +7,5 @@ namespace UniversityContracts.SearchModels public int? Id { get; set; } public int UserId { get; set; } public string? Name { get; set; } - } } diff --git a/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs b/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs index ab18309..437940e 100644 --- a/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs +++ b/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs @@ -17,5 +17,6 @@ namespace UniversityContracts.StorageContracts DisciplineViewModel? Insert(DisciplineBindingModel model); DisciplineViewModel? Update(DisciplineBindingModel model); DisciplineViewModel? Delete(DisciplineBindingModel model); + List GetStudentsForDiscipline(DisciplineSearchModel model); } } diff --git a/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs b/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs new file mode 100644 index 0000000..5bed29f --- /dev/null +++ b/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ReportDisciplineViewModel + { + public string DisciplineName { get; set; } = string.Empty; + public List PlanOfStudys { get; set; } = new(); + public List Statements { get; set; } = new(); + } +} \ No newline at end of file diff --git a/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs new file mode 100644 index 0000000..3c203fe --- /dev/null +++ b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ReportTeacherViewModel + { + public string TeacherName { get; set; } = string.Empty; + public List<(string Student, string PhoneNumber)> Students { get; set; } = new(); + } +} \ No newline at end of file diff --git a/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs index 6a02cd7..a7978ce 100644 --- a/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs @@ -15,6 +15,25 @@ namespace UniversityDatabaseImplement.Implements { public class DisciplineStorage : IDisciplineStorage { + public List GetStudentsForDiscipline(DisciplineSearchModel model) + { + using var context = new UniversityDatabase(); + + var discipline = context.Disciplines + .Include(d => d.Students) + .ThenInclude(sd => sd.Student) + .FirstOrDefault(d => d.Id == model.Id); + + if (discipline == null) + { + return new List(); // Если дисциплина не найдена, возвращаем пустой список + } + + return discipline.Students + .Select(sd => sd.Student.GetViewModel) + .ToList(); + } + public DisciplineViewModel? Delete(DisciplineBindingModel model) { using var context = new UniversityDatabase(); @@ -42,22 +61,48 @@ namespace UniversityDatabaseImplement.Implements } + + //ешьте котиков в них витамин с public List GetFilteredList(DisciplineSearchModel model) { - if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Description)) - { - return new(); - } + CheckSearchModel(model); + using var context = new UniversityDatabase(); - return context.Disciplines - .Include(x => x.Students) - .ThenInclude(x => x.Student) - .Where(x => x.Name.Contains(model.Name) || x.Description.Contains(model.Description) || x.Id == model.Id || x.TeacherId == model.TeacherId) - .Include(x => x.Teacher) - .Select(x => x.GetViewModel) - .ToList(); + var query = context.Disciplines + .Include(x => x.Students) + .ThenInclude(x => x.Student) + .Include(x => x.Teacher) + .AsQueryable(); + + if (!string.IsNullOrEmpty(model.Name)) + { + query = query.Where(x => x.Name.Contains(model.Name)); + } + + if (!string.IsNullOrEmpty(model.Description)) + { + query = query.Where(x => x.Description.Contains(model.Description)); + } + + if (model.Id.HasValue) + { + query = query.Where(x => x.Id == model.Id.Value); + } + + if (model.TeacherId.HasValue) + { + query = query.Where(x => x.TeacherId == model.TeacherId.Value); + } + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value); + } + + return query.Select(x => x.GetViewModel).ToList(); } + public List GetFullList() { using var context = new UniversityDatabase(); @@ -105,5 +150,13 @@ namespace UniversityDatabaseImplement.Implements throw; } } + + private void CheckSearchModel(DisciplineSearchModel model) + { + if (model == null) + throw new ArgumentNullException("Передаваемая модель пуста", nameof(model)); + if (model.DateFrom.HasValue != model.DateTo.HasValue) + throw new ArgumentException($"Не указано начало {model.DateFrom} или конец {model.DateTo} периода."); + } } } diff --git a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs index e4df1e7..a56480c 100644 --- a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs @@ -9,6 +9,7 @@ using UniversityContracts.SearchModels; using UniversityContracts.StorageContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace UniversityDatabaseImplement.Implements { diff --git a/University/UniversityDatabaseImplement/Models/Discipline.cs b/University/UniversityDatabaseImplement/Models/Discipline.cs index b058589..6053987 100644 --- a/University/UniversityDatabaseImplement/Models/Discipline.cs +++ b/University/UniversityDatabaseImplement/Models/Discipline.cs @@ -23,6 +23,7 @@ namespace UniversityDatabaseImplement.Models public string Name { get; private set; } = string.Empty; [Required] public string Description { get; private set; } = string.Empty; + public DateOnly Date { get; private set; } public virtual User User { get; set; } = new(); public virtual Teacher Teacher { get; set; } = new(); private Dictionary? _studentDisciplines = null;