From f281f7a0095ccf067212bc7f4b05fa48b75eb60f Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Fri, 7 Apr 2023 17:44:00 +0400 Subject: [PATCH 1/8] add dictionaries and refactoring --- .../Implements/ActivityStorage.cs | 46 ++++++------- .../Implements/DisciplineStorage.cs | 49 +++++++------- .../Implements/ExaminationResultStorage.cs | 46 ++++++------- .../Implements/ReportTypeStorage.cs | 48 +++++++------- .../Implements/StatementStorage.cs | 65 ++++++++++--------- .../Implements/StudentStorage.cs | 55 +++++++++------- .../DatabaseImplement/Models/Discipline.cs | 4 +- .../Models/ExaminationResult.cs | 2 +- .../DatabaseImplement/Models/ReportType.cs | 2 +- .../DatabaseImplement/Models/Statement.cs | 18 ++++- .../DatabaseImplement/Models/Student.cs | 22 ++++++- 11 files changed, 191 insertions(+), 166 deletions(-) diff --git a/University/DatabaseImplement/Implements/ActivityStorage.cs b/University/DatabaseImplement/Implements/ActivityStorage.cs index d805983..b031bc4 100644 --- a/University/DatabaseImplement/Implements/ActivityStorage.cs +++ b/University/DatabaseImplement/Implements/ActivityStorage.cs @@ -8,30 +8,11 @@ namespace UniversityDatabaseImplement.Implements { internal class ActivityStorage : IActivityStorage { - public ActivityViewModel? Delete(ActivityBindingModel model) + public List GetFullList() { using var context = new UniversityDatabase(); - var element = context.Activities.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Activities.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.Activities.Select(x => x.GetViewModel).ToList(); } - - public ActivityViewModel? GetElement(ActivitySearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - return context.Activities - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public List GetFilteredList(ActivitySearchModel model) { using var context = new UniversityDatabase(); @@ -43,13 +24,16 @@ namespace UniversityDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - public List GetFullList() + public ActivityViewModel? GetElement(ActivitySearchModel model) { + if (!model.Id.HasValue) + { + return null; + } using var context = new UniversityDatabase(); - return context.Activities.Select(x => x.GetViewModel).ToList(); + return context.Activities + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - public ActivityViewModel? Insert(ActivityBindingModel model) { var newActivity = Activity.Create(model); @@ -75,5 +59,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return activity.GetViewModel; } + public ActivityViewModel? Delete(ActivityBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Activities.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Activities.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Implements/DisciplineStorage.cs b/University/DatabaseImplement/Implements/DisciplineStorage.cs index 8e3c4b5..d5a39ff 100644 --- a/University/DatabaseImplement/Implements/DisciplineStorage.cs +++ b/University/DatabaseImplement/Implements/DisciplineStorage.cs @@ -8,31 +8,11 @@ namespace UniversityDatabaseImplement.Implements { internal class DisciplineStorage : IDisciplineStorage { - public DisciplineViewModel? Delete(DisciplineBindingModel model) + public List GetFullList() { using var context = new UniversityDatabase(); - var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.ExaminationResults.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.Disciplines.Select(x => x.GetViewModel).ToList(); } - - public DisciplineViewModel? GetElement(DisciplineSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - return context.Disciplines - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public List GetFilteredList(DisciplineSearchModel model) { using var context = new UniversityDatabase(); @@ -45,13 +25,17 @@ namespace UniversityDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - public List GetFullList() + public DisciplineViewModel? GetElement(DisciplineSearchModel model) { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } using var context = new UniversityDatabase(); - return context.Disciplines.Select(x => x.GetViewModel).ToList(); + return context.Disciplines + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - public DisciplineViewModel? Insert(DisciplineBindingModel model) { var newDiscipline = Discipline.Create(model); @@ -64,7 +48,6 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return newDiscipline.GetViewModel; } - public DisciplineViewModel? Update(DisciplineBindingModel model) { using var context = new UniversityDatabase(); @@ -77,5 +60,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return discipline.GetViewModel; } + public DisciplineViewModel? Delete(DisciplineBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.ExaminationResults.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs index 5882682..86f2495 100644 --- a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs +++ b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs @@ -8,30 +8,11 @@ namespace UniversityDatabaseImplement.Implements { internal class ExaminationResultStorage : IExaminationResultStorage { - public ExaminationResultViewModel? Delete(ExaminationResultBindingModel model) + public List GetFullList() { using var context = new UniversityDatabase(); - var element = context.ExaminationResults.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.ExaminationResults.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.ExaminationResults.Select(x => x.GetViewModel).ToList(); } - - public ExaminationResultViewModel? GetElement(ExaminationResultSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - return context.ExaminationResults - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public List GetFilteredList(ExaminationResultSearchModel model) { using var context = new UniversityDatabase(); @@ -43,13 +24,16 @@ namespace UniversityDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - public List GetFullList() + public ExaminationResultViewModel? GetElement(ExaminationResultSearchModel model) { + if (!model.Id.HasValue) + { + return null; + } using var context = new UniversityDatabase(); - return context.ExaminationResults.Select(x => x.GetViewModel).ToList(); + return context.ExaminationResults + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - public ExaminationResultViewModel? Insert(ExaminationResultBindingModel model) { var newExaminationResult = ExaminationResult.Create(model); @@ -75,5 +59,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return examinationResult.GetViewModel; } + public ExaminationResultViewModel? Delete(ExaminationResultBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.ExaminationResults.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.ExaminationResults.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Implements/ReportTypeStorage.cs b/University/DatabaseImplement/Implements/ReportTypeStorage.cs index bcb57af..8f9b814 100644 --- a/University/DatabaseImplement/Implements/ReportTypeStorage.cs +++ b/University/DatabaseImplement/Implements/ReportTypeStorage.cs @@ -8,31 +8,11 @@ namespace UniversityDatabaseImplement.Implements { internal class ReportTypeStorage : IReportTypeStorage { - public ReportTypeViewModel? Delete(ReportTypeBindingModel model) + public List GetFullList() { using var context = new UniversityDatabase(); - var element = context.ReportTypes.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.ReportTypes.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.ReportTypes.Select(x => x.GetViewModel).ToList(); } - - public ReportTypeViewModel? GetElement(ReportTypeSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - return context.ReportTypes - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public List GetFilteredList(ReportTypeSearchModel model) { using var context = new UniversityDatabase(); @@ -45,13 +25,17 @@ namespace UniversityDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - public List GetFullList() + public ReportTypeViewModel? GetElement(ReportTypeSearchModel model) { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } using var context = new UniversityDatabase(); - return context.ReportTypes.Select(x => x.GetViewModel).ToList(); + return context.ReportTypes + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - public ReportTypeViewModel? Insert(ReportTypeBindingModel model) { var newReportType = ReportType.Create(model); @@ -77,5 +61,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return reportType.GetViewModel; } + public ReportTypeViewModel? Delete(ReportTypeBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.ReportTypes.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.ReportTypes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Implements/StatementStorage.cs b/University/DatabaseImplement/Implements/StatementStorage.cs index 72ed6da..13b5973 100644 --- a/University/DatabaseImplement/Implements/StatementStorage.cs +++ b/University/DatabaseImplement/Implements/StatementStorage.cs @@ -3,24 +3,34 @@ using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace UniversityDatabaseImplement.Implements { internal class StatementStorage : IStatementStorage { - public StatementViewModel? Delete(StatementBindingModel model) + public List GetFullList() { using var context = new UniversityDatabase(); - var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Statements.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; + return context.Statements + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Student) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(StatementSearchModel model) + { + using var context = new UniversityDatabase(); + return context.Statements + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Student) + .Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) + ) + ) + .Select(x => x.GetViewModel) + .ToList(); } - public StatementViewModel? GetElement(StatementSearchModel model) { if (!model.Id.HasValue) @@ -29,27 +39,10 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.Statements - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Student) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - - public List GetFilteredList(StatementSearchModel model) - { - using var context = new UniversityDatabase(); - return context.Statements - .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) - ) - ) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - using var context = new UniversityDatabase(); - return context.Statements.Select(x => x.GetViewModel).ToList(); - } - public StatementViewModel? Insert(StatementBindingModel model) { var newStatement = Statement.Create(model); @@ -75,5 +68,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return statement.GetViewModel; } + public StatementViewModel? Delete(StatementBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Statements.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Implements/StudentStorage.cs b/University/DatabaseImplement/Implements/StudentStorage.cs index e474dfd..c22b540 100644 --- a/University/DatabaseImplement/Implements/StudentStorage.cs +++ b/University/DatabaseImplement/Implements/StudentStorage.cs @@ -3,40 +3,27 @@ using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace UniversityDatabaseImplement.Implements { internal class StudentStorage : IStudentStorage { - public StudentViewModel? Delete(StudentBindingModel model) + public List GetFullList() { - using var context = new UniversityDatabase(); - var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Students.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public StudentViewModel? GetElement(StudentSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } using var context = new UniversityDatabase(); return context.Students - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.ExaminationResult) + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFilteredList(StudentSearchModel model) { using var context = new UniversityDatabase(); return context.Students + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.ExaminationResult) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name)) @@ -45,13 +32,19 @@ namespace UniversityDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - public List GetFullList() + public StudentViewModel? GetElement(StudentSearchModel model) { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } using var context = new UniversityDatabase(); - return context.Students.Select(x => x.GetViewModel).ToList(); + return context.Students + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.ExaminationResult) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } - public StudentViewModel? Insert(StudentBindingModel model) { var newStudent = Student.Create(model); @@ -77,5 +70,17 @@ namespace UniversityDatabaseImplement.Implements context.SaveChanges(); return student.GetViewModel; } + public StudentViewModel? Delete(StudentBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Students.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/University/DatabaseImplement/Models/Discipline.cs b/University/DatabaseImplement/Models/Discipline.cs index 26621db..6aa5679 100644 --- a/University/DatabaseImplement/Models/Discipline.cs +++ b/University/DatabaseImplement/Models/Discipline.cs @@ -10,9 +10,9 @@ namespace UniversityDatabaseImplement.Models { public int Id { get; set; } [Required] - public string Name { get; set; } + public string Name { get; set; } = string.Empty; [Required] - public string Department { get; set; } + public string Department { get; set; } = string.Empty; [ForeignKey("DisciplineId")] public virtual List Statements { get; set; } = new(); [ForeignKey("DisciplineId")] diff --git a/University/DatabaseImplement/Models/ExaminationResult.cs b/University/DatabaseImplement/Models/ExaminationResult.cs index fc29881..bd77bb9 100644 --- a/University/DatabaseImplement/Models/ExaminationResult.cs +++ b/University/DatabaseImplement/Models/ExaminationResult.cs @@ -10,7 +10,7 @@ namespace UniversityDatabaseImplement.Models public class ExaminationResult : IExaminationResultModel { public int Id { get; set; } - public string ExaminationForm { get; set; } + public string ExaminationForm { get; set; } = string.Empty; [Required] public MarkType Mark { get; set; } [Required] diff --git a/University/DatabaseImplement/Models/ReportType.cs b/University/DatabaseImplement/Models/ReportType.cs index acf60ba..50bb684 100644 --- a/University/DatabaseImplement/Models/ReportType.cs +++ b/University/DatabaseImplement/Models/ReportType.cs @@ -10,7 +10,7 @@ namespace UniversityDatabaseImplement.Models { public int Id { get; set; } [Required] - public string Name { get; set; } + public string Name { get; set; } = string.Empty; [ForeignKey("ReportTypeId")] public virtual List ReportTypeActivities { get; set; } = new(); [ForeignKey("ReportTypeId")] diff --git a/University/DatabaseImplement/Models/Statement.cs b/University/DatabaseImplement/Models/Statement.cs index 05655ed..629599d 100644 --- a/University/DatabaseImplement/Models/Statement.cs +++ b/University/DatabaseImplement/Models/Statement.cs @@ -17,6 +17,20 @@ namespace UniversityDatabaseImplement.Models public virtual List StatementStudents { get; set; } = new(); [ForeignKey("StatementId")] public virtual List ExaminationResults { get; set; } = new(); + private Dictionary? _students = null; + public Dictionary Students + { + get + { + if(_students == null) + { + _students = StatementStudents.ToDictionary( + x => x.Student.Id, x => x.Student as IStudentModel); + } + + return _students; + } + } public static Statement Create(StatementBindingModel model) { return new Statement @@ -39,7 +53,9 @@ namespace UniversityDatabaseImplement.Models { Id = Id, Date = Date, - HoursCount = HoursCount + HoursCount = HoursCount, + Students = Students }; + } } diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index d7bff7d..0637590 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -10,13 +10,27 @@ namespace UniversityDatabaseImplement.Models { public int Id { get; set; } [Required] - public string Name { get; set; } + public string Name { get; set; } = string.Empty; [Required] - public string RecordCardNumber { get; set; } + public string RecordCardNumber { get; set; } = string.Empty; [ForeignKey("StudentId")] public virtual List StatementStudents { get; set; } = new(); [ForeignKey("StudentId")] public virtual List StudentExaminationResults { get; set; } = new(); + + private Dictionary? _results; + [NotMapped] + public Dictionary Results { + get { + if(_results == null) + { + _results = StudentExaminationResults.ToDictionary( + x => x.ExaminationResult.Id, x => x.ExaminationResult as IExaminationResultModel); + } + + return _results; + } + } public static Student Create(StudentBindingModel model) { return new Student @@ -39,7 +53,9 @@ namespace UniversityDatabaseImplement.Models { Id = Id, Name = Name, - RecordCardNumber = RecordCardNumber + RecordCardNumber = RecordCardNumber, + Results = Results }; + } } From 7a7a1f2ed3e1f1767fe4f0e3f0de5af23dcaa2ae Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 17:38:26 +0400 Subject: [PATCH 2/8] fix --- University/DatabaseImplement/Implements/DisciplineStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/University/DatabaseImplement/Implements/DisciplineStorage.cs b/University/DatabaseImplement/Implements/DisciplineStorage.cs index d5a39ff..de5a49f 100644 --- a/University/DatabaseImplement/Implements/DisciplineStorage.cs +++ b/University/DatabaseImplement/Implements/DisciplineStorage.cs @@ -66,7 +66,7 @@ namespace UniversityDatabaseImplement.Implements var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.ExaminationResults.Remove(element); + context.Disciplines.Remove(element); context.SaveChanges(); return element.GetViewModel; } From 92cfe7ad61ffb27c55d4fe29e808cb500e2118ac Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 17:38:34 +0400 Subject: [PATCH 3/8] add user --- .../Implements/UserStorage.cs | 78 +++++++++++++++++++ University/DatabaseImplement/Models/User.cs | 62 +++++++++++++++ .../DatabaseImplement/UniversityDatabase.cs | 1 + 3 files changed, 141 insertions(+) create mode 100644 University/DatabaseImplement/Implements/UserStorage.cs create mode 100644 University/DatabaseImplement/Models/User.cs diff --git a/University/DatabaseImplement/Implements/UserStorage.cs b/University/DatabaseImplement/Implements/UserStorage.cs new file mode 100644 index 0000000..1e8b534 --- /dev/null +++ b/University/DatabaseImplement/Implements/UserStorage.cs @@ -0,0 +1,78 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; + +namespace UniversityDatabaseImplement.Implements +{ + internal class UserStorage : IUserStorage + { + public List GetFullList() + { + using var context = new UniversityDatabase(); + return context.Users.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(UserSearchModel model) + { + using var context = new UniversityDatabase(); + return context.Users + .Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Login) || x.Login.Contains(model.Login)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)) + ) + ) + .Select(x => x.GetViewModel) + .ToList(); + } + public UserViewModel? GetElement(UserSearchModel model) + { + if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new UniversityDatabase(); + return context.Users + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) || + (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public UserViewModel? Insert(UserBindingModel model) + { + var newUser = User.Create(model); + if (newUser == null) + { + return null; + } + using var context = new UniversityDatabase(); + context.Users.Add(newUser); + context.SaveChanges(); + return newUser.GetViewModel; + } + public UserViewModel? Update(UserBindingModel model) + { + using var context = new UniversityDatabase(); + var user = context.Users.FirstOrDefault(x => x.Id == model.Id); + if (user == null) + { + return null; + } + user.Update(model); + context.SaveChanges(); + return user.GetViewModel; + } + public UserViewModel? Delete(UserBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Users.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/University/DatabaseImplement/Models/User.cs b/University/DatabaseImplement/Models/User.cs new file mode 100644 index 0000000..f6090e0 --- /dev/null +++ b/University/DatabaseImplement/Models/User.cs @@ -0,0 +1,62 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace UniversityDatabaseImplement.Models +{ + public class User : IUserModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string Surname { get; set; } = string.Empty; + [Required] + public string PhoneNumber { get; set; } = string.Empty; + [Required] + public string Position { get; set; } = string.Empty; + [Required] + public string Login { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + public static User Create(UserBindingModel model) + { + return new User + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + PhoneNumber = model.PhoneNumber, + Position = model.Position, + Login = model.Login, + Password = model.Password + }; + } + + public void Update(UserBindingModel model) + { + if (model == null) return; + + Id = model.Id; + Name = model.Name; + Surname = model.Surname; + PhoneNumber = model.PhoneNumber; + Position = model.Position; + Login = model.Login; + Password = model.Password; + } + + public UserViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + PhoneNumber = PhoneNumber, + Position = Position, + Login = Login, + Password = Password + }; + } +} diff --git a/University/DatabaseImplement/UniversityDatabase.cs b/University/DatabaseImplement/UniversityDatabase.cs index 3c78a0b..7561a59 100644 --- a/University/DatabaseImplement/UniversityDatabase.cs +++ b/University/DatabaseImplement/UniversityDatabase.cs @@ -23,5 +23,6 @@ namespace UniversityDatabaseImplement public virtual DbSet StatementStudents { set; get; } public virtual DbSet Students { set; get; } public virtual DbSet StudentExaminationResults { set; get; } + public virtual DbSet Users { set; get; } } } \ No newline at end of file From d36d38e35310436d4c6771e2a34cb3ac220e189c Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:26:45 +0400 Subject: [PATCH 4/8] change dictionaries in database implement --- .../Implements/StatementStorage.cs | 6 ------ .../Implements/StudentStorage.cs | 6 ++++++ .../DatabaseImplement/Models/Statement.cs | 15 --------------- .../DatabaseImplement/Models/Student.cs | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/University/DatabaseImplement/Implements/StatementStorage.cs b/University/DatabaseImplement/Implements/StatementStorage.cs index 13b5973..25581f5 100644 --- a/University/DatabaseImplement/Implements/StatementStorage.cs +++ b/University/DatabaseImplement/Implements/StatementStorage.cs @@ -13,8 +13,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .Select(x => x.GetViewModel) .ToList(); } @@ -22,8 +20,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) ) @@ -39,8 +35,6 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.Statements - .Include(x => x.StatementStudents) - .ThenInclude(x => x.Student) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public StatementViewModel? Insert(StatementBindingModel model) diff --git a/University/DatabaseImplement/Implements/StudentStorage.cs b/University/DatabaseImplement/Implements/StudentStorage.cs index c22b540..8510a19 100644 --- a/University/DatabaseImplement/Implements/StudentStorage.cs +++ b/University/DatabaseImplement/Implements/StudentStorage.cs @@ -15,6 +15,8 @@ namespace UniversityDatabaseImplement.Implements return context.Students .Include(x => x.StudentExaminationResults) .ThenInclude(x => x.ExaminationResult) + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Statement) .Select(x => x.GetViewModel) .ToList(); } @@ -24,6 +26,8 @@ namespace UniversityDatabaseImplement.Implements return context.Students .Include(x => x.StudentExaminationResults) .ThenInclude(x => x.ExaminationResult) + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Statement) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name)) @@ -42,6 +46,8 @@ namespace UniversityDatabaseImplement.Implements return context.Students .Include(x => x.StudentExaminationResults) .ThenInclude(x => x.ExaminationResult) + .Include(x => x.StatementStudents) + .ThenInclude(x => x.Statement) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } diff --git a/University/DatabaseImplement/Models/Statement.cs b/University/DatabaseImplement/Models/Statement.cs index 629599d..04c4442 100644 --- a/University/DatabaseImplement/Models/Statement.cs +++ b/University/DatabaseImplement/Models/Statement.cs @@ -17,20 +17,6 @@ namespace UniversityDatabaseImplement.Models public virtual List StatementStudents { get; set; } = new(); [ForeignKey("StatementId")] public virtual List ExaminationResults { get; set; } = new(); - private Dictionary? _students = null; - public Dictionary Students - { - get - { - if(_students == null) - { - _students = StatementStudents.ToDictionary( - x => x.Student.Id, x => x.Student as IStudentModel); - } - - return _students; - } - } public static Statement Create(StatementBindingModel model) { return new Statement @@ -54,7 +40,6 @@ namespace UniversityDatabaseImplement.Models Id = Id, Date = Date, HoursCount = HoursCount, - Students = Students }; } diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index 0637590..cfba763 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -31,6 +31,22 @@ namespace UniversityDatabaseImplement.Models return _results; } } + + private Dictionary? _statements; + [NotMapped] + public Dictionary Statements + { + get + { + if (_statements == null) + { + _statements = StatementStudents.ToDictionary( + x => x.Statement.Id, x => x.Statement as IStatementModel); + } + + return _statements; + } + } public static Student Create(StudentBindingModel model) { return new Student @@ -54,7 +70,8 @@ namespace UniversityDatabaseImplement.Models Id = Id, Name = Name, RecordCardNumber = RecordCardNumber, - Results = Results + Results = Results, + Statements = Statements }; } From cc04070287e2feb9937b5ad21a5b01b102b151e3 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 00:18:16 +0400 Subject: [PATCH 5/8] refactoring and add date filter --- .../Implements/ExaminationResultStorage.cs | 16 +++++++++++++--- .../Implements/StatementStorage.cs | 4 +++- .../Implements/StudentStorage.cs | 6 ------ .../Models/ExaminationResult.cs | 16 ++++++++++++++++ University/DatabaseImplement/Models/Student.cs | 15 --------------- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs index 86f2495..94650ec 100644 --- a/University/DatabaseImplement/Implements/ExaminationResultStorage.cs +++ b/University/DatabaseImplement/Implements/ExaminationResultStorage.cs @@ -3,6 +3,7 @@ using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; using UniversityDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace UniversityDatabaseImplement.Implements { @@ -11,14 +12,21 @@ namespace UniversityDatabaseImplement.Implements public List GetFullList() { using var context = new UniversityDatabase(); - return context.ExaminationResults.Select(x => x.GetViewModel).ToList(); + return context.ExaminationResults + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) + .Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(ExaminationResultSearchModel model) { using var context = new UniversityDatabase(); return context.ExaminationResults + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) + (!model.Id.HasValue || x.Id == model.Id) && + (!model.From.HasValue || x.Date >= model.From) && + (!model.To.HasValue || x.Date <= model.To) ) ) .Select(x => x.GetViewModel) @@ -32,7 +40,9 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.ExaminationResults - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + .Include(x => x.StudentExaminationResults) + .ThenInclude(x => x.Student) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public ExaminationResultViewModel? Insert(ExaminationResultBindingModel model) { diff --git a/University/DatabaseImplement/Implements/StatementStorage.cs b/University/DatabaseImplement/Implements/StatementStorage.cs index 25581f5..77a99db 100644 --- a/University/DatabaseImplement/Implements/StatementStorage.cs +++ b/University/DatabaseImplement/Implements/StatementStorage.cs @@ -21,7 +21,9 @@ namespace UniversityDatabaseImplement.Implements using var context = new UniversityDatabase(); return context.Statements .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) + (!model.Id.HasValue || x.Id == model.Id) && + (!model.From.HasValue || x.Date >= model.From) && + (!model.To.HasValue || x.Date <= model.To) ) ) .Select(x => x.GetViewModel) diff --git a/University/DatabaseImplement/Implements/StudentStorage.cs b/University/DatabaseImplement/Implements/StudentStorage.cs index 8510a19..33fc7a7 100644 --- a/University/DatabaseImplement/Implements/StudentStorage.cs +++ b/University/DatabaseImplement/Implements/StudentStorage.cs @@ -13,8 +13,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .Select(x => x.GetViewModel) @@ -24,8 +22,6 @@ namespace UniversityDatabaseImplement.Implements { using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .Where(x => ( @@ -44,8 +40,6 @@ namespace UniversityDatabaseImplement.Implements } using var context = new UniversityDatabase(); return context.Students - .Include(x => x.StudentExaminationResults) - .ThenInclude(x => x.ExaminationResult) .Include(x => x.StatementStudents) .ThenInclude(x => x.Statement) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) || diff --git a/University/DatabaseImplement/Models/ExaminationResult.cs b/University/DatabaseImplement/Models/ExaminationResult.cs index bd77bb9..0ab3285 100644 --- a/University/DatabaseImplement/Models/ExaminationResult.cs +++ b/University/DatabaseImplement/Models/ExaminationResult.cs @@ -19,6 +19,22 @@ namespace UniversityDatabaseImplement.Models public virtual List Activities { get; set; } = new(); [ForeignKey("ExaminationResultId")] public virtual List StudentExaminationResults { get; set; } = new(); + + private Dictionary? _students; + [NotMapped] + public Dictionary Students + { + get + { + if (_students == null) + { + _students = StudentExaminationResults.ToDictionary( + x => x.Student.Id, x => x.Student as IStudentModel); + } + + return _students; + } + } public static ExaminationResult Create(ExaminationResultBindingModel model) { return new ExaminationResult diff --git a/University/DatabaseImplement/Models/Student.cs b/University/DatabaseImplement/Models/Student.cs index cfba763..615ae6d 100644 --- a/University/DatabaseImplement/Models/Student.cs +++ b/University/DatabaseImplement/Models/Student.cs @@ -18,20 +18,6 @@ namespace UniversityDatabaseImplement.Models [ForeignKey("StudentId")] public virtual List StudentExaminationResults { get; set; } = new(); - private Dictionary? _results; - [NotMapped] - public Dictionary Results { - get { - if(_results == null) - { - _results = StudentExaminationResults.ToDictionary( - x => x.ExaminationResult.Id, x => x.ExaminationResult as IExaminationResultModel); - } - - return _results; - } - } - private Dictionary? _statements; [NotMapped] public Dictionary Statements @@ -70,7 +56,6 @@ namespace UniversityDatabaseImplement.Models Id = Id, Name = Name, RecordCardNumber = RecordCardNumber, - Results = Results, Statements = Statements }; 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 6/8] 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 From d07365e746e73d4476c3f3ffd631c215c394bec3 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 01:11:16 +0400 Subject: [PATCH 7/8] add statements in database discipline model --- .../Implements/DisciplineStorage.cs | 9 +++++++-- University/DatabaseImplement/Models/Discipline.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/University/DatabaseImplement/Implements/DisciplineStorage.cs b/University/DatabaseImplement/Implements/DisciplineStorage.cs index de5a49f..4ff387a 100644 --- a/University/DatabaseImplement/Implements/DisciplineStorage.cs +++ b/University/DatabaseImplement/Implements/DisciplineStorage.cs @@ -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 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 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) diff --git a/University/DatabaseImplement/Models/Discipline.cs b/University/DatabaseImplement/Models/Discipline.cs index 6aa5679..3c35ca6 100644 --- a/University/DatabaseImplement/Models/Discipline.cs +++ b/University/DatabaseImplement/Models/Discipline.cs @@ -17,6 +17,21 @@ namespace UniversityDatabaseImplement.Models public virtual List Statements { get; set; } = new(); [ForeignKey("DisciplineId")] public virtual List ReportTypeDisciplines { get; set; } = new(); + private Dictionary? _disciplineStatements; + [NotMapped] + public Dictionary DisciplineStatements + { + get + { + if (_disciplineStatements == null) + { + _disciplineStatements = Statements.ToDictionary( + x => x.Id, x => x as IStatementModel); + } + + return _disciplineStatements; + } + } public static Discipline Create(DisciplineBindingModel model) { From aa08035ab4abdac588168db9b8c934d37def8768 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 01:20:49 +0400 Subject: [PATCH 8/8] make migration --- .../20230408211938_Init.Designer.cs | 497 ++++++++++++++++++ .../Migrations/20230408211938_Init.cs | 384 ++++++++++++++ .../UniversityDatabaseModelSnapshot.cs | 494 +++++++++++++++++ University/University/University.csproj | 11 + 4 files changed, 1386 insertions(+) create mode 100644 University/DatabaseImplement/Migrations/20230408211938_Init.Designer.cs create mode 100644 University/DatabaseImplement/Migrations/20230408211938_Init.cs create mode 100644 University/DatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs diff --git a/University/DatabaseImplement/Migrations/20230408211938_Init.Designer.cs b/University/DatabaseImplement/Migrations/20230408211938_Init.Designer.cs new file mode 100644 index 0000000..ccfeb13 --- /dev/null +++ b/University/DatabaseImplement/Migrations/20230408211938_Init.Designer.cs @@ -0,0 +1,497 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + [Migration("20230408211938_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("ExaminationResultId") + .HasColumnType("integer"); + + b.Property("Number") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExaminationResultId"); + + b.ToTable("Activities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Department") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("ExaminationForm") + .IsRequired() + .HasColumnType("text"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("StatementId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StatementId"); + + b.ToTable("ExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("ReportTypes"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActivityId") + .HasColumnType("integer"); + + b.Property("ReportTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId"); + + b.HasIndex("ReportTypeId"); + + b.ToTable("ReportTypeActivities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("integer"); + + b.Property("ReportTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("ReportTypeId"); + + b.ToTable("ReportTypeDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DisciplineId") + .HasColumnType("integer"); + + b.Property("HoursCount") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("UserId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StatementId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StudentTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StatementId"); + + b.HasIndex("StudentId"); + + b.ToTable("StatementStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecordCardNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ExaminationResultId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExaminationResultId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Position") + .IsRequired() + .HasColumnType("text"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StudentTypeId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.HasIndex("UserId"); + + b.ToTable("UserStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", null) + .WithMany("Activities") + .HasForeignKey("ExaminationResultId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Statement", null) + .WithMany("ExaminationResults") + .HasForeignKey("StatementId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Activity", "Activity") + .WithMany("ReportTypeActivities") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType") + .WithMany("ReportTypeActivities") + .HasForeignKey("ReportTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + + b.Navigation("ReportType"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("ReportTypeDisciplines") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType") + .WithMany("ReportTypeDisciplines") + .HasForeignKey("ReportTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("ReportType"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", null) + .WithMany("Statements") + .HasForeignKey("DisciplineId"); + + b.HasOne("UniversityDatabaseImplement.Models.User", null) + .WithMany("Statements") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Statement", "Statement") + .WithMany("StatementStudents") + .HasForeignKey("StatementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StatementStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Statement"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b => + { + b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", "ExaminationResult") + .WithMany("StudentExaminationResults") + .HasForeignKey("ExaminationResultId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentExaminationResults") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ExaminationResult"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentUsers") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("StudentUsers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.Navigation("ReportTypeActivities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("ReportTypeDisciplines"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.Navigation("Activities"); + + b.Navigation("StudentExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b => + { + b.Navigation("ReportTypeActivities"); + + b.Navigation("ReportTypeDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Navigation("ExaminationResults"); + + b.Navigation("StatementStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("StatementStudents"); + + b.Navigation("StudentExaminationResults"); + + b.Navigation("StudentUsers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Navigation("Statements"); + + b.Navigation("StudentUsers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/DatabaseImplement/Migrations/20230408211938_Init.cs b/University/DatabaseImplement/Migrations/20230408211938_Init.cs new file mode 100644 index 0000000..31afc6e --- /dev/null +++ b/University/DatabaseImplement/Migrations/20230408211938_Init.cs @@ -0,0 +1,384 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Disciplines", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Department = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Disciplines", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ReportTypes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReportTypes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + RecordCardNumber = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Surname = table.Column(type: "text", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: false), + Position = table.Column(type: "text", nullable: false), + Login = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ReportTypeDisciplines", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ReportTypeId = table.Column(type: "integer", nullable: false), + DisciplineId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReportTypeDisciplines", x => x.Id); + table.ForeignKey( + name: "FK_ReportTypeDisciplines_Disciplines_DisciplineId", + column: x => x.DisciplineId, + principalTable: "Disciplines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReportTypeDisciplines_ReportTypes_ReportTypeId", + column: x => x.ReportTypeId, + principalTable: "ReportTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Statements", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "timestamp with time zone", nullable: false), + HoursCount = table.Column(type: "integer", nullable: false), + DisciplineId = table.Column(type: "integer", nullable: true), + UserId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Statements", x => x.Id); + table.ForeignKey( + name: "FK_Statements_Disciplines_DisciplineId", + column: x => x.DisciplineId, + principalTable: "Disciplines", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Statements_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "UserStudents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StudentTypeId = table.Column(type: "integer", nullable: false), + UserId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserStudents", x => x.Id); + table.ForeignKey( + name: "FK_UserStudents_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserStudents_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ExaminationResults", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ExaminationForm = table.Column(type: "text", nullable: false), + Mark = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "timestamp with time zone", nullable: false), + StatementId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ExaminationResults", x => x.Id); + table.ForeignKey( + name: "FK_ExaminationResults_Statements_StatementId", + column: x => x.StatementId, + principalTable: "Statements", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "StatementStudents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StudentTypeId = table.Column(type: "integer", nullable: false), + StatementId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StatementStudents", x => x.Id); + table.ForeignKey( + name: "FK_StatementStudents_Statements_StatementId", + column: x => x.StatementId, + principalTable: "Statements", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_StatementStudents_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Activities", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "timestamp with time zone", nullable: false), + Number = table.Column(type: "integer", nullable: false), + ExaminationResultId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Activities", x => x.Id); + table.ForeignKey( + name: "FK_Activities_ExaminationResults_ExaminationResultId", + column: x => x.ExaminationResultId, + principalTable: "ExaminationResults", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "StudentExaminationResults", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ExaminationResultId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StudentExaminationResults", x => x.Id); + table.ForeignKey( + name: "FK_StudentExaminationResults_ExaminationResults_ExaminationRes~", + column: x => x.ExaminationResultId, + principalTable: "ExaminationResults", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_StudentExaminationResults_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ReportTypeActivities", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ReportTypeId = table.Column(type: "integer", nullable: false), + ActivityId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReportTypeActivities", x => x.Id); + table.ForeignKey( + name: "FK_ReportTypeActivities_Activities_ActivityId", + column: x => x.ActivityId, + principalTable: "Activities", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReportTypeActivities_ReportTypes_ReportTypeId", + column: x => x.ReportTypeId, + principalTable: "ReportTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Activities_ExaminationResultId", + table: "Activities", + column: "ExaminationResultId"); + + migrationBuilder.CreateIndex( + name: "IX_ExaminationResults_StatementId", + table: "ExaminationResults", + column: "StatementId"); + + migrationBuilder.CreateIndex( + name: "IX_ReportTypeActivities_ActivityId", + table: "ReportTypeActivities", + column: "ActivityId"); + + migrationBuilder.CreateIndex( + name: "IX_ReportTypeActivities_ReportTypeId", + table: "ReportTypeActivities", + column: "ReportTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_ReportTypeDisciplines_DisciplineId", + table: "ReportTypeDisciplines", + column: "DisciplineId"); + + migrationBuilder.CreateIndex( + name: "IX_ReportTypeDisciplines_ReportTypeId", + table: "ReportTypeDisciplines", + column: "ReportTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Statements_DisciplineId", + table: "Statements", + column: "DisciplineId"); + + migrationBuilder.CreateIndex( + name: "IX_Statements_UserId", + table: "Statements", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_StatementStudents_StatementId", + table: "StatementStudents", + column: "StatementId"); + + migrationBuilder.CreateIndex( + name: "IX_StatementStudents_StudentId", + table: "StatementStudents", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_StudentExaminationResults_ExaminationResultId", + table: "StudentExaminationResults", + column: "ExaminationResultId"); + + migrationBuilder.CreateIndex( + name: "IX_StudentExaminationResults_StudentId", + table: "StudentExaminationResults", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_UserStudents_StudentId", + table: "UserStudents", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_UserStudents_UserId", + table: "UserStudents", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ReportTypeActivities"); + + migrationBuilder.DropTable( + name: "ReportTypeDisciplines"); + + migrationBuilder.DropTable( + name: "StatementStudents"); + + migrationBuilder.DropTable( + name: "StudentExaminationResults"); + + migrationBuilder.DropTable( + name: "UserStudents"); + + migrationBuilder.DropTable( + name: "Activities"); + + migrationBuilder.DropTable( + name: "ReportTypes"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "ExaminationResults"); + + migrationBuilder.DropTable( + name: "Statements"); + + migrationBuilder.DropTable( + name: "Disciplines"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/University/DatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs b/University/DatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs new file mode 100644 index 0000000..78b5f46 --- /dev/null +++ b/University/DatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs @@ -0,0 +1,494 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + partial class UniversityDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("ExaminationResultId") + .HasColumnType("integer"); + + b.Property("Number") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExaminationResultId"); + + b.ToTable("Activities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Department") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("ExaminationForm") + .IsRequired() + .HasColumnType("text"); + + b.Property("Mark") + .HasColumnType("integer"); + + b.Property("StatementId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StatementId"); + + b.ToTable("ExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("ReportTypes"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActivityId") + .HasColumnType("integer"); + + b.Property("ReportTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId"); + + b.HasIndex("ReportTypeId"); + + b.ToTable("ReportTypeActivities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("integer"); + + b.Property("ReportTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("ReportTypeId"); + + b.ToTable("ReportTypeDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DisciplineId") + .HasColumnType("integer"); + + b.Property("HoursCount") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("UserId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StatementId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StudentTypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StatementId"); + + b.HasIndex("StudentId"); + + b.ToTable("StatementStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecordCardNumber") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ExaminationResultId") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExaminationResultId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Position") + .IsRequired() + .HasColumnType("text"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StudentTypeId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.HasIndex("UserId"); + + b.ToTable("UserStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", null) + .WithMany("Activities") + .HasForeignKey("ExaminationResultId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Statement", null) + .WithMany("ExaminationResults") + .HasForeignKey("StatementId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Activity", "Activity") + .WithMany("ReportTypeActivities") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType") + .WithMany("ReportTypeActivities") + .HasForeignKey("ReportTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + + b.Navigation("ReportType"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("ReportTypeDisciplines") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType") + .WithMany("ReportTypeDisciplines") + .HasForeignKey("ReportTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("ReportType"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", null) + .WithMany("Statements") + .HasForeignKey("DisciplineId"); + + b.HasOne("UniversityDatabaseImplement.Models.User", null) + .WithMany("Statements") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Statement", "Statement") + .WithMany("StatementStudents") + .HasForeignKey("StatementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StatementStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Statement"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b => + { + b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", "ExaminationResult") + .WithMany("StudentExaminationResults") + .HasForeignKey("ExaminationResultId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentExaminationResults") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ExaminationResult"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentUsers") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("StudentUsers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b => + { + b.Navigation("ReportTypeActivities"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("ReportTypeDisciplines"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b => + { + b.Navigation("Activities"); + + b.Navigation("StudentExaminationResults"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b => + { + b.Navigation("ReportTypeActivities"); + + b.Navigation("ReportTypeDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Navigation("ExaminationResults"); + + b.Navigation("StatementStudents"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("StatementStudents"); + + b.Navigation("StudentExaminationResults"); + + b.Navigation("StudentUsers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Navigation("Statements"); + + b.Navigation("StudentUsers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/University/University.csproj b/University/University/University.csproj index b57c89e..b00e6c7 100644 --- a/University/University/University.csproj +++ b/University/University/University.csproj @@ -8,4 +8,15 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file