add statements in database discipline model

This commit is contained in:
MaxKarme 2023-04-09 01:11:16 +04:00
parent 53fe0986cf
commit d07365e746
2 changed files with 22 additions and 2 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,12 +12,15 @@ namespace UniversityDatabaseImplement.Implements
public List<DisciplineViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Disciplines.Select(x => x.GetViewModel).ToList();
return context.Disciplines
.Include(x => x.Statements)
.Select(x => x.GetViewModel).ToList();
}
public List<DisciplineViewModel> GetFilteredList(DisciplineSearchModel model)
{
using var context = new UniversityDatabase();
return context.Disciplines
.Include(x => x.Statements)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
@ -33,7 +37,8 @@ namespace UniversityDatabaseImplement.Implements
}
using var context = new UniversityDatabase();
return context.Disciplines
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
.Include(x => x.Statements)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public DisciplineViewModel? Insert(DisciplineBindingModel model)

View File

@ -17,6 +17,21 @@ namespace UniversityDatabaseImplement.Models
public virtual List<Statement> Statements { get; set; } = new();
[ForeignKey("DisciplineId")]
public virtual List<ReportTypeDiscipline> ReportTypeDisciplines { get; set; } = new();
private Dictionary<int, IStatementModel>? _disciplineStatements;
[NotMapped]
public Dictionary<int, IStatementModel> DisciplineStatements
{
get
{
if (_disciplineStatements == null)
{
_disciplineStatements = Statements.ToDictionary(
x => x.Id, x => x as IStatementModel);
}
return _disciplineStatements;
}
}
public static Discipline Create(DisciplineBindingModel model)
{