diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index 973c501..2220045 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -1,10 +1,11 @@ -using AbstractLawFirmContracts.ViewModels; -using System.Reflection; +using System.Reflection; +using University.ViewModels; using UniversityBusinessLogics.OfficePackage; using UniversityContracts.BindingModels; using UniversityContracts.BusinessLogicContracts; using UniversityContracts.SearchModels; using UniversityContracts.StorageContracts; +using UniversityContracts.ViewModels; namespace UniversityBusinessLogics.BusinessLogics; @@ -125,10 +126,74 @@ private readonly AbstractSaveToPdf _saveToPdf;*/ return reportDisciplineViewModels; } + public List GetPlanOfStudyAndDisciplines() + { + var planOfStudies = _planOfStudyStorage.GetFullList(); + var reportPlanOfStudyViewModels = new List(); + + foreach (var planOfStudy in planOfStudies) + { + // Получаем список дисциплин для текущего плана обучения + var disciplines = _planOfStudyStorage.GetDisciplineFromStudentsFromPlanOfStudys(new PlanOfStudySearchModel { Id = planOfStudy.Id }); + + // Создаем ReportPlanOfStudyViewModel и добавляем его в список + reportPlanOfStudyViewModels.Add(new ReportPlanOfStudyViewModel + { + PlanOfStudyName = planOfStudy.Profile, + Disciplines = disciplines.Select(d => d.Name).ToList() // Получаем только имена дисциплин + }); + } + + return reportPlanOfStudyViewModels; + } + + public List GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model) + { + var planOfStudies = _planOfStudyStorage.GetFullList(); + var reportPlanOfStudyAndStudentViewModels = new List(); + + foreach (var planOfStudy in planOfStudies) + { + // Получаем список студентов для текущего плана обучения + var students = _studentStorage.GetFilteredList(new StudentSearchModel { Id = planOfStudy.Id }); + + var studentsAndDisciplines = new List<(string Student, string Discipline)>(); + + foreach (var student in students) + { + // Получаем список дисциплин для текущего студента + var disciplines = _disciplineStorage.GetFilteredList(new DisciplineSearchModel { Id = student.Id }); + + foreach (var discipline in disciplines) + { + studentsAndDisciplines.Add((student.Name, discipline.Name)); + } + } + + // Создаем ReportPlanOfStudyAndStudentViewModel и добавляем его в список + reportPlanOfStudyAndStudentViewModels.Add(new ReportPlanOfStudyAndStudentViewModel + { + PlanOfStudyName = planOfStudy.Profile, + StudentsAndDisciplines = studentsAndDisciplines + }); + } + + return reportPlanOfStudyAndStudentViewModels; + } + public void SaveTeachersToExcel(ReportBindingModel option) { throw new NotImplementedException(); } + public void SavePlanOfStudyToExcel(ReportBindingModel option) + { + throw new NotImplementedException(); + } + + public void SavePlanOfStudyToWord(ReportBindingModel option) + { + throw new NotImplementedException(); + } public void SaveTeachersToWord(ReportBindingModel option) { @@ -139,4 +204,9 @@ private readonly AbstractSaveToPdf _saveToPdf;*/ { throw new NotImplementedException(); } + + public void SendPlanOfStudyToEmail(ReportDateRangeBindingModel option, string email) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 3d32280..6c17041 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -1,9 +1,9 @@ -using AbstractLawFirmContracts.ViewModels; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using University.ViewModels; using UniversityContracts.BindingModels; namespace UniversityContracts.BusinessLogicContracts diff --git a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs index e3466a2..9b48f00 100644 --- a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs +++ b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs @@ -11,5 +11,7 @@ namespace UniversityContracts.SearchModels public int? Id { get; set; } public int UserId { get; set; } public string? Profile { get; set; } + public DateOnly? DateFrom { get; set; } + public DateOnly? DateTo { get; set; } } } diff --git a/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs b/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs index a02307d..6409946 100644 --- a/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs +++ b/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs @@ -17,5 +17,6 @@ namespace UniversityContracts.StorageContracts PlanOfStudyViewModel? Insert(PlanOfStudyBindingModel model); PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model); PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model); + List GetDisciplineFromStudentsFromPlanOfStudys(PlanOfStudySearchModel model); } } diff --git a/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs b/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs index 5bed29f..cfd4fcf 100644 --- a/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs +++ b/University/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractLawFirmContracts.ViewModels +namespace University.ViewModels { public class ReportDisciplineViewModel { diff --git a/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs b/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs new file mode 100644 index 0000000..c33ba9b --- /dev/null +++ b/University/UniversityContracts/ViewModels/ReportPlanOfStudyAndStudentViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportPlanOfStudyAndStudentViewModel + { + public string PlanOfStudyName { get; set; } = string.Empty; + public List<(string Student, string Discipline)> StudentsAndDisciplines { get; set; } = new(); + } +} diff --git a/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs b/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs new file mode 100644 index 0000000..7a16559 --- /dev/null +++ b/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportPlanOfStudyViewModel + { + public string PlanOfStudyName { get; set; } = string.Empty; + public List Disciplines { get; set; } = new(); + } +} diff --git a/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs index 3c203fe..abc3141 100644 --- a/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs +++ b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractLawFirmContracts.ViewModels +namespace University.ViewModels { public class ReportTeacherViewModel { diff --git a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs index cfe9023..7a5d86b 100644 --- a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs @@ -21,16 +21,46 @@ namespace UniversityDatabaseImplement.Implements return context.PlanOfStudys.Select(x => x.GetViewModel).ToList(); } + public List GetDisciplineFromStudentsFromPlanOfStudys(PlanOfStudySearchModel model) + { + using var context = new UniversityDatabase(); + + var students = context.Students + .Where(s => s.PlanOfStudyId == model.Id) + .Include(s => s.StudentDiscipline) + .ToList(); + + if(students == null) + { + return new List(); + } + + // Получаем список дисциплин, которые соответствуют условиям поиска в модели PlanOfStudySearchModel + var disciplines = students + .SelectMany(s => s.StudentDiscipline) + .Distinct() + .ToList(); + + if (disciplines == null) + { + return new List(); + } + + // Преобразуем список дисциплин в список DisciplineViewModel и возвращаем его + return disciplines + .Select(d => d.Discipline.GetViewModel).ToList(); + } + public List GetFilteredList(PlanOfStudySearchModel model) { using var context = new UniversityDatabase(); - if (model.Id.HasValue) + var query = context.PlanOfStudys + .Include(x => x.Students) + .Where(x => x.Id == model.Id) + .AsQueryable(); + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return context.PlanOfStudys - .Include(x => x.Students) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value); } return new(); } diff --git a/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs index 5f37071..b721af2 100644 --- a/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs +++ b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs @@ -18,6 +18,7 @@ namespace UniversityDatabaseImplement.Models public int UserId { get; private set; } [Required] public string Profile { get; private set; } = string.Empty; + public DateOnly Date { get; private set; } [Required] public string FormOfStudy { get; private set; } = string.Empty; private Dictionary? _planOfStudyTeachers = null; diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 9d0ebdc..2b73bad 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -10,8 +10,8 @@ namespace UniversityDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR + optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/UniversityRestApi.csproj b/University/UniversityRestApi/UniversityRestApi.csproj index 0a37e73..cbced8d 100644 --- a/University/UniversityRestApi/UniversityRestApi.csproj +++ b/University/UniversityRestApi/UniversityRestApi.csproj @@ -7,6 +7,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +