add statements in database discipline model
This commit is contained in:
parent
53fe0986cf
commit
d07365e746
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user