diff --git a/University/UniversityContracts/BindingModel/AttestationBindingModel.cs b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs similarity index 90% rename from University/UniversityContracts/BindingModel/AttestationBindingModel.cs rename to University/UniversityContracts/BindingModels/AttestationBindingModel.cs index 37408ea..95223d5 100644 --- a/University/UniversityContracts/BindingModel/AttestationBindingModel.cs +++ b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityDataModels.Models; -namespace UniversityContracts.BindingModel +namespace UniversityContracts.BindingModels { public class AttestationBindingModel : IAttestationModel { diff --git a/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs new file mode 100644 index 0000000..1d607b1 --- /dev/null +++ b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.BindingModels +{ + public class DisciplineBindingModel : IDisciplineModel + { + public int Id { get; set; } + public int TeacherId { get; set; } + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + } +} diff --git a/University/UniversityContracts/BindingModel/PlanOfStudyBindingModel.cs b/University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs similarity index 90% rename from University/UniversityContracts/BindingModel/PlanOfStudyBindingModel.cs rename to University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs index 7c81892..5dae649 100644 --- a/University/UniversityContracts/BindingModel/PlanOfStudyBindingModel.cs +++ b/University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UniversityDataModels.Models; -namespace UniversityContracts.BindingModel +namespace UniversityContracts.BindingModels { public class PlanOfStudyBindingModel : IPlanOfStudyModel { diff --git a/University/UniversityContracts/BindingModels/StatementBindingModel.cs b/University/UniversityContracts/BindingModels/StatementBindingModel.cs new file mode 100644 index 0000000..eb9d971 --- /dev/null +++ b/University/UniversityContracts/BindingModels/StatementBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.BindingModels +{ + public class StatementBindingModel : IStatementModel + { + public int Id { get; set; } + public int TeacherId { get; set; } + public string Name { get; set; } = string.Empty; + public DateTime Date { get; } + } +} diff --git a/University/UniversityContracts/BindingModels/StorekeeperBindingModel.cs b/University/UniversityContracts/BindingModels/StorekeeperBindingModel.cs new file mode 100644 index 0000000..a184afc --- /dev/null +++ b/University/UniversityContracts/BindingModels/StorekeeperBindingModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.BindingModels +{ + public class StorekeeperBindingModel : IStorekeeperModel + { + public int Id { get; set; } + public string FirstName { get; set; } = string.Empty; + + public string LastName { get; set; } = string.Empty; + + public string MiddleName { get; set; } = string.Empty; + + public string PhoneNumber { get; set; } = string.Empty; + + public string Email { get; set; } = string.Empty; + } +} diff --git a/University/UniversityContracts/BindingModel/StudentBindingModel.cs b/University/UniversityContracts/BindingModels/StudentBindingModel.cs similarity index 87% rename from University/UniversityContracts/BindingModel/StudentBindingModel.cs rename to University/UniversityContracts/BindingModels/StudentBindingModel.cs index d356a86..a95cc48 100644 --- a/University/UniversityContracts/BindingModel/StudentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -1,6 +1,6 @@ using UniversityDataModels.Models; -namespace UniversityContracts.BindingModel +namespace UniversityContracts.BindingModels { public class StudentBindingModel : IStudentModel { diff --git a/University/UniversityContracts/BindingModels/TeacherBindingModel.cs b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs new file mode 100644 index 0000000..b2bc993 --- /dev/null +++ b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.BindingModels +{ + public class TeacherBindingModel : ITeacherModel + { + public int Id { get; set; } + public int StorekeeperId { get; set; } + public string Name { get; set; } = string.Empty; + public string AcademicDegree { get; set; } = string.Empty; + public string Position { get; set; } = string.Empty; + } +} diff --git a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs index 8fd72fd..7c5db3c 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IAttestationLogic.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/BusinessLogicsContracts/IDisciplineLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IDisciplineLogic.cs new file mode 100644 index 0000000..ce31758 --- /dev/null +++ b/University/UniversityContracts/BusinessLogicsContracts/IDisciplineLogic.cs @@ -0,0 +1,15 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.BusinessLogicsContracts +{ + public interface IDisciplineLogic + { + List? ReadList(DisciplineSearchModel? model); + DisciplineViewModel? ReadElement(DisciplineSearchModel model); + bool Create(DisciplineBindingModel model); + bool Update(DisciplineBindingModel model); + bool Delete(DisciplineBindingModel model); + } +} diff --git a/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs index 3fcdd72..f64ca6f 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IPlanOfStudyLogic.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/BusinessLogicsContracts/IStatementLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IStatementLogic.cs new file mode 100644 index 0000000..9726a67 --- /dev/null +++ b/University/UniversityContracts/BusinessLogicsContracts/IStatementLogic.cs @@ -0,0 +1,15 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.BusinessLogicsContracts +{ + public interface IStatementLogic + { + List? ReadList(StatementSearchModel? model); + StatementViewModel? ReadElement(StatementSearchModel model); + bool Create(StatementBindingModel model); + bool Update(StatementBindingModel model); + bool Delete(StatementBindingModel model); + } +} diff --git a/University/UniversityContracts/BusinessLogicsContracts/IStudentLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IStudentLogic.cs index 8550b80..12b37d7 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IStudentLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IStudentLogic.cs @@ -1,4 +1,4 @@ -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/BusinessLogicsContracts/ITeacherLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/ITeacherLogic.cs new file mode 100644 index 0000000..e66f177 --- /dev/null +++ b/University/UniversityContracts/BusinessLogicsContracts/ITeacherLogic.cs @@ -0,0 +1,15 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.BusinessLogicsContracts +{ + public interface ITeacherLogic + { + List? ReadList(TeacherSearchModel? model); + TeacherViewModel? ReadElement(TeacherSearchModel model); + bool Create(TeacherBindingModel model); + bool Update(TeacherBindingModel model); + bool Delete(TeacherBindingModel model); + } +} diff --git a/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs new file mode 100644 index 0000000..998b4a1 --- /dev/null +++ b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.SearchModels +{ + public class DisciplineSearchModel + { + public int? TeacherId { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + } +} diff --git a/University/UniversityContracts/SearchModels/StatementSearchModel.cs b/University/UniversityContracts/SearchModels/StatementSearchModel.cs new file mode 100644 index 0000000..6070faf --- /dev/null +++ b/University/UniversityContracts/SearchModels/StatementSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.SearchModels +{ + public class StatementSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public DateTime? Date { get; set; } + } +} diff --git a/University/UniversityContracts/SearchModels/TeacherSearchModel.cs b/University/UniversityContracts/SearchModels/TeacherSearchModel.cs new file mode 100644 index 0000000..d91bd71 --- /dev/null +++ b/University/UniversityContracts/SearchModels/TeacherSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.SearchModels +{ + public class TeacherSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public string? AcademicDegree { get; set; } + public string? Position { get; set; } + } +} diff --git a/University/UniversityContracts/StorageContracts/IAttestationStorage.cs b/University/UniversityContracts/StorageContracts/IAttestationStorage.cs index fab43f2..2b1856c 100644 --- a/University/UniversityContracts/StorageContracts/IAttestationStorage.cs +++ b/University/UniversityContracts/StorageContracts/IAttestationStorage.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs b/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs new file mode 100644 index 0000000..ab18309 --- /dev/null +++ b/University/UniversityContracts/StorageContracts/IDisciplineStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.StorageContracts +{ + public interface IDisciplineStorage + { + List GetFullList(); + List GetFilteredList(DisciplineSearchModel model); + DisciplineViewModel? GetElement(DisciplineSearchModel model); + DisciplineViewModel? Insert(DisciplineBindingModel model); + DisciplineViewModel? Update(DisciplineBindingModel model); + DisciplineViewModel? Delete(DisciplineBindingModel model); + } +} diff --git a/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs b/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs index 0c36c8f..a02307d 100644 --- a/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs +++ b/University/UniversityContracts/StorageContracts/IPlanOfStudyStorage.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/StorageContracts/IStatementStorage.cs b/University/UniversityContracts/StorageContracts/IStatementStorage.cs new file mode 100644 index 0000000..a4ba5e5 --- /dev/null +++ b/University/UniversityContracts/StorageContracts/IStatementStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.StorageContracts +{ + public interface IStatementStorage + { + List GetFullList(); + List GetFilteredList(StatementSearchModel model); + StatementViewModel? GetElement(StatementSearchModel model); + StatementViewModel? Insert(StatementBindingModel model); + StatementViewModel? Update(StatementBindingModel model); + StatementViewModel? Delete(StatementBindingModel model); + } +} diff --git a/University/UniversityContracts/StorageContracts/IStudentStorage.cs b/University/UniversityContracts/StorageContracts/IStudentStorage.cs index c6e36f3..edaa158 100644 --- a/University/UniversityContracts/StorageContracts/IStudentStorage.cs +++ b/University/UniversityContracts/StorageContracts/IStudentStorage.cs @@ -1,4 +1,4 @@ -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.ViewModels; diff --git a/University/UniversityContracts/StorageContracts/ITeacherStorage.cs b/University/UniversityContracts/StorageContracts/ITeacherStorage.cs new file mode 100644 index 0000000..a7f0ae8 --- /dev/null +++ b/University/UniversityContracts/StorageContracts/ITeacherStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.StorageContracts +{ + public interface ITeacherStorage + { + List GetFullList(); + List GetFilteredList(TeacherSearchModel model); + TeacherViewModel? GetElement(TeacherSearchModel model); + TeacherViewModel? Insert(TeacherBindingModel model); + TeacherViewModel? Update(TeacherBindingModel model); + TeacherViewModel? Delete(TeacherBindingModel model); + } +} diff --git a/University/UniversityContracts/ViewModels/DisciplineViewModel.cs b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs new file mode 100644 index 0000000..3d9be8e --- /dev/null +++ b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.ViewModels +{ + public class DisciplineViewModel : IDisciplineModel + { + public int Id { get; set; } + public int TeacherId { get; set; } + [DisplayName("Название дисциплины")] + public string Name { get; set; } = string.Empty; + [DisplayName("Описание дисциплины")] + public string Description { get; set; } = string.Empty; + } +} diff --git a/University/UniversityContracts/ViewModels/StatementViewModel.cs b/University/UniversityContracts/ViewModels/StatementViewModel.cs new file mode 100644 index 0000000..0ae8823 --- /dev/null +++ b/University/UniversityContracts/ViewModels/StatementViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.ViewModels +{ + public class StatementViewModel : IStatementModel + { + public int Id { get; set; } + public int TeacherId { get; set; } + [DisplayName("Название ведомости")] + public string Name { get; set; } = string.Empty; + [DisplayName("Дата оформления ведомости")] + public DateTime Date { get; set; } + } +} diff --git a/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs b/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs new file mode 100644 index 0000000..4082034 --- /dev/null +++ b/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.ViewModels +{ + public class StorekeeperViewModel : IStorekeeperModel + { + public int Id { get; set; } + [DisplayName("Имя")] + public string FirstName { get; set; } = string.Empty; + [DisplayName("Фамилия")] + public string LastName { get; set; } = string.Empty; + [DisplayName("Отчество")] + public string MiddleName { get; set; } = string.Empty; + [DisplayName("Номер телефона")] + public string PhoneNumber { get; set; } = string.Empty; + [DisplayName("Почта")] + public string Email { get; set; } = string.Empty; + } +} diff --git a/University/UniversityContracts/ViewModels/TeacherViewModel.cs b/University/UniversityContracts/ViewModels/TeacherViewModel.cs new file mode 100644 index 0000000..522e3f5 --- /dev/null +++ b/University/UniversityContracts/ViewModels/TeacherViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityContracts.ViewModels +{ + public class TeacherViewModel : ITeacherModel + { + public int Id { get; set; } + public int StorekeeperId { get; set; } + [DisplayName("ФИО")] + public string Name { get; set; } = string.Empty; + [DisplayName("Учёная степень")] + public string AcademicDegree { get; set; } = string.Empty; + [DisplayName("Должность")] + public string Position { get; set; } = string.Empty; + } +} diff --git a/University/UniversityDataModels/Models/IDisciplineModel.cs b/University/UniversityDataModels/Models/IDisciplineModel.cs index d1bb666..f24b7f8 100644 --- a/University/UniversityDataModels/Models/IDisciplineModel.cs +++ b/University/UniversityDataModels/Models/IDisciplineModel.cs @@ -3,7 +3,7 @@ public interface IDisciplineModel : IId { int TeacherId { get; } - string Name { get; set; } - string Description { get; set; } + string Name { get; } + string Description { get; } } } diff --git a/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs new file mode 100644 index 0000000..f8f86bd --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityDatabaseImplement.Implements +{ + public class DisciplineStorage + { + } +} diff --git a/University/UniversityDatabaseImplement/Implements/StatementStorage.cs b/University/UniversityDatabaseImplement/Implements/StatementStorage.cs new file mode 100644 index 0000000..f3211e7 --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/StatementStorage.cs @@ -0,0 +1,85 @@ +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.StorageContracts; +using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; + +namespace UniversityDatabaseImplement.Implements +{ + public class StatementStorage: IStatementStorage + { + public StatementViewModel? GetElement(StatementSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new UniversityDatabase(); + return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(StatementSearchModel model) + { + if (!model.Id.HasValue && !model.Date.HasValue) + { + return new(); + } + using var context = new UniversityDatabase(); + return context.Statements + .Where(x => x.Id == model.Id || model.Date <= x.Date) + .Include(x => x.Teacher) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new UniversityDatabase(); + return context.Statements.Include(x => x.Teacher).Select(x => x.GetViewModel).ToList(); + } + + public StatementViewModel? Insert(StatementBindingModel model) + { + var newStatement = Statement.Create(model); + if (newStatement == null) + { + return null; + } + using var context = new UniversityDatabase(); + context.Statements.Add(newStatement); + context.SaveChanges(); + return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => x.Id == newStatement.Id)?.GetViewModel; + } + + public StatementViewModel? Update(StatementBindingModel model) + { + using var context = new UniversityDatabase(); + var order = context.Statements.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Statements.Include(x => x.Teacher).FirstOrDefault(x => x.Id == model.Id)?.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/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs b/University/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs new file mode 100644 index 0000000..a65f2a6 --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityDatabaseImplement.Implements +{ + public class StorekeeperStorage + { + } +} diff --git a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs new file mode 100644 index 0000000..4273379 --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StorageContracts; +using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; +// TODO +namespace UniversityDatabaseImplement.Implements +{ + public class TeacherStorage: ITeacherStorage + { + public List GetFullList() + { + using var context = new UniversityDatabase(); + return context.Teachers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(TeacherSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + using var context = new UniversityDatabase(); + return context.Teachers + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); + } + public TeacherViewModel? GetElement(TeacherSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new UniversityDatabase(); + return context.Teachers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public TeacherViewModel? Insert(TeacherBindingModel model) + { + var newTeacher = Teacher.Create(model); + if (newTeacher == null) + { + return null; + } + using var context = new UniversityDatabase(); + context.Teachers.Add(newTeacher); + context.SaveChanges(); + return newTeacher.GetViewModel; + } + public TeacherViewModel? Update(TeacherBindingModel model) + { + using var context = new UniversityDatabase(); + var component = context.Teachers.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + public TeacherViewModel? Delete(TeacherBindingModel model) + { + using var context = new UniversityDatabase(); + var element = context.Teachers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Teachers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/University/UniversityDatabaseImplement/Models/Discipline.cs b/University/UniversityDatabaseImplement/Models/Discipline.cs new file mode 100644 index 0000000..bf95e1a --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Discipline.cs @@ -0,0 +1,69 @@ +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 UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Discipline : IDisciplineModel + { + public int Id { get; private set; } + [Required] + public int TeacherId { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string Description { get; private set; } = string.Empty; + public virtual Teacher Teacher { get; set; } = new(); + [ForeignKey("DisciplineId")] + public virtual List StudentDiscipline { get; set; } = new(); + public static Discipline? Create(DisciplineBindingModel model) + { + if (model == null) + { + return null; + } + return new Discipline() + { + Id = model.Id, + TeacherId = model.TeacherId, + Name = model.Name, + Description = model.Description, + }; + } + public static Discipline Create(DisciplineViewModel model) + { + return new Discipline() + { + Id = model.Id, + TeacherId = model.TeacherId, + Name = model.Name, + Description = model.Description, + }; + } + public void Update(DisciplineBindingModel model) + { + if (model == null) + { + return; + } + Id = model.Id; + TeacherId = model.TeacherId; + Name = model.Name; + Description = model.Description; + } + public DisciplineViewModel GetViewModel => new() + { + Id = Id, + TeacherId = TeacherId, + Name = Name, + Description = Description, + }; + } +} diff --git a/University/UniversityDatabaseImplement/Models/Statement.cs b/University/UniversityDatabaseImplement/Models/Statement.cs new file mode 100644 index 0000000..4225b0b --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Statement.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Statement : IStatementModel + { + public int Id { get; private set; } + [Required] + public int TeacherId { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public DateTime Date { get; private set; } + public virtual Teacher Teacher { get; set; } = new (); + public static Statement? Create(StatementBindingModel model) + { + if (model == null) + { + return null; + } + return new Statement() + { + Id = model.Id, + TeacherId = model.TeacherId, + Name = model.Name, + Date = model.Date, + }; + } + public static Statement Create(StatementViewModel model) + { + return new Statement() + { + Id = model.Id, + TeacherId = model.TeacherId, + Name = model.Name, + Date = model.Date, + }; + } + public void Update(StatementBindingModel model) + { + if (model == null) + { + return; + } + Id = model.Id; + TeacherId = model.Id; + Name = model.Name; + Date = model.Date; + } + public StatementViewModel GetViewModel => new() + { + Id = Id, + TeacherId = TeacherId, + Name = Name, + Date = Date, + }; + } +} diff --git a/University/UniversityDatabaseImplement/Models/Storekeeper.cs b/University/UniversityDatabaseImplement/Models/Storekeeper.cs new file mode 100644 index 0000000..e25b3e7 --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Storekeeper.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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 UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Storekeeper : IStorekeeperModel + { + public int Id { get; private set; } + [Required] + public string FirstName { get; private set; } = string.Empty; + [Required] + public string LastName { get; private set; } = string.Empty; + [Required] + public string MiddleName { get; private set; } = string.Empty; + [Required] + public string PhoneNumber { get; private set; } = string.Empty; + [Required] + public string Email { get; private set; } = string.Empty; + [ForeignKey("StorekeeperId")] + public virtual List Teachers { get; set; } = new(); + public static Storekeeper? Create(StorekeeperBindingModel model) + { + if (model == null) + { + return null; + } + return new Storekeeper() + { + Id = model.Id, + FirstName = model.FirstName, + LastName = model.LastName, + MiddleName = model.MiddleName, + PhoneNumber = model.PhoneNumber, + Email = model.Email, + + }; + } + public static Storekeeper Create(StorekeeperViewModel model) + { + return new Storekeeper + { + Id = model.Id, + FirstName = model.FirstName, + LastName = model.LastName, + MiddleName = model.MiddleName, + PhoneNumber = model.PhoneNumber, + Email = model.Email, + }; + } + public void Update(StorekeeperBindingModel model) + { + if (model == null) + { + return; + } + Id = model.Id; + FirstName = model.FirstName; + LastName = model.LastName; + MiddleName = model.MiddleName; + PhoneNumber = model.PhoneNumber; + Email = model.Email; + } + public StorekeeperViewModel GetViewModel => new() + { + Id = Id, + FirstName = FirstName, + LastName = LastName, + MiddleName = MiddleName, + PhoneNumber = PhoneNumber, + Email = Email, + }; + + } +} diff --git a/University/UniversityDatabaseImplement/Models/Student.cs b/University/UniversityDatabaseImplement/Models/Student.cs index ad7b13d..4753193 100644 --- a/University/UniversityDatabaseImplement/Models/Student.cs +++ b/University/UniversityDatabaseImplement/Models/Student.cs @@ -2,10 +2,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; -using UniversityContracts.BindingModel; +using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; using UniversityDataModels.Models; @@ -19,7 +20,8 @@ namespace UniversityDatabaseImplement.Models public string Name { get; set; } = string.Empty; [Required] public string PhoneNumber { get; private set; } = string.Empty; - + [ForeignKey("StudentId")] + public virtual List StudentDiscipline { get; set; } = new(); public static Student? Create(StudentBindingModel model) { if (model == null) diff --git a/University/UniversityDatabaseImplement/Models/StudentDiscipline.cs b/University/UniversityDatabaseImplement/Models/StudentDiscipline.cs new file mode 100644 index 0000000..6a135b7 --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/StudentDiscipline.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 UniversityDatabaseImplement.Models +{ + public class StudentDiscipline + { + public int Id { get; set; } + [Required] + public int StudentId { get; set; } + [Required] + public int DisciplineId { get; set; } + public virtual Student Student { get; set; } = new (); + public virtual Discipline Discipline { get; set; } = new(); + } +} diff --git a/University/UniversityDatabaseImplement/Models/Teacher.cs b/University/UniversityDatabaseImplement/Models/Teacher.cs new file mode 100644 index 0000000..f19fdae --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Teacher.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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 UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Teacher : ITeacherModel + { + public int Id { get; private set; } + [Required] + public int StorekeeperId { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string AcademicDegree { get; private set; } = string.Empty; + [Required] + public string Position { get; private set; } = string.Empty; + public virtual Storekeeper Storekeeper { get; set; } = new (); + [ForeignKey("TeacherId")] + public virtual List Statement { get; set; } = new(); + [ForeignKey("TeacherId")] + public virtual List Discipline { get; set; } = new(); + public static Teacher? Create(TeacherBindingModel model) + { + if (model == null) + { + return null; + } + return new Teacher() + { + Id = model.Id, + StorekeeperId = model.StorekeeperId, + Name = model.Name, + AcademicDegree = model.AcademicDegree, + Position = model.Position, + }; + } + public static Teacher Create(TeacherViewModel model) + { + return new Teacher() + { + Id = model.Id, + StorekeeperId = model.StorekeeperId, + Name = model.Name, + AcademicDegree = model.AcademicDegree, + Position = model.Position, + }; + } + public void Update(TeacherBindingModel model) + { + if (model == null) + { + return; + } + Id = model.Id; + StorekeeperId = model.StorekeeperId; + Name = model.Name; + AcademicDegree = model.AcademicDegree; + Position = model.Position; + } + public TeacherViewModel GetViewModel => new() + { + Id = Id, + StorekeeperId = StorekeeperId, + Name = Name, + AcademicDegree = AcademicDegree, + Position = Position, + }; + } +} diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 278cf7d..30a3235 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,8 @@ namespace UniversityDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=PlumbingRepairDatabaseFull;Username=postgres;Password=postgres"); + //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR + optionsBuilder.UseSqlServer(@"Data Source=(localdb)\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -19,6 +20,9 @@ namespace UniversityDatabaseImplement public virtual DbSet PlansOfStudy { set; get; } public virtual DbSet Attestations { set; get; } // public virtual DbSet Workers { set; get; } - // public virtual DbSet Storekeepers { set; get; } + public virtual DbSet Storekeepers { set; get; } + public virtual DbSet Teachers { set; get; } + public virtual DbSet Disciplines { set; get; } + public virtual DbSet Statements { set; get; } } }