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 };