Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic
This commit is contained in:
commit
9ae67bcc97
@ -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)
|
||||
{
|
||||
|
@ -17,6 +17,8 @@ namespace UniversityDatabaseImplement.Models
|
||||
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
|
||||
[ForeignKey("StudentId")]
|
||||
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
|
||||
[ForeignKey("StudentId")]
|
||||
public virtual List<UserStudent> StudentUsers { get; set; } = new();
|
||||
|
||||
private Dictionary<int, IStatementModel>? _statements;
|
||||
[NotMapped]
|
||||
|
@ -21,6 +21,10 @@ namespace UniversityDatabaseImplement.Models
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<UserStudent> StudentUsers { get; set; } = new();
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Statement> Statements { get; set; } = new();
|
||||
public static User Create(UserBindingModel model)
|
||||
{
|
||||
return new User
|
||||
|
15
University/DatabaseImplement/Models/UserStudent.cs
Normal file
15
University/DatabaseImplement/Models/UserStudent.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace UniversityDatabaseImplement.Models
|
||||
{
|
||||
public class UserStudent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int StudentTypeId { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public virtual Student Student { get; set; } = new();
|
||||
public virtual User User { get; set; } = new();
|
||||
}
|
||||
}
|
@ -24,5 +24,6 @@ namespace UniversityDatabaseImplement
|
||||
public virtual DbSet<Student> Students { set; get; }
|
||||
public virtual DbSet<StudentExaminationResult> StudentExaminationResults { set; get; }
|
||||
public virtual DbSet<User> Users { set; get; }
|
||||
public virtual DbSet<UserStudent> UserStudents { set; get; }
|
||||
}
|
||||
}
|
@ -8,5 +8,6 @@ namespace UniversityContracts.BindingModels
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Department { get; set; } = String.Empty;
|
||||
public int StatementId { get; set; }
|
||||
public Dictionary<int, IStatementModel> DisciplineStatements { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ namespace UniversityContracts.ViewModels
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Department { get; set; } = String.Empty;
|
||||
public int StatementId { get; set; }
|
||||
public Dictionary<int, IStatementModel> DisciplineStatements { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
{
|
||||
String Name { get; }
|
||||
String Department { get; }
|
||||
int StatementId { get; }
|
||||
Dictionary<int, IStatementModel> DisciplineStatements { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user