This commit is contained in:
MaxKarme 2023-04-09 00:18:39 +04:00
commit 8eb66e60c5
13 changed files with 39 additions and 28 deletions

View File

@ -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<ExaminationResultViewModel> 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<ExaminationResultViewModel> 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)
{

View File

@ -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)

View File

@ -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) ||

View File

@ -19,6 +19,22 @@ namespace UniversityDatabaseImplement.Models
public virtual List<Activity> Activities { get; set; } = new();
[ForeignKey("ExaminationResultId")]
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
private Dictionary<int, IStudentModel>? _students;
[NotMapped]
public Dictionary<int, IStudentModel> 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

View File

@ -18,20 +18,6 @@ namespace UniversityDatabaseImplement.Models
[ForeignKey("StudentId")]
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
private Dictionary<int, IExaminationResultModel>? _results;
[NotMapped]
public Dictionary<int, IExaminationResultModel> Results {
get {
if(_results == null)
{
_results = StudentExaminationResults.ToDictionary(
x => x.ExaminationResult.Id, x => x.ExaminationResult as IExaminationResultModel);
}
return _results;
}
}
private Dictionary<int, IStatementModel>? _statements;
[NotMapped]
public Dictionary<int, IStatementModel> Statements
@ -70,7 +56,6 @@ namespace UniversityDatabaseImplement.Models
Id = Id,
Name = Name,
RecordCardNumber = RecordCardNumber,
Results = Results,
Statements = Statements
};

View File

@ -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<int, IStudentModel> Students { get; set; } = new();
}
}

View File

@ -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<int, IExaminationResultModel> Results { get; set; } = new();
public Dictionary<int, IStatementModel> Statements { get; set; } = new();
}
}

View File

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

View File

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

View File

@ -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<int, IStudentModel> Students { get; set; } = new();
}
}

View File

@ -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<int, IExaminationResultModel> Results { get; set; } = new();
public Dictionary<int, IStatementModel> Statements { get; set; } = new();
}
}

View File

@ -6,5 +6,6 @@ namespace UniversityDataModels.Models
String ExaminationForm { get; }
MarkType Mark { get; }
DateTime Date { get; }
Dictionary<int, IStudentModel> Students { get; }
}
}

View File

@ -4,7 +4,6 @@
{
String Name { get; }
String RecordCardNumber { get; }
Dictionary<int, IExaminationResultModel> Results { get; }
Dictionary<int, IStatementModel> Statements { get; }
}
}