From 59e6a1418f0d15a5cbedcda79c38347285c18df9 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:17:52 +0400 Subject: [PATCH 1/3] change dictionaries --- University/UniversityDataModels/Models/IDisciplineModel.cs | 1 + University/UniversityDataModels/Models/IStatementModel.cs | 1 - University/UniversityDataModels/Models/IStudentModel.cs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/University/UniversityDataModels/Models/IDisciplineModel.cs b/University/UniversityDataModels/Models/IDisciplineModel.cs index a40373f..c2c26ae 100644 --- a/University/UniversityDataModels/Models/IDisciplineModel.cs +++ b/University/UniversityDataModels/Models/IDisciplineModel.cs @@ -4,5 +4,6 @@ { String Name { get; } String Department { get; } + int StatementId { get; } } } diff --git a/University/UniversityDataModels/Models/IStatementModel.cs b/University/UniversityDataModels/Models/IStatementModel.cs index 6188a75..681f016 100644 --- a/University/UniversityDataModels/Models/IStatementModel.cs +++ b/University/UniversityDataModels/Models/IStatementModel.cs @@ -4,6 +4,5 @@ { DateTime Date { get; } int HoursCount { get; } - Dictionary Students { get; } } } diff --git a/University/UniversityDataModels/Models/IStudentModel.cs b/University/UniversityDataModels/Models/IStudentModel.cs index ce5db79..1ff6eb5 100644 --- a/University/UniversityDataModels/Models/IStudentModel.cs +++ b/University/UniversityDataModels/Models/IStudentModel.cs @@ -5,5 +5,6 @@ String Name { get; } String RecordCardNumber { get; } Dictionary Results { get; } + Dictionary Statements { get; } } } From c863490d687a807244816a48dd489a3545b04c5c Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:20:25 +0400 Subject: [PATCH 2/3] change dictionaries in contracts --- .../UniversityContracts/BindingModels/DisciplineBindingModel.cs | 1 + .../UniversityContracts/BindingModels/StatementBindingModel.cs | 1 - .../UniversityContracts/BindingModels/StudentBindingModel.cs | 1 + University/UniversityContracts/ViewModels/DisciplineViewModel.cs | 1 + University/UniversityContracts/ViewModels/StatementViewModel.cs | 1 - University/UniversityContracts/ViewModels/StudentViewModel.cs | 1 + 6 files changed, 4 insertions(+), 2 deletions(-) diff --git a/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs index 806a25f..9b07450 100644 --- a/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs +++ b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs @@ -7,5 +7,6 @@ namespace UniversityContracts.BindingModels public int Id { get; set; } public string Name { get; set; } = String.Empty; public string Department { get; set; } = String.Empty; + public int StatementId { get; set; } } } diff --git a/University/UniversityContracts/BindingModels/StatementBindingModel.cs b/University/UniversityContracts/BindingModels/StatementBindingModel.cs index d584937..7cf9d4f 100644 --- a/University/UniversityContracts/BindingModels/StatementBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StatementBindingModel.cs @@ -7,6 +7,5 @@ namespace UniversityContracts.BindingModels public int Id { get; set; } public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public int HoursCount { get; set; } - public Dictionary Students { get; set; } = new(); } } diff --git a/University/UniversityContracts/BindingModels/StudentBindingModel.cs b/University/UniversityContracts/BindingModels/StudentBindingModel.cs index 26869e3..f3d682b 100644 --- a/University/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -8,5 +8,6 @@ namespace UniversityContracts.BindingModels 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/ViewModels/DisciplineViewModel.cs b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs index 472734a..4b16129 100644 --- a/University/UniversityContracts/ViewModels/DisciplineViewModel.cs +++ b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs @@ -7,5 +7,6 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public string Name { get; set; } = String.Empty; public string Department { get; set; } = String.Empty; + public int StatementId { get; set; } } } diff --git a/University/UniversityContracts/ViewModels/StatementViewModel.cs b/University/UniversityContracts/ViewModels/StatementViewModel.cs index b3ded91..728fb53 100644 --- a/University/UniversityContracts/ViewModels/StatementViewModel.cs +++ b/University/UniversityContracts/ViewModels/StatementViewModel.cs @@ -7,6 +7,5 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public int HoursCount { get; set; } - public Dictionary Students { get; set; } = new(); } } diff --git a/University/UniversityContracts/ViewModels/StudentViewModel.cs b/University/UniversityContracts/ViewModels/StudentViewModel.cs index 141b33e..3c44bff 100644 --- a/University/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/University/UniversityContracts/ViewModels/StudentViewModel.cs @@ -8,5 +8,6 @@ namespace UniversityContracts.ViewModels 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(); } } From d36d38e35310436d4c6771e2a34cb3ac220e189c Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:26:45 +0400 Subject: [PATCH 3/3] change dictionaries in database implement --- .../Implements/StatementStorage.cs | 6 ------ .../Implements/StudentStorage.cs | 6 ++++++ .../DatabaseImplement/Models/Statement.cs | 15 --------------- .../DatabaseImplement/Models/Student.cs | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/University/DatabaseImplement/Implements/StatementStorage.cs b/University/DatabaseImplement/Implements/StatementStorage.cs index 13b5973..25581f5 100644 --- a/University/DatabaseImplement/Implements/StatementStorage.cs +++ b/University/DatabaseImplement/Implements/StatementStorage.cs @@ -13,8 +13,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .Select(x => x.GetViewModel) .ToList(); } @@ -22,8 +20,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) ) @@ -39,8 +35,6 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public StatementViewModel? Insert(StatementBindingModel model) diff --git a/University/DatabaseImplement/Implements/StudentStorage.cs b/University/DatabaseImplement/Implements/StudentStorage.cs index c22b540..8510a19 100644 --- a/University/DatabaseImplement/Implements/StudentStorage.cs +++ b/University/DatabaseImplement/Implements/StudentStorage.cs @@ -15,6 +15,8 @@ namespace UniversityDatabaseImplement.Implements return context.Students .Include(x => x.StudentExaminationResults) .ThenInclude(x => x.ExaminationResult) + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Statement) .Select(x => x.GetViewModel) .ToList(); } @@ -24,6 +26,8 @@ namespace UniversityDatabaseImplement.Implements return context.Students .Include(x => x.StudentExaminationResults) .ThenInclude(x => x.ExaminationResult) + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Statement) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name)) @@ -42,6 +46,8 @@ namespace UniversityDatabaseImplement.Implements 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) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } diff --git a/University/DatabaseImplement/Models/Statement.cs b/University/DatabaseImplement/Models/Statement.cs index 629599d..04c4442 100644 --- a/University/DatabaseImplement/Models/Statement.cs +++ b/University/DatabaseImplement/Models/Statement.cs @@ -17,20 +17,6 @@ namespace UniversityDatabaseImplement.Models public virtual List StatementStudents { get; set; } = new(); [ForeignKey("StatementId")] public virtual List ExaminationResults { get; set; } = new(); - private Dictionary? _students = null; - public Dictionary Students - { - get - { - if(_students == null) - { - _students = StatementStudents.ToDictionary( - x => x.Student.Id, x => x.Student as IStudentModel); - } - - return _students; - } - } public static Statement Create(StatementBindingModel model) { return new Statement @@ -54,7 +40,6 @@ namespace UniversityDatabaseImplement.Models Id = Id, Date = Date, HoursCount = HoursCount, - Students = Students }; } diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index 0637590..cfba763 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -31,6 +31,22 @@ namespace UniversityDatabaseImplement.Models return _results; } } + + private Dictionary? _statements; + [NotMapped] + public Dictionary Statements + { + get + { + if (_statements == null) + { + _statements = StatementStudents.ToDictionary( + x => x.Statement.Id, x => x.Statement as IStatementModel); + } + + return _statements; + } + } public static Student Create(StudentBindingModel model) { return new Student @@ -54,7 +70,8 @@ namespace UniversityDatabaseImplement.Models Id = Id, Name = Name, RecordCardNumber = RecordCardNumber, - Results = Results + Results = Results, + Statements = Statements }; }