From 48db39218dc59501739676f6ad1cc2ac2a4979a6 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 00:45:19 +0400 Subject: [PATCH] add user database links --- University/DatabaseImplement/Models/Student.cs | 2 ++ University/DatabaseImplement/Models/User.cs | 4 ++++ .../DatabaseImplement/Models/UserStudent.cs | 15 +++++++++++++++ .../DatabaseImplement/UniversityDatabase.cs | 1 + 4 files changed, 22 insertions(+) create mode 100644 University/DatabaseImplement/Models/UserStudent.cs diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index 615ae6d..849ba54 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -17,6 +17,8 @@ namespace UniversityDatabaseImplement.Models public virtual List StatementStudents { get; set; } = new(); [ForeignKey("StudentId")] public virtual List StudentExaminationResults { get; set; } = new(); + [ForeignKey("StudentId")] + public virtual List StudentUsers { get; set; } = new(); private Dictionary? _statements; [NotMapped] diff --git a/University/DatabaseImplement/Models/User.cs b/University/DatabaseImplement/Models/User.cs index f6090e0..d9f0978 100644 --- a/University/DatabaseImplement/Models/User.cs +++ b/University/DatabaseImplement/Models/User.cs @@ -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 StudentUsers { get; set; } = new(); + [ForeignKey("UserId")] + public virtual List Statements { get; set; } = new(); public static User Create(UserBindingModel model) { return new User diff --git a/University/DatabaseImplement/Models/UserStudent.cs b/University/DatabaseImplement/Models/UserStudent.cs new file mode 100644 index 0000000..e7f1e29 --- /dev/null +++ b/University/DatabaseImplement/Models/UserStudent.cs @@ -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(); + } +} diff --git a/University/DatabaseImplement/UniversityDatabase.cs b/University/DatabaseImplement/UniversityDatabase.cs index 7561a59..6b8e224 100644 --- a/University/DatabaseImplement/UniversityDatabase.cs +++ b/University/DatabaseImplement/UniversityDatabase.cs @@ -24,5 +24,6 @@ namespace UniversityDatabaseImplement public virtual DbSet Students { set; get; } public virtual DbSet StudentExaminationResults { set; get; } public virtual DbSet Users { set; get; } + public virtual DbSet UserStudents { set; get; } } } \ No newline at end of file