From f5c1abd6ed9e2b6ebbac8457f799710620e001e5 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Fri, 7 Apr 2023 13:24:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20Databaseimplement=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/DocumentBindingModel.cs | 1 + .../EducationStatusBindingModel.cs | 2 + .../BindingModels/StudentBindingModel.cs | 3 +- .../SearchModels/DocumentSearchModel.cs | 1 + .../EducationStatusSearchModel.cs | 1 + .../SearchModels/StudentSearchModel.cs | 1 + .../StoragesContracts/IDocumentStorage.cs | 1 + .../IEducationStatusStorage.cs | 1 + .../StoragesContracts/IStudentStorage.cs | 1 + .../ViewModels/DocumentViewModel.cs | 1 + .../ViewModels/EducationStatusViewModel.cs | 1 + .../ViewModels/StudentViewModel.cs | 3 + UniversityDataBaseImplemet/Class1.cs | 7 -- UniversityDataBaseImplemet/Database.cs | 26 ++++ .../Implements/DocumentStorage.cs | 113 +++++++++++++++++ .../Implements/EducationStatusStorage.cs | 115 +++++++++++++++++ .../Implements/StudentStorage.cs | 119 ++++++++++++++++++ UniversityDataBaseImplemet/Models/Document.cs | 55 ++++++++ .../Models/EducationStatus.cs | 50 ++++++++ UniversityDataBaseImplemet/Models/Student.cs | 64 ++++++++++ .../Models/StudentDocument.cs | 20 +++ .../UniversityDataBaseImplemet.csproj | 14 +++ UniversityModels/Models/IDocumentModel.cs | 1 + .../Models/IEducationStatusModel.cs | 1 + UniversityModels/Models/IStudentModel.cs | 1 + 25 files changed, 595 insertions(+), 8 deletions(-) delete mode 100644 UniversityDataBaseImplemet/Class1.cs create mode 100644 UniversityDataBaseImplemet/Database.cs create mode 100644 UniversityDataBaseImplemet/Implements/DocumentStorage.cs create mode 100644 UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs create mode 100644 UniversityDataBaseImplemet/Implements/StudentStorage.cs create mode 100644 UniversityDataBaseImplemet/Models/Document.cs create mode 100644 UniversityDataBaseImplemet/Models/EducationStatus.cs create mode 100644 UniversityDataBaseImplemet/Models/Student.cs create mode 100644 UniversityDataBaseImplemet/Models/StudentDocument.cs diff --git a/UniversityContracts/BindingModels/DocumentBindingModel.cs b/UniversityContracts/BindingModels/DocumentBindingModel.cs index f25c6be..700dc38 100644 --- a/UniversityContracts/BindingModels/DocumentBindingModel.cs +++ b/UniversityContracts/BindingModels/DocumentBindingModel.cs @@ -12,5 +12,6 @@ namespace UniversityContracts.BindingModels public int Id { get; set; } public string Name { get; set; } = string.Empty; public DateTime Date { get; set; } = DateTime.Now; + public int UserId { get; set; } } } diff --git a/UniversityContracts/BindingModels/EducationStatusBindingModel.cs b/UniversityContracts/BindingModels/EducationStatusBindingModel.cs index 5e7a84f..d9602f3 100644 --- a/UniversityContracts/BindingModels/EducationStatusBindingModel.cs +++ b/UniversityContracts/BindingModels/EducationStatusBindingModel.cs @@ -11,5 +11,7 @@ namespace UniversityContracts.BindingModels { public int Id { get; set; } public string Name { get; set; } = string.Empty; + public int UserId { get; set; } + } } diff --git a/UniversityContracts/BindingModels/StudentBindingModel.cs b/UniversityContracts/BindingModels/StudentBindingModel.cs index 24bf335..f614eb3 100644 --- a/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -14,6 +14,7 @@ namespace UniversityContracts.BindingModels public string Surname { get; set; } = string.Empty; public DateTime DateOfBirth { get; set; } public int StudentCard { get; set; } - public int EducationStatusId { get; set; } + public int EducationStatusId { get; set; } + public int UserId { get; set; } } } diff --git a/UniversityContracts/SearchModels/DocumentSearchModel.cs b/UniversityContracts/SearchModels/DocumentSearchModel.cs index f6b755a..ca97897 100644 --- a/UniversityContracts/SearchModels/DocumentSearchModel.cs +++ b/UniversityContracts/SearchModels/DocumentSearchModel.cs @@ -9,5 +9,6 @@ namespace UniversityContracts.SearchModels public class DocumentSearchModel { public int? Id { get; set; } + public int? UserId { get; set; } } } diff --git a/UniversityContracts/SearchModels/EducationStatusSearchModel.cs b/UniversityContracts/SearchModels/EducationStatusSearchModel.cs index b3eb13f..2c27b20 100644 --- a/UniversityContracts/SearchModels/EducationStatusSearchModel.cs +++ b/UniversityContracts/SearchModels/EducationStatusSearchModel.cs @@ -10,5 +10,6 @@ namespace UniversityContracts.SearchModels { public int? Id { get; set; } public string? Name { get; set; } + public int? UserId { get; set; } } } diff --git a/UniversityContracts/SearchModels/StudentSearchModel.cs b/UniversityContracts/SearchModels/StudentSearchModel.cs index 73e899f..2c55b25 100644 --- a/UniversityContracts/SearchModels/StudentSearchModel.cs +++ b/UniversityContracts/SearchModels/StudentSearchModel.cs @@ -9,5 +9,6 @@ namespace UniversityContracts.SearchModels public class StudentSearchModel { public int? Id { get; set; } + public int? UserId { get; set; } } } diff --git a/UniversityContracts/StoragesContracts/IDocumentStorage.cs b/UniversityContracts/StoragesContracts/IDocumentStorage.cs index 9b51360..86c718b 100644 --- a/UniversityContracts/StoragesContracts/IDocumentStorage.cs +++ b/UniversityContracts/StoragesContracts/IDocumentStorage.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.StoragesContracts { diff --git a/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs b/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs index 536d65c..9d69479 100644 --- a/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs +++ b/UniversityContracts/StoragesContracts/IEducationStatusStorage.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.StoragesContracts { diff --git a/UniversityContracts/StoragesContracts/IStudentStorage.cs b/UniversityContracts/StoragesContracts/IStudentStorage.cs index 5c68bff..9de8945 100644 --- a/UniversityContracts/StoragesContracts/IStudentStorage.cs +++ b/UniversityContracts/StoragesContracts/IStudentStorage.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.StoragesContracts { diff --git a/UniversityContracts/ViewModels/DocumentViewModel.cs b/UniversityContracts/ViewModels/DocumentViewModel.cs index a10a3be..c74461c 100644 --- a/UniversityContracts/ViewModels/DocumentViewModel.cs +++ b/UniversityContracts/ViewModels/DocumentViewModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels public class DocumentViewModel : IDocumentModel { public int Id { get; set; } + public int UserId { get; set; } [DisplayName("Название документа")] public string Name { get; set; } = string.Empty; [DisplayName("Дата создания документа")] diff --git a/UniversityContracts/ViewModels/EducationStatusViewModel.cs b/UniversityContracts/ViewModels/EducationStatusViewModel.cs index d436a7e..a0d3295 100644 --- a/UniversityContracts/ViewModels/EducationStatusViewModel.cs +++ b/UniversityContracts/ViewModels/EducationStatusViewModel.cs @@ -13,5 +13,6 @@ namespace UniversityContracts.ViewModels public int Id { get; set; } [DisplayName("Название документа")] public string Name { get; set; } = string.Empty; + public int UserId { get; set; } } } diff --git a/UniversityContracts/ViewModels/StudentViewModel.cs b/UniversityContracts/ViewModels/StudentViewModel.cs index ca0a85c..9370b5c 100644 --- a/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/UniversityContracts/ViewModels/StudentViewModel.cs @@ -11,12 +11,15 @@ namespace UniversityContracts.ViewModels public class StudentViewModel : IStudentModel { public int Id { get; set; } + public int UserId { get; set; } [DisplayName("Имя студента")] public string Name { get; set; } = string.Empty; [DisplayName("Фамилия студента")] public string Surname { get; set; } = string.Empty; [DisplayName("Дата рождения студента")] public DateTime DateOfBirth { get; set; } = DateTime.Now; + [DisplayName("Статус обучения")] + public string EducationStatusName { get; set; } = string.Empty; public int StudentCard { get; set; } public int EducationStatusId { get; set; } } diff --git a/UniversityDataBaseImplemet/Class1.cs b/UniversityDataBaseImplemet/Class1.cs deleted file mode 100644 index 79315b2..0000000 --- a/UniversityDataBaseImplemet/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace UniversityDataBaseImplemet -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/UniversityDataBaseImplemet/Database.cs b/UniversityDataBaseImplemet/Database.cs new file mode 100644 index 0000000..32d2753 --- /dev/null +++ b/UniversityDataBaseImplemet/Database.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet +{ + public class Database : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=University;Username=postgres;Password=postgres"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Documents { get; set; } + public virtual DbSet EducationStatuses { get; set; } + public virtual DbSet Students { get; set; } + public virtual DbSet StudentDocuments { get; set; } + } +} diff --git a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs new file mode 100644 index 0000000..0d66be0 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs @@ -0,0 +1,113 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class DocumentStorage : IDocumentStorage + { + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Documents + .Include(record => record.User) + .FirstOrDefault(record => record.Id == model.Id)? + .GetViewModel; + } + public List GetFilteredList(DocumentSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Documents + .Include(x => x.User) + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Documents + .Include(x => x.User) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Documents + .Include(record => record.User) + .Select(record => record.GetViewModel) + .ToList(); + } + public DocumentViewModel? Insert(DocumentBindingModel model) + { + var newDocument = Document.Create(model); + if(newDocument == null) + { + return null; + } + using var context = new Database(); + context.Documents.Add(newDocument); + context.SaveChanges(); + return newDocument.GetViewModel; + } + public DocumentViewModel? Update(DocumentBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var document = context.Documents + .Include(x => x.User) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (document == null) + { + return null; + } + document.Update(model); + context.SaveChanges(); + transaction.Commit(); + return document.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + using var context = new Database(); + var document = context.Documents + .Include(x => x.User) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (document == null) + { + return null; + } + context.Documents.Remove(document); + context.SaveChanges(); + return document.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs b/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs new file mode 100644 index 0000000..204ac40 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs @@ -0,0 +1,115 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class EducationStatusStorage : IEducationStatusStorage + { + public EducationStatusViewModel? GetElement(EducationStatusSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.EducationStatuses + .Include(x => x.User) + .FirstOrDefault(record => record.Id == model.Id)? + .GetViewModel; + } + public List GetFilteredList(EducationStatusSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.EducationStatuses + .Include(x => x.User) + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.EducationStatuses + .Include(x => x.User) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.EducationStatuses + .Include(x => x.User) + .Select(record => record.GetViewModel) + .ToList(); + } + public EducationStatusViewModel? Insert(EducationStatusBindingModel model) + { + var newEducationStatus = EducationStatus.Create(model); + if (newEducationStatus == null) + { + return null; + } + using var context = new Database(); + context.EducationStatuses.Add(newEducationStatus); + context.SaveChanges(); + return context.EducationStatuses + .Include(x => x.User) + .FirstOrDefault(x => x.Id.Equals(newEducationStatus.Id)) + ?.GetViewModel; + } + public EducationStatusViewModel? Update(EducationStatusBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var educationStatus = context.EducationStatuses + .Include(x => x.User) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationStatus == null) + { + return null; + } + educationStatus.Update(model); + context.SaveChanges(); + transaction.Commit(); + return educationStatus.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public EducationStatusViewModel? Delete(EducationStatusBindingModel model) + { + using var context = new Database(); + var educationStatus = context.EducationStatuses + .Include(x => x.User) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationStatus == null) + { + return null; + } + context.EducationStatuses.Remove(educationStatus); + context.SaveChanges(); + return educationStatus.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/StudentStorage.cs b/UniversityDataBaseImplemet/Implements/StudentStorage.cs new file mode 100644 index 0000000..3587a93 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/StudentStorage.cs @@ -0,0 +1,119 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class StudentStorage : IStudentStorage + { + public StudentViewModel? GetElement(StudentSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Students + .Include(record => record.User) + .Include(record => record.EducationStatus) + .FirstOrDefault(record => record.Id.Equals(model.Id)) + ?.GetViewModel; + } + public List GetFilteredList(StudentSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Students + .Include(record => record.EducationStatus) + .Include(x => x.User) + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Students + .Include(x => x.EducationStatus) + .Include(x => x.User) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Students + .Include(x => x.User) + .Include(x => x.EducationStatus) + .Select(record => record.GetViewModel) + .ToList(); + } + public StudentViewModel? Insert(StudentBindingModel model) + { + var newStudent = Student.Create(model); + if (newStudent == null) + { + return null; + } + using var context = new Database(); + context.Students.Add(newStudent); + context.SaveChanges(); + return newStudent.GetViewModel; + } + public StudentViewModel? Update(StudentBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var student = context.Students + .Include(x => x.User) + .Include(x => x.EducationStatus) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (student == null) + { + return null; + } + student.Update(model); + context.SaveChanges(); + transaction.Commit(); + return student.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public StudentViewModel? Delete(StudentBindingModel model) + { + using var context = new Database(); + var student = context.Students + .Include(x => x.User) + .Include(x => x.EducationStatus) + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (student == null) + { + return null; + } + context.Students.Remove(student); + context.SaveChanges(); + return student.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Models/Document.cs b/UniversityDataBaseImplemet/Models/Document.cs new file mode 100644 index 0000000..f4f24b0 --- /dev/null +++ b/UniversityDataBaseImplemet/Models/Document.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityModels.Models; + +namespace UniversityDataBaseImplemet.Models +{ + public class Document : IDocumentModel + { + public int Id { get; private set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public DateTime Date { get; set; } + [Required] + public int UserId { get; set; } + [ForeignKey("DocumentId")] + public virtual List Students { get; set; } = new(); + public virtual EducationStatus User { get; set; } + + public static Document? Create(DocumentBindingModel model) + { + return new Document() + { + Id = model.Id, + Name = model.Name, + Date = model.Date, + UserId = model.UserId, + }; + } + public void Update(DocumentBindingModel model) + { + if(model == null) + { + return; + } + Name = model.Name; + Date = model.Date; + UserId = model.UserId; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Date = Date, + UserId = UserId, + }; + } +} diff --git a/UniversityDataBaseImplemet/Models/EducationStatus.cs b/UniversityDataBaseImplemet/Models/EducationStatus.cs new file mode 100644 index 0000000..06aff6a --- /dev/null +++ b/UniversityDataBaseImplemet/Models/EducationStatus.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityModels.Models; + +namespace UniversityDataBaseImplemet.Models +{ + public class EducationStatus : IEducationStatusModel + { + public int Id { get; private set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public int UserId { get; set; } + [ForeignKey("EducationStatusId")] + public virtual List Students { get; set; } = new(); + public virtual EducationStatus User { get; set; } + + public static EducationStatus? Create(EducationStatusBindingModel model) + { + return new EducationStatus() + { + Id = model.Id, + Name = model.Name, + UserId = model.UserId, + }; + } + public void Update(EducationStatusBindingModel model) + { + if (model == null) + { + return; + } + Name = model.Name; + UserId = model.UserId; + } + public EducationStatusViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + UserId = UserId, + }; + } +} diff --git a/UniversityDataBaseImplemet/Models/Student.cs b/UniversityDataBaseImplemet/Models/Student.cs new file mode 100644 index 0000000..2182206 --- /dev/null +++ b/UniversityDataBaseImplemet/Models/Student.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityModels.Models; + +namespace UniversityDataBaseImplemet.Models +{ + public class Student : IStudentModel + { + public int Id { get; private set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string Surname { get; set; } = string.Empty; + [Required] + public DateTime DateOfBirth { get; set; } + [Required] + public int StudentCard { get; set; } + [Required] + public int EducationStatusId { get; set; } + [Required] + public int UserId { get; set; } + [ForeignKey("StudentId")] + public virtual List DocumentStudents { get; set; } = new(); + public virtual EducationStatus EducationStatus { get; set; } + public virtual EducationStatus User { get; set; } + + public static Student Create(StudentBindingModel model) + { + return new Student() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + DateOfBirth = model.DateOfBirth, + StudentCard = model.StudentCard, + EducationStatusId = model.EducationStatusId, + UserId = model.UserId + }; + } + public void Update(StudentBindingModel model) + { + StudentCard = model.StudentCard; + EducationStatusId = model.EducationStatusId; + } + public StudentViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + DateOfBirth = DateOfBirth, + StudentCard = StudentCard, + EducationStatusId = EducationStatusId, + UserId = UserId, + EducationStatusName = EducationStatus.Name + }; + } +} diff --git a/UniversityDataBaseImplemet/Models/StudentDocument.cs b/UniversityDataBaseImplemet/Models/StudentDocument.cs new file mode 100644 index 0000000..263c6ef --- /dev/null +++ b/UniversityDataBaseImplemet/Models/StudentDocument.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityDataBaseImplemet.Models +{ + public class StudentDocument + { + public int Id { get; set; } + [Required] + public int StudentId { get; set; } + [Required] + public int DocumentId { get; set; } + public virtual Student Student { get; set; } = new(); + public virtual Document Document { get; set; } = new(); + } +} diff --git a/UniversityDataBaseImplemet/UniversityDataBaseImplemet.csproj b/UniversityDataBaseImplemet/UniversityDataBaseImplemet.csproj index 132c02c..e9aeb03 100644 --- a/UniversityDataBaseImplemet/UniversityDataBaseImplemet.csproj +++ b/UniversityDataBaseImplemet/UniversityDataBaseImplemet.csproj @@ -6,4 +6,18 @@ enable + + + + + + + + + + + + + + diff --git a/UniversityModels/Models/IDocumentModel.cs b/UniversityModels/Models/IDocumentModel.cs index 33f093f..408b787 100644 --- a/UniversityModels/Models/IDocumentModel.cs +++ b/UniversityModels/Models/IDocumentModel.cs @@ -10,5 +10,6 @@ namespace UniversityModels.Models { string Name { get; } DateTime Date { get; } + int UserId { get; } } } diff --git a/UniversityModels/Models/IEducationStatusModel.cs b/UniversityModels/Models/IEducationStatusModel.cs index 552ac2c..777b5ef 100644 --- a/UniversityModels/Models/IEducationStatusModel.cs +++ b/UniversityModels/Models/IEducationStatusModel.cs @@ -9,5 +9,6 @@ namespace UniversityModels.Models public interface IEducationStatusModel : IId { string Name { get; } + int UserId { get; } } } diff --git a/UniversityModels/Models/IStudentModel.cs b/UniversityModels/Models/IStudentModel.cs index 6b45b77..01bbb55 100644 --- a/UniversityModels/Models/IStudentModel.cs +++ b/UniversityModels/Models/IStudentModel.cs @@ -13,5 +13,6 @@ namespace UniversityModels.Models DateTime DateOfBirth { get; } int StudentCard { get; } int EducationStatusId { get; } + int UserId { get; } } }