diff --git a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs index 86f2495..94650ec 100644 --- a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs +++ b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs @@ -3,6 +3,7 @@ using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace UniversityDatabaseImplement.Implements { @@ -11,14 +12,21 @@ namespace UniversityDatabaseImplement.Implements public List GetFullList() { using var context = new UniversityDatabase(); - return context.ExaminationResults.Select(x => x.GetViewModel).ToList(); + return context.ExaminationResults + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) + .Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(ExaminationResultSearchModel model) { using var context = new UniversityDatabase(); return context.ExaminationResults + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) + (!model.Id.HasValue || x.Id == model.Id) && + (!model.From.HasValue || x.Date >= model.From) && + (!model.To.HasValue || x.Date <= model.To) ) ) .Select(x => x.GetViewModel) @@ -32,7 +40,9 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.ExaminationResults - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public ExaminationResultViewModel? Insert(ExaminationResultBindingModel model) { diff --git a/University/DatabaseImplement/Implements/StatementStorage.cs b/University/DatabaseImplement/Implements/StatementStorage.cs index 25581f5..77a99db 100644 --- a/University/DatabaseImplement/Implements/StatementStorage.cs +++ b/University/DatabaseImplement/Implements/StatementStorage.cs @@ -21,7 +21,9 @@ namespace UniversityDatabaseImplement.Implements using var context = new UniversityDatabase(); return context.Statements .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) + (!model.Id.HasValue || x.Id == model.Id) && + (!model.From.HasValue || x.Date >= model.From) && + (!model.To.HasValue || x.Date <= model.To) ) ) .Select(x => x.GetViewModel) diff --git a/University/DatabaseImplement/Implements/StudentStorage.cs b/University/DatabaseImplement/Implements/StudentStorage.cs index 8510a19..33fc7a7 100644 --- a/University/DatabaseImplement/Implements/StudentStorage.cs +++ b/University/DatabaseImplement/Implements/StudentStorage.cs @@ -13,8 +13,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .Select(x => x.GetViewModel) @@ -24,8 +22,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .Where(x => ( @@ -44,8 +40,6 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) || diff --git a/University/DatabaseImplement/Models/ExaminationResult.cs b/University/DatabaseImplement/Models/ExaminationResult.cs index bd77bb9..0ab3285 100644 --- a/University/DatabaseImplement/Models/ExaminationResult.cs +++ b/University/DatabaseImplement/Models/ExaminationResult.cs @@ -19,6 +19,22 @@ namespace UniversityDatabaseImplement.Models public virtual List Activities { get; set; } = new(); [ForeignKey("ExaminationResultId")] public virtual List StudentExaminationResults { get; set; } = new(); + + private Dictionary? _students; + [NotMapped] + public Dictionary Students + { + get + { + if (_students == null) + { + _students = StudentExaminationResults.ToDictionary( + x => x.Student.Id, x => x.Student as IStudentModel); + } + + return _students; + } + } public static ExaminationResult Create(ExaminationResultBindingModel model) { return new ExaminationResult diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index cfba763..615ae6d 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -18,20 +18,6 @@ namespace UniversityDatabaseImplement.Models [ForeignKey("StudentId")] public virtual List StudentExaminationResults { get; set; } = new(); - private Dictionary? _results; - [NotMapped] - public Dictionary Results { - get { - if(_results == null) - { - _results = StudentExaminationResults.ToDictionary( - x => x.ExaminationResult.Id, x => x.ExaminationResult as IExaminationResultModel); - } - - return _results; - } - } - private Dictionary? _statements; [NotMapped] public Dictionary Statements @@ -70,7 +56,6 @@ namespace UniversityDatabaseImplement.Models Id = Id, Name = Name, RecordCardNumber = RecordCardNumber, - Results = Results, Statements = Statements }; diff --git a/University/UniversityContracts/BindingModels/ExaminationResultBindingModel.cs b/University/UniversityContracts/BindingModels/ExaminationResultBindingModel.cs index 8fbd495..372056d 100644 --- a/University/UniversityContracts/BindingModels/ExaminationResultBindingModel.cs +++ b/University/UniversityContracts/BindingModels/ExaminationResultBindingModel.cs @@ -9,5 +9,6 @@ namespace UniversityContracts.BindingModels public string ExaminationForm { get; set; } = String.Empty; public MarkType Mark { get; set; } = MarkType.Неизвестен; public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + public Dictionary Students { get; set; } = new(); } } diff --git a/University/UniversityContracts/BindingModels/StudentBindingModel.cs b/University/UniversityContracts/BindingModels/StudentBindingModel.cs index f3d682b..884775e 100644 --- a/University/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -7,7 +7,6 @@ namespace UniversityContracts.BindingModels public int Id { get; set; } public string Name { get; set; } = String.Empty; public string RecordCardNumber { get; set; } = String.Empty; - public Dictionary Results { get; set; } = new(); public Dictionary Statements { get; set; } = new(); } } diff --git a/University/UniversityContracts/SearchModels/ExaminationResultSearchModel.cs b/University/UniversityContracts/SearchModels/ExaminationResultSearchModel.cs index 4f27f9f..53c1f00 100644 --- a/University/UniversityContracts/SearchModels/ExaminationResultSearchModel.cs +++ b/University/UniversityContracts/SearchModels/ExaminationResultSearchModel.cs @@ -6,5 +6,7 @@ namespace UniversityContracts.SearchModels public class ExaminationResultSearchModel { public int? Id { get; set; } + public DateTime? From { get; set; } + public DateTime? To { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/StatementSearchModel.cs b/University/UniversityContracts/SearchModels/StatementSearchModel.cs index 7c3ca9d..6e807ad 100644 --- a/University/UniversityContracts/SearchModels/StatementSearchModel.cs +++ b/University/UniversityContracts/SearchModels/StatementSearchModel.cs @@ -5,5 +5,7 @@ namespace UniversityContracts.SearchModels public class StatementSearchModel { public int? Id { get; set; } + public DateTime? From { get; set; } + public DateTime? To { get; set; } } } diff --git a/University/UniversityContracts/ViewModels/ExaminationResultViewModel.cs b/University/UniversityContracts/ViewModels/ExaminationResultViewModel.cs index 379ac90..98817e6 100644 --- a/University/UniversityContracts/ViewModels/ExaminationResultViewModel.cs +++ b/University/UniversityContracts/ViewModels/ExaminationResultViewModel.cs @@ -9,5 +9,6 @@ namespace UniversityContracts.ViewModels public string ExaminationForm { get; set; } = String.Empty; public MarkType Mark { get; set; } = MarkType.Неизвестен; public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); + public Dictionary Students { get; set; } = new(); } } diff --git a/University/UniversityContracts/ViewModels/StudentViewModel.cs b/University/UniversityContracts/ViewModels/StudentViewModel.cs index 3c44bff..4cfc34d 100644 --- a/University/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/University/UniversityContracts/ViewModels/StudentViewModel.cs @@ -7,7 +7,6 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public string Name { get; set; } = String.Empty; public string RecordCardNumber { get; set; } = String.Empty; - public Dictionary Results { get; set; } = new(); public Dictionary Statements { get; set; } = new(); } } diff --git a/University/UniversityDataModels/Models/IExaminationResultModel.cs b/University/UniversityDataModels/Models/IExaminationResultModel.cs index c3c33e1..6180c87 100644 --- a/University/UniversityDataModels/Models/IExaminationResultModel.cs +++ b/University/UniversityDataModels/Models/IExaminationResultModel.cs @@ -6,5 +6,6 @@ namespace UniversityDataModels.Models String ExaminationForm { get; } MarkType Mark { get; } DateTime Date { get; } + Dictionary Students { get; } } } diff --git a/University/UniversityDataModels/Models/IStudentModel.cs b/University/UniversityDataModels/Models/IStudentModel.cs index 1ff6eb5..d296aaa 100644 --- a/University/UniversityDataModels/Models/IStudentModel.cs +++ b/University/UniversityDataModels/Models/IStudentModel.cs @@ -4,7 +4,6 @@ { String Name { get; } String RecordCardNumber { get; } - Dictionary Results { get; } Dictionary Statements { get; } } }