diff --git a/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs index 8d9cc03..cba9f81 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/AttestationLogic.cs @@ -127,13 +127,17 @@ namespace UniversityBusinessLogic.BusinessLogics { throw new ArgumentNullException("Не выбрана форма оценивания", nameof(model.FormOfEvaluation)); } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } if (model.StudentId <= 0) { throw new ArgumentNullException("Некорректный идентификатор студента", nameof(model.StudentId)); } - _logger.LogInformation("Attestation. AttestationId:{Id}.FormOfEvaluation:{FormOfEvaluation}. StudentId: { StudentId}", - model.Id, model.FormOfEvaluation, model.StudentId); + _logger.LogInformation("Attestation. AttestationId:{Id}.FormOfEvaluation:{FormOfEvaluation}. StudentId: {StudentId}. UserId: {UserId}", + model.Id, model.FormOfEvaluation, model.StudentId, model.UserId); } } } diff --git a/University/UniversityBusinessLogic/BusinessLogics/DisciplineLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/DisciplineLogic.cs index 6c62dd7..15f563c 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/DisciplineLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/DisciplineLogic.cs @@ -97,8 +97,12 @@ namespace UniversityBusinessLogic.BusinessLogics { throw new ArgumentNullException("Должна быть дисциплина", nameof(model.Description)); } - _logger.LogInformation("Discipline. Name:{Name}.Description:{Description}. Id: {Id}", - model.Name, model.Description, model.Id); + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } + _logger.LogInformation("Discipline. Name:{Name}.Description:{Description}. UserId: {UserId}. Id: {Id}", + model.Name, model.Description, model.UserId, model.Id); var element = _disciplineStorage.GetElement(new DisciplineSearchModel { Name = model.Name diff --git a/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs index 194f4b0..82a0f95 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/PlanOfStudyLogic.cs @@ -103,8 +103,12 @@ namespace UniversityBusinessLogic.BusinessLogics { throw new ArgumentNullException("Не указана форма обучения", nameof(model.FormOfStudy)); } - _logger.LogInformation("Student. Profile:{Profile}.FormOfStudy:{FormOfStudy}. Id: {Id}", - model.Profile, model.FormOfStudy, model.Id); + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } + _logger.LogInformation("Student. Profile:{Profile}.FormOfStudy:{FormOfStudy}. UserId: {UserId}. Id: {Id}", + model.Profile, model.FormOfStudy, model.UserId, model.Id); var element = _planOfStudyStorage.GetElement(new PlanOfStudySearchModel { Profile = model.Profile diff --git a/University/UniversityBusinessLogic/BusinessLogics/StatementLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/StatementLogic.cs index 9f4412f..abbc774 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/StatementLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/StatementLogic.cs @@ -107,8 +107,12 @@ namespace UniversityBusinessLogic.BusinessLogics { throw new ArgumentNullException("Некорректный идентификатор преподавателя", nameof(model.TeacherId)); } - _logger.LogInformation("Statement. StatementId:{Id}.Name:{Name}. TeacherId: { TeacherId}", - model.Id, model.Name, model.TeacherId); + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } + _logger.LogInformation("Statement. StatementId:{Id}.Name:{Name}. TeacherId: {TeacherId}. UserId: {UserId}", + model.Id, model.Name, model.TeacherId, model.UserId); } } } diff --git a/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs index 129ffbc..be68706 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs @@ -98,8 +98,12 @@ namespace UniversityBusinessLogic.BusinessLogics { throw new ArgumentNullException("Должен быть номер телефона", nameof(model.PhoneNumber)); } - _logger.LogInformation("Student. Name:{Name}.PhoneNumber:{PhoneNumber}. Id: {Id}", - model.Name, model.PhoneNumber, model.Id); + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } + _logger.LogInformation("Student. Name:{Name}.PhoneNumber:{PhoneNumber}. UserId: {UserId}. Id: {Id}", + model.Name, model.PhoneNumber, model.UserId, model.Id); var element = _studentStorage.GetElement(new StudentSearchModel { Name = model.Name diff --git a/University/UniversityBusinessLogic/BusinessLogics/TeacherLogic .cs b/University/UniversityBusinessLogic/BusinessLogics/TeacherLogic .cs index 15baa7a..8afcc9c 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/TeacherLogic .cs +++ b/University/UniversityBusinessLogic/BusinessLogics/TeacherLogic .cs @@ -108,8 +108,12 @@ namespace UniversityBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет должности", nameof(model.Position)); } - _logger.LogInformation("Teacher. Name:{Name}.AcademicDegree:{AcademicDegree}. Position:{Position}. Id: {Id}", - model.Name, model.AcademicDegree, model.Position, model.Id); + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", nameof(model.UserId)); + } + _logger.LogInformation("Teacher. Name:{Name}.AcademicDegree:{AcademicDegree}. Position:{Position}. UserId: {UserId}. Id: {Id}", + model.Name, model.AcademicDegree, model.Position, model.UserId, model.Id); var element = _teacherStorage.GetElement(new TeacherSearchModel { Name = model.Name diff --git a/University/UniversityBusinessLogic/BusinessLogics/UserLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/UserLogic.cs new file mode 100644 index 0000000..6df44e4 --- /dev/null +++ b/University/UniversityBusinessLogic/BusinessLogics/UserLogic.cs @@ -0,0 +1,131 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicsContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StorageContracts; +using UniversityContracts.ViewModels; +using UniversityDataModels.Enums; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class UserLogic : IUserLogic + { + private readonly ILogger _logger; + private readonly IUserStorage _userStorage; + + public UserLogic(ILogger logger, IUserStorage userStorage) + { + _logger = logger; + _userStorage = userStorage; + } + public List? ReadList(UserSearchModel? model) + { + _logger.LogInformation("User ReadList. Login:{Login} Emain:{Email} Id:{Id}", model?.Login, model?.Email, model?.Id); + var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public UserViewModel? ReadElement(UserSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login:{Login}. Email:{Email}. Id:{Id}", model?.Login, model?.Email, model?.Id); + var element = _userStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(UserBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_userStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(UserBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + var user1 = _userStorage.GetElement(new UserSearchModel + { + Login = model.Login + }); + + if (user1 != null && user1.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким логином уже есть"); + } + var user2 = _userStorage.GetElement(new UserSearchModel + { + Email = model.Email + }); + + if (user2 != null && user2.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с такой почтой уже есть"); + } + } + } +} diff --git a/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs deleted file mode 100644 index 0c9cae7..0000000 --- a/University/UniversityBusinessLogic/BusinessLogics/WorkerLogic.cs +++ /dev/null @@ -1,135 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UniversityContracts.BindingModels; -using UniversityContracts.BusinessLogicsContracts; -using UniversityContracts.SearchModels; -using UniversityContracts.StorageContracts; -using UniversityContracts.ViewModels; -using UniversityDataModels.Enums; - -namespace UniversityBusinessLogic.BusinessLogics -{ - public class WorkerLogic : IWorkerLogic - { - private readonly ILogger _logger; - private readonly IWorkerStorage _workerStorage; - public WorkerLogic(ILogger logger, IWorkerStorage - workerStorage) - { - _logger = logger; - _workerStorage = workerStorage; - } - public List? ReadList(WorkerSearchModel? model) - { - _logger.LogInformation("ReadList. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: {PhoneNumber}" + - "Email: {Email}.Id:{Id} ", - model?.FirstName, model?.LastName, model?.PhoneNumber, model?.Email, model?.Id); - var list = model == null ? _workerStorage.GetFullList() : - _workerStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public WorkerViewModel? ReadElement(WorkerSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadList. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: {PhoneNumber}" + - "Email: {Email}.Id:{Id} ", - model?.FirstName, model?.LastName, model?.PhoneNumber, model?.Email, model?.Id); - var element = _workerStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - public bool Create(WorkerBindingModel model) - { - CheckModel(model); - if (_workerStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(WorkerBindingModel model) - { - CheckModel(model); - if (_workerStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(WorkerBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_workerStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(WorkerBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.FirstName)) - { - throw new ArgumentNullException("Нет имени пользователя", - nameof(model.FirstName)); - } - if (string.IsNullOrEmpty(model.LastName)) - { - throw new ArgumentNullException("Нет фамилии пользователя", - nameof(model.LastName)); - } - if (string.IsNullOrEmpty(model.PhoneNumber)) - { - throw new ArgumentNullException("Должен быть номер телефона", nameof(model.PhoneNumber)); - } - if (string.IsNullOrEmpty(model.Email)) - { - throw new ArgumentNullException("Не указана почта", - nameof(model.Email)); - } - _logger.LogInformation("Worker. FirstName: {FirstName}.LastName: {LastName}. PhoneNumber: " + - "{PhoneNumber}.Email: {Email}.Id:{Id}", - model.FirstName, model.LastName, model.PhoneNumber, model.Email, model.Id); - var element = _workerStorage.GetElement(new WorkerSearchModel - { - FirstName = model.FirstName, - LastName = model.LastName, - PhoneNumber = model.PhoneNumber, - Email = model.Email - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Данный пользователь уже существует"); - } - } - } -} diff --git a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs index f85ab83..8a23be6 100644 --- a/University/UniversityContracts/BindingModels/AttestationBindingModel.cs +++ b/University/UniversityContracts/BindingModels/AttestationBindingModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.BindingModels public class AttestationBindingModel : IAttestationModel { public int Id { get; set; } + public int UserId { get; set; } public string FormOfEvaluation { get; set; } = string.Empty; public AttestationScore Score { get; set; } = AttestationScore.Неявка; public int StudentId { get; set; } diff --git a/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs index c49d61a..fe848f8 100644 --- a/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs +++ b/University/UniversityContracts/BindingModels/DisciplineBindingModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.BindingModels public class DisciplineBindingModel : IDisciplineModel { public int Id { get; set; } + public int UserId { 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/BindingModels/PlanOfStudyBindingModel.cs b/University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs index a2be402..cc3e2a8 100644 --- a/University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs +++ b/University/UniversityContracts/BindingModels/PlanOfStudyBindingModel.cs @@ -10,6 +10,7 @@ namespace UniversityContracts.BindingModels public class PlanOfStudyBindingModel : IPlanOfStudyModel { public int Id { get; set; } + public int UserId { get; set; } public string Profile { get; set; } = string.Empty; public string FormOfStudy { get; set; } = string.Empty; public int WorkerId { get; set; } diff --git a/University/UniversityContracts/BindingModels/StatementBindingModel.cs b/University/UniversityContracts/BindingModels/StatementBindingModel.cs index eb9d971..2c787e4 100644 --- a/University/UniversityContracts/BindingModels/StatementBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StatementBindingModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.BindingModels public class StatementBindingModel : IStatementModel { public int Id { get; set; } + public int UserId { 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 deleted file mode 100644 index a184afc..0000000 --- a/University/UniversityContracts/BindingModels/StorekeeperBindingModel.cs +++ /dev/null @@ -1,23 +0,0 @@ -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/BindingModels/StudentBindingModel.cs b/University/UniversityContracts/BindingModels/StudentBindingModel.cs index a95cc48..748c58b 100644 --- a/University/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/University/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -5,6 +5,7 @@ namespace UniversityContracts.BindingModels public class StudentBindingModel : IStudentModel { public int Id { get; set; } + public int UserId { get; set; } public int PlanOfStudyId { get; set; } public string Name { get; set; } = string.Empty; public string PhoneNumber { get; set; } = string.Empty; diff --git a/University/UniversityContracts/BindingModels/TeacherBindingModel.cs b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs index b2bc993..75d6955 100644 --- a/University/UniversityContracts/BindingModels/TeacherBindingModel.cs +++ b/University/UniversityContracts/BindingModels/TeacherBindingModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.BindingModels public class TeacherBindingModel : ITeacherModel { public int Id { get; set; } + public int UserId { get; set; } public int StorekeeperId { get; set; } public string Name { get; set; } = string.Empty; public string AcademicDegree { get; set; } = string.Empty; diff --git a/University/UniversityContracts/BindingModels/WorkerBindingModel.cs b/University/UniversityContracts/BindingModels/UserBindingModel.cs similarity index 50% rename from University/UniversityContracts/BindingModels/WorkerBindingModel.cs rename to University/UniversityContracts/BindingModels/UserBindingModel.cs index ff76328..4861f3f 100644 --- a/University/UniversityContracts/BindingModels/WorkerBindingModel.cs +++ b/University/UniversityContracts/BindingModels/UserBindingModel.cs @@ -3,17 +3,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.Enums; using UniversityDataModels.Models; namespace UniversityContracts.BindingModels { - public class WorkerBindingModel : IWorkerModel + public class UserBindingModel : IUserModel { 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 Login { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; + public UserRole Role { get; set; } = UserRole.Неизвестная; } } diff --git a/University/UniversityContracts/BusinessLogicsContracts/IStorekeeperLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IStorekeeperLogic.cs deleted file mode 100644 index b051e94..0000000 --- a/University/UniversityContracts/BusinessLogicsContracts/IStorekeeperLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -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.BusinessLogicsContracts -{ - public interface IStorekeeperLogic - { - List? ReadList(StorekeeperSearchModel? model); - StorekeeperViewModel? ReadElement(StorekeeperSearchModel model); - bool Create(StorekeeperBindingModel model); - bool Update(StorekeeperBindingModel model); - bool Delete(StorekeeperBindingModel model); - } -} diff --git a/University/UniversityContracts/BusinessLogicsContracts/IWorkerLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IUserLogic.cs similarity index 50% rename from University/UniversityContracts/BusinessLogicsContracts/IWorkerLogic.cs rename to University/UniversityContracts/BusinessLogicsContracts/IUserLogic.cs index 810a3d2..fbce0f1 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IWorkerLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IUserLogic.cs @@ -9,12 +9,12 @@ using UniversityContracts.ViewModels; namespace UniversityContracts.BusinessLogicsContracts { - public interface IWorkerLogic + public interface IUserLogic { - List? ReadList(WorkerSearchModel? model); - WorkerViewModel? ReadElement(WorkerSearchModel model); - bool Create(WorkerBindingModel model); - bool Update(WorkerBindingModel model); - bool Delete(WorkerBindingModel model); + List? ReadList(UserSearchModel? model); + UserViewModel? ReadElement(UserSearchModel model); + bool Create(UserBindingModel model); + bool Update(UserBindingModel model); + bool Delete(UserBindingModel model); } } diff --git a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs index cb3d1b8..45f8c92 100644 --- a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs +++ b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class AttestationSearchModel { public int? Id { get; set; } + public int UserId { get; set; } public int? StudentId { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs index 576c621..7b22b8d 100644 --- a/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs +++ b/University/UniversityContracts/SearchModels/DisciplineSearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class DisciplineSearchModel { public int? Id { get; set; } + public int UserId { get; set; } public int? TeacherId { get; set; } public string? Name { get; set; } public string? Description { get; set; } diff --git a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs index 9a4005c..e3466a2 100644 --- a/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs +++ b/University/UniversityContracts/SearchModels/PlanOfStudySearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class PlanOfStudySearchModel { public int? Id { get; set; } + public int UserId { get; set; } public string? Profile { get; set; } } } diff --git a/University/UniversityContracts/SearchModels/StatementSearchModel.cs b/University/UniversityContracts/SearchModels/StatementSearchModel.cs index 6070faf..e54561c 100644 --- a/University/UniversityContracts/SearchModels/StatementSearchModel.cs +++ b/University/UniversityContracts/SearchModels/StatementSearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class StatementSearchModel { public int? Id { get; set; } + public int UserId { get; set; } public string? Name { get; set; } public DateTime? Date { get; set; } } diff --git a/University/UniversityContracts/SearchModels/StorekeeperSearchModel.cs b/University/UniversityContracts/SearchModels/StorekeeperSearchModel.cs deleted file mode 100644 index 8c768b8..0000000 --- a/University/UniversityContracts/SearchModels/StorekeeperSearchModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UniversityDataModels; -using UniversityDataModels.Models; - -namespace UniversityContracts.SearchModels -{ - public class StorekeeperSearchModel - { - public int? Id { get; set; } - public string? FirstName { get; set; } - - public string? LastName { get; set; } - - public string? MiddleName { get; set; } - - public string? PhoneNumber { get; set; } - - public string? Email { get; set; } - } -} diff --git a/University/UniversityContracts/SearchModels/StudentSearchModel.cs b/University/UniversityContracts/SearchModels/StudentSearchModel.cs index 7e47e4c..64577d9 100644 --- a/University/UniversityContracts/SearchModels/StudentSearchModel.cs +++ b/University/UniversityContracts/SearchModels/StudentSearchModel.cs @@ -5,6 +5,7 @@ namespace UniversityContracts.SearchModels public class StudentSearchModel { public int? Id { get; set; } + public int UserId { get; set; } public string? Name { get; set; } } diff --git a/University/UniversityContracts/SearchModels/TeacherSearchModel.cs b/University/UniversityContracts/SearchModels/TeacherSearchModel.cs index d91bd71..677a69f 100644 --- a/University/UniversityContracts/SearchModels/TeacherSearchModel.cs +++ b/University/UniversityContracts/SearchModels/TeacherSearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class TeacherSearchModel { public int? Id { get; set; } + public int UserId { get; set; } public string? Name { get; set; } public string? AcademicDegree { get; set; } public string? Position { get; set; } diff --git a/University/UniversityContracts/SearchModels/WorkerSearchModel.cs b/University/UniversityContracts/SearchModels/UserSearchModel.cs similarity index 56% rename from University/UniversityContracts/SearchModels/WorkerSearchModel.cs rename to University/UniversityContracts/SearchModels/UserSearchModel.cs index e103afe..3da78e8 100644 --- a/University/UniversityContracts/SearchModels/WorkerSearchModel.cs +++ b/University/UniversityContracts/SearchModels/UserSearchModel.cs @@ -3,15 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityDataModels.Enums; namespace UniversityContracts.SearchModels { - public class WorkerSearchModel + public class UserSearchModel { public int? Id { get; set; } - public string? FirstName { get; set; } - public string? LastName { get; set; } - public string? PhoneNumber { get; set; } + public string? Login { get; set; } + + public string? Password { get; set; } + public string? Email { get; set; } + public UserRole? Role { get; set; } } } diff --git a/University/UniversityContracts/StorageContracts/IStorekeeperStorage.cs b/University/UniversityContracts/StorageContracts/IStorekeeperStorage.cs deleted file mode 100644 index d4505c7..0000000 --- a/University/UniversityContracts/StorageContracts/IStorekeeperStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -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 IStorekeeperStorage - { - List GetFullList(); - List GetFilteredList(StorekeeperSearchModel model); - StorekeeperViewModel? GetElement(StorekeeperSearchModel model); - StorekeeperViewModel? Insert(StorekeeperBindingModel model); - StorekeeperViewModel? Update(StorekeeperBindingModel model); - StorekeeperViewModel? Delete(StorekeeperBindingModel model); - } -} diff --git a/University/UniversityContracts/StorageContracts/IUserStorage.cs b/University/UniversityContracts/StorageContracts/IUserStorage.cs new file mode 100644 index 0000000..a080a00 --- /dev/null +++ b/University/UniversityContracts/StorageContracts/IUserStorage.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 IUserStorage + { + List GetFullList(); + List GetFilteredList(UserSearchModel model); + UserViewModel? GetElement(UserSearchModel model); + UserViewModel? Insert(UserBindingModel model); + UserViewModel? Update(UserBindingModel model); + UserViewModel? Delete(UserBindingModel model); + } +} diff --git a/University/UniversityContracts/StorageContracts/IWorkerStorage.cs b/University/UniversityContracts/StorageContracts/IWorkerStorage.cs deleted file mode 100644 index a61053d..0000000 --- a/University/UniversityContracts/StorageContracts/IWorkerStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -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 IWorkerStorage - { - List GetFullList(); - List GetFilteredList(WorkerSearchModel model); - WorkerViewModel? GetElement(WorkerSearchModel model); - WorkerViewModel? Insert(WorkerBindingModel model); - WorkerViewModel? Update(WorkerBindingModel model); - WorkerViewModel? Delete(WorkerBindingModel model); - } -} diff --git a/University/UniversityContracts/ViewModels/AttestationViewModel.cs b/University/UniversityContracts/ViewModels/AttestationViewModel.cs index 53cd21d..23073ac 100644 --- a/University/UniversityContracts/ViewModels/AttestationViewModel.cs +++ b/University/UniversityContracts/ViewModels/AttestationViewModel.cs @@ -12,6 +12,7 @@ namespace UniversityContracts.ViewModels public class AttestationViewModel : IAttestationModel { public int Id { get; set; } + public int UserId { get; set; } public int StudentId { get; set; } [DisplayName("Форма оценивания")] public string FormOfEvaluation { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/DisciplineViewModel.cs b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs index 32162f3..4b06540 100644 --- a/University/UniversityContracts/ViewModels/DisciplineViewModel.cs +++ b/University/UniversityContracts/ViewModels/DisciplineViewModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels public class DisciplineViewModel : IDisciplineModel { public int Id { get; set; } + public int UserId { get; set; } public int TeacherId { get; set; } [DisplayName("Название дисциплины")] public string Name { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs b/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs index 411e916..96f51a9 100644 --- a/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs +++ b/University/UniversityContracts/ViewModels/PlanOfStudyViewModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels public class PlanOfStudyViewModel : IPlanOfStudyModel { public int Id { get; set; } + public int UserId { get; set; } public int WorkerId { get; set; } [DisplayName("Профиль")] public string Profile { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/StatementViewModel.cs b/University/UniversityContracts/ViewModels/StatementViewModel.cs index 0ae8823..4a2def6 100644 --- a/University/UniversityContracts/ViewModels/StatementViewModel.cs +++ b/University/UniversityContracts/ViewModels/StatementViewModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels public class StatementViewModel : IStatementModel { public int Id { get; set; } + public int UserId { get; set; } public int TeacherId { get; set; } [DisplayName("Название ведомости")] public string Name { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs b/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs deleted file mode 100644 index 4082034..0000000 --- a/University/UniversityContracts/ViewModels/StorekeeperViewModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -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/StudentViewModel.cs b/University/UniversityContracts/ViewModels/StudentViewModel.cs index d10c76c..1da47ed 100644 --- a/University/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/University/UniversityContracts/ViewModels/StudentViewModel.cs @@ -6,6 +6,7 @@ namespace UniversityContracts.ViewModels public class StudentViewModel : IStudentModel { public int Id { get; set; } + public int UserId { get; set; } public int PlanOfStudyId { get; set; } [DisplayName("ФИО")] public string Name { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/TeacherViewModel.cs b/University/UniversityContracts/ViewModels/TeacherViewModel.cs index 522e3f5..5a494cc 100644 --- a/University/UniversityContracts/ViewModels/TeacherViewModel.cs +++ b/University/UniversityContracts/ViewModels/TeacherViewModel.cs @@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels public class TeacherViewModel : ITeacherModel { public int Id { get; set; } + public int UserId { get; set; } public int StorekeeperId { get; set; } [DisplayName("ФИО")] public string Name { get; set; } = string.Empty; diff --git a/University/UniversityContracts/ViewModels/UserViewModel.cs b/University/UniversityContracts/ViewModels/UserViewModel.cs new file mode 100644 index 0000000..4231347 --- /dev/null +++ b/University/UniversityContracts/ViewModels/UserViewModel.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.Enums; +using UniversityDataModels.Models; + +namespace UniversityContracts.ViewModels +{ + public class UserViewModel : IUserModel + { + public int Id { get; set; } + [DisplayName("Логин")] + public string Login { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Почта")] + public string Email { get; set; } = string.Empty; + public UserRole Role { get; set; } + } +} diff --git a/University/UniversityContracts/ViewModels/WorkerViewModel.cs b/University/UniversityContracts/ViewModels/WorkerViewModel.cs deleted file mode 100644 index 86f063d..0000000 --- a/University/UniversityContracts/ViewModels/WorkerViewModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -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 WorkerViewModel : IWorkerModel - { - 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/UniversityDataModels/Enums/UserRole.cs b/University/UniversityDataModels/Enums/UserRole.cs new file mode 100644 index 0000000..8bfaced --- /dev/null +++ b/University/UniversityDataModels/Enums/UserRole.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityDataModels.Enums +{ + public enum UserRole + { + Неизвестная = -1, + + Работник = 0, + + Кладовщик = 1 + } +} diff --git a/University/UniversityDataModels/IPerson.cs b/University/UniversityDataModels/IPerson.cs deleted file mode 100644 index b378721..0000000 --- a/University/UniversityDataModels/IPerson.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace UniversityDataModels -{ - public interface IPerson : IId - { - public string FirstName { get; } - - public string LastName { get; } - - public string MiddleName { get; } - - public string PhoneNumber { get; } - - public string Email { get; } - } -} diff --git a/University/UniversityDataModels/Models/IAttestationModel.cs b/University/UniversityDataModels/Models/IAttestationModel.cs index 8a7a08a..9c2ea2e 100644 --- a/University/UniversityDataModels/Models/IAttestationModel.cs +++ b/University/UniversityDataModels/Models/IAttestationModel.cs @@ -4,6 +4,7 @@ namespace UniversityDataModels.Models { public interface IAttestationModel : IId { + int UserId { get; } string FormOfEvaluation { get; } AttestationScore Score { get; } int StudentId { get; } diff --git a/University/UniversityDataModels/Models/IDisciplineModel.cs b/University/UniversityDataModels/Models/IDisciplineModel.cs index f24b7f8..2663d82 100644 --- a/University/UniversityDataModels/Models/IDisciplineModel.cs +++ b/University/UniversityDataModels/Models/IDisciplineModel.cs @@ -2,6 +2,7 @@ { public interface IDisciplineModel : IId { + int UserId { get; } int TeacherId { get; } string Name { get; } string Description { get; } diff --git a/University/UniversityDataModels/Models/IPlanOfStudyModel.cs b/University/UniversityDataModels/Models/IPlanOfStudyModel.cs index 594b5ba..0dfd345 100644 --- a/University/UniversityDataModels/Models/IPlanOfStudyModel.cs +++ b/University/UniversityDataModels/Models/IPlanOfStudyModel.cs @@ -2,8 +2,8 @@ { public interface IPlanOfStudyModel : IId { + int UserId { get; } string Profile { get; } string FormOfStudy { get; } - int WorkerId { get; } } } diff --git a/University/UniversityDataModels/Models/IStatementModel.cs b/University/UniversityDataModels/Models/IStatementModel.cs index 6e12711..12cbff2 100644 --- a/University/UniversityDataModels/Models/IStatementModel.cs +++ b/University/UniversityDataModels/Models/IStatementModel.cs @@ -2,6 +2,7 @@ { public interface IStatementModel : IId { + int UserId { get; } int TeacherId { get; } string Name { get; } DateTime Date { get; } diff --git a/University/UniversityDataModels/Models/IStorekeeperModel.cs b/University/UniversityDataModels/Models/IStorekeeperModel.cs deleted file mode 100644 index 3177ac2..0000000 --- a/University/UniversityDataModels/Models/IStorekeeperModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace UniversityDataModels.Models -{ - public interface IStorekeeperModel : IPerson - { - } -} diff --git a/University/UniversityDataModels/Models/IStudentModel.cs b/University/UniversityDataModels/Models/IStudentModel.cs index 24b3be0..0b006c0 100644 --- a/University/UniversityDataModels/Models/IStudentModel.cs +++ b/University/UniversityDataModels/Models/IStudentModel.cs @@ -2,6 +2,7 @@ { public interface IStudentModel : IId { + int UserId { get; } string Name { get; } string PhoneNumber { get; } int PlanOfStudyId { get; } diff --git a/University/UniversityDataModels/Models/ITeacherModel.cs b/University/UniversityDataModels/Models/ITeacherModel.cs index 39cccc3..2540c1e 100644 --- a/University/UniversityDataModels/Models/ITeacherModel.cs +++ b/University/UniversityDataModels/Models/ITeacherModel.cs @@ -2,7 +2,7 @@ { public interface ITeacherModel : IId { - int StorekeeperId { get; } + int UserId { get; } string Name { get; } string AcademicDegree { get; } string Position { get; } diff --git a/University/UniversityDataModels/Models/IUserModel.cs b/University/UniversityDataModels/Models/IUserModel.cs new file mode 100644 index 0000000..767b91b --- /dev/null +++ b/University/UniversityDataModels/Models/IUserModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Enums; + +namespace UniversityDataModels.Models +{ + public interface IUserModel : IId + { + public string Login { get; } + public string Password { get; } + + public string Email { get; } + public UserRole Role { get; } + } +} diff --git a/University/UniversityDataModels/Models/IWorkerModel.cs b/University/UniversityDataModels/Models/IWorkerModel.cs deleted file mode 100644 index 240cecf..0000000 --- a/University/UniversityDataModels/Models/IWorkerModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace UniversityDataModels.Models -{ - public interface IWorkerModel : IPerson - { - } -} diff --git a/University/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs b/University/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs deleted file mode 100644 index 652cfb6..0000000 --- a/University/UniversityDatabaseImplement/Implements/StorekeeperStorage.cs +++ /dev/null @@ -1,86 +0,0 @@ -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; -using UniversityDataModels.Models; - -namespace UniversityDatabaseImplement.Implements -{ - public class StorekeeperStorage: IStorekeeperStorage - { - public StorekeeperViewModel? GetElement(StorekeeperSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - return context.Storekeepers.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - - public List GetFilteredList(StorekeeperSearchModel model) - { - if (string.IsNullOrEmpty(model.Email)) - { - return new(); - } - using var context = new UniversityDatabase(); - return context.Storekeepers - .Where(x => x.Email.Contains(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - using var context = new UniversityDatabase(); - return context.Storekeepers.Select(x => x.GetViewModel).ToList(); - } - - public StorekeeperViewModel? Insert(StorekeeperBindingModel model) - { - var newStorekeeper = Storekeeper.Create(model); - if (newStorekeeper == null) - { - return null; - } - using var context = new UniversityDatabase(); - context.Storekeepers.Add(newStorekeeper); - context.SaveChanges(); - return newStorekeeper.GetViewModel; - } - - public StorekeeperViewModel? Update(StorekeeperBindingModel model) - { - using var context = new UniversityDatabase(); - var client = context.Storekeepers.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - client.Update(model); - context.SaveChanges(); - return client.GetViewModel; - } - public StorekeeperViewModel? Delete(StorekeeperBindingModel model) - { - using var context = new UniversityDatabase(); - var client = context.Storekeepers.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - context.Storekeepers.Remove(client); - context.SaveChanges(); - return client.GetViewModel; - } - } -} diff --git a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs index 988cfd3..94da27a 100644 --- a/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/TeacherStorage.cs @@ -32,7 +32,7 @@ namespace UniversityDatabaseImplement.Implements .Where(x => x.Name.Contains(model.Name)) .Where(x => x.Position.Contains(model.Position)) .Where(x => x.AcademicDegree.Contains(model.AcademicDegree)) - .Include(x => x.Storekeeper) + .Include(x => x.User) .Select(x => x.GetViewModel) .ToList(); } diff --git a/University/UniversityDatabaseImplement/Implements/UserStorage.cs b/University/UniversityDatabaseImplement/Implements/UserStorage.cs new file mode 100644 index 0000000..60ebf7b --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/UserStorage.cs @@ -0,0 +1,96 @@ +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; +using UniversityDataModels.Enums; + +namespace UniversityDatabaseImplement.Implements +{ + public class UserStorage : IUserStorage + { + public List GetFullList() + { + using var context = new UniversityDatabase(); + return context.Users.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(UserSearchModel model) + { + if (model.Role == null || model.Role == UserRole.Неизвестная) + { + return new(); + } + using var context = new UniversityDatabase(); + return context.Users.Where(x => x.Role == model.Role).Select(x => x.GetViewModel).ToList(); + } + public UserViewModel? GetElement(UserSearchModel model) + { + if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + using var context = new UniversityDatabase(); + + //Поиск пользователя при входе в систему по логину, паролю и его роли (чтобы не могли войти в аккаунты другой роли) + if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && model.Role.HasValue) + { + return context.Users.FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password && x.Role == model.Role)?.GetViewModel; + } + //Получение по логину (пользователей с таким логином будет 1 или 0) + if (!string.IsNullOrEmpty(model.Login)) + { + return context.Users.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel; + } + //Получение по почте (пользователей с такой почтой будет 1 или 0) + else if (!string.IsNullOrEmpty(model.Email)) + { + return context.Users.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel; + } + //Получение по id + return context.Users.FirstOrDefault(x => 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 user = context.Users.FirstOrDefault(rec => rec.Id == model.Id); + if (user != null) + { + context.Users.Remove(user); + context.SaveChanges(); + return user.GetViewModel; + } + return null; + } + } +} diff --git a/University/UniversityDatabaseImplement/Implements/WorkerStorage.cs b/University/UniversityDatabaseImplement/Implements/WorkerStorage.cs deleted file mode 100644 index df039c5..0000000 --- a/University/UniversityDatabaseImplement/Implements/WorkerStorage.cs +++ /dev/null @@ -1,86 +0,0 @@ -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 WorkerStorage : IWorkerStorage - { - public WorkerViewModel? GetElement(WorkerSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } - using var context = new UniversityDatabase(); - - return context.Workers.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - - public List GetFilteredList(WorkerSearchModel model) - { - if (string.IsNullOrEmpty(model.Email)) - { - return new(); - } - using var context = new UniversityDatabase(); - return context.Workers - .Where(x => x.Email.Contains(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - using var context = new UniversityDatabase(); - return context.Workers.Select(x => x.GetViewModel).ToList(); - } - - public WorkerViewModel? Insert(WorkerBindingModel model) - { - var newWorker = Worker.Create(model); - if (newWorker == null) - { - return null; - } - using var context = new UniversityDatabase(); - context.Workers.Add(newWorker); - context.SaveChanges(); - return newWorker.GetViewModel; - } - - public WorkerViewModel? Update(WorkerBindingModel model) - { - using var context = new UniversityDatabase(); - var client = context.Workers.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - client.Update(model); - context.SaveChanges(); - return client.GetViewModel; - } - public WorkerViewModel? Delete(WorkerBindingModel model) - { - using var context = new UniversityDatabase(); - var client = context.Workers.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - context.Workers.Remove(client); - context.SaveChanges(); - return client.GetViewModel; - } - } -} diff --git a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs deleted file mode 100644 index 9ae693c..0000000 --- a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.Designer.cs +++ /dev/null @@ -1,442 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using UniversityDatabaseImplement; - -#nullable disable - -namespace UniversityDatabaseImplement.Migrations -{ - [DbContext(typeof(UniversityDatabase))] - [Migration("20240429094924_Initial")] - partial class Initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("FormOfEvaluation") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Score") - .HasColumnType("int"); - - b.Property("StudentId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("StudentId"); - - b.ToTable("Attestations"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Disciplines"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("FormOfStudy") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Profile") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("WorkerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("WorkerId"); - - b.ToTable("PlanOfStudys"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PlanOfStudyId") - .HasColumnType("int"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PlanOfStudyId"); - - b.HasIndex("TeacherId"); - - b.ToTable("PlanOfStudyTeachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Statements"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Storekeepers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PlanOfStudyId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PlanOfStudyId"); - - b.ToTable("Students"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DisciplineId") - .HasColumnType("int"); - - b.Property("StudentId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DisciplineId"); - - b.HasIndex("StudentId"); - - b.ToTable("StudentDisciplines"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AcademicDegree") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Position") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StorekeeperId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("StorekeeperId"); - - b.ToTable("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Workers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") - .WithMany("Attestations") - .HasForeignKey("StudentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Student"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("Disciplines") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Worker", "Worker") - .WithMany("PlanOfStudys") - .HasForeignKey("WorkerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Worker"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => - { - b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") - .WithMany("Teachers") - .HasForeignKey("PlanOfStudyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("PlanOfStudyTeachers") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("PlanOfStudy"); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("Statements") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") - .WithMany("Students") - .HasForeignKey("PlanOfStudyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("PlanOfStudy"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") - .WithMany("Students") - .HasForeignKey("DisciplineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") - .WithMany("StudentDiscipline") - .HasForeignKey("StudentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Discipline"); - - b.Navigation("Student"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Storekeeper", "Storekeeper") - .WithMany("Teachers") - .HasForeignKey("StorekeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Storekeeper"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.Navigation("Students"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.Navigation("Students"); - - b.Navigation("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => - { - b.Navigation("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.Navigation("Attestations"); - - b.Navigation("StudentDiscipline"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.Navigation("Disciplines"); - - b.Navigation("PlanOfStudyTeachers"); - - b.Navigation("Statements"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => - { - b.Navigation("PlanOfStudys"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs b/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs deleted file mode 100644 index c55372c..0000000 --- a/University/UniversityDatabaseImplement/Migrations/20240429094924_Initial.cs +++ /dev/null @@ -1,312 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace UniversityDatabaseImplement.Migrations -{ - /// - public partial class Initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Storekeepers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FirstName = table.Column(type: "nvarchar(max)", nullable: false), - LastName = table.Column(type: "nvarchar(max)", nullable: false), - MiddleName = table.Column(type: "nvarchar(max)", nullable: false), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Storekeepers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Workers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FirstName = table.Column(type: "nvarchar(max)", nullable: false), - LastName = table.Column(type: "nvarchar(max)", nullable: false), - MiddleName = table.Column(type: "nvarchar(max)", nullable: false), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Workers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Teachers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - StorekeeperId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - AcademicDegree = table.Column(type: "nvarchar(max)", nullable: false), - Position = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Teachers", x => x.Id); - table.ForeignKey( - name: "FK_Teachers_Storekeepers_StorekeeperId", - column: x => x.StorekeeperId, - principalTable: "Storekeepers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "PlanOfStudys", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - WorkerId = table.Column(type: "int", nullable: false), - Profile = table.Column(type: "nvarchar(max)", nullable: false), - FormOfStudy = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PlanOfStudys", x => x.Id); - table.ForeignKey( - name: "FK_PlanOfStudys_Workers_WorkerId", - column: x => x.WorkerId, - principalTable: "Workers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Disciplines", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TeacherId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Disciplines", x => x.Id); - table.ForeignKey( - name: "FK_Disciplines_Teachers_TeacherId", - column: x => x.TeacherId, - principalTable: "Teachers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Statements", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TeacherId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Date = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Statements", x => x.Id); - table.ForeignKey( - name: "FK_Statements_Teachers_TeacherId", - column: x => x.TeacherId, - principalTable: "Teachers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "PlanOfStudyTeachers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PlanOfStudyId = table.Column(type: "int", nullable: false), - TeacherId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PlanOfStudyTeachers", x => x.Id); - table.ForeignKey( - name: "FK_PlanOfStudyTeachers_PlanOfStudys_PlanOfStudyId", - column: x => x.PlanOfStudyId, - principalTable: "PlanOfStudys", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PlanOfStudyTeachers_Teachers_TeacherId", - column: x => x.TeacherId, - principalTable: "Teachers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Students", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PlanOfStudyId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Students", x => x.Id); - table.ForeignKey( - name: "FK_Students_PlanOfStudys_PlanOfStudyId", - column: x => x.PlanOfStudyId, - principalTable: "PlanOfStudys", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Attestations", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - StudentId = table.Column(type: "int", nullable: false), - FormOfEvaluation = table.Column(type: "nvarchar(max)", nullable: false), - Score = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Attestations", x => x.Id); - table.ForeignKey( - name: "FK_Attestations_Students_StudentId", - column: x => x.StudentId, - principalTable: "Students", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "StudentDisciplines", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - StudentId = table.Column(type: "int", nullable: false), - DisciplineId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_StudentDisciplines", x => x.Id); - table.ForeignKey( - name: "FK_StudentDisciplines_Disciplines_DisciplineId", - column: x => x.DisciplineId, - principalTable: "Disciplines", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_StudentDisciplines_Students_StudentId", - column: x => x.StudentId, - principalTable: "Students", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Attestations_StudentId", - table: "Attestations", - column: "StudentId"); - - migrationBuilder.CreateIndex( - name: "IX_Disciplines_TeacherId", - table: "Disciplines", - column: "TeacherId"); - - migrationBuilder.CreateIndex( - name: "IX_PlanOfStudys_WorkerId", - table: "PlanOfStudys", - column: "WorkerId"); - - migrationBuilder.CreateIndex( - name: "IX_PlanOfStudyTeachers_PlanOfStudyId", - table: "PlanOfStudyTeachers", - column: "PlanOfStudyId"); - - migrationBuilder.CreateIndex( - name: "IX_PlanOfStudyTeachers_TeacherId", - table: "PlanOfStudyTeachers", - column: "TeacherId"); - - migrationBuilder.CreateIndex( - name: "IX_Statements_TeacherId", - table: "Statements", - column: "TeacherId"); - - migrationBuilder.CreateIndex( - name: "IX_StudentDisciplines_DisciplineId", - table: "StudentDisciplines", - column: "DisciplineId"); - - migrationBuilder.CreateIndex( - name: "IX_StudentDisciplines_StudentId", - table: "StudentDisciplines", - column: "StudentId"); - - migrationBuilder.CreateIndex( - name: "IX_Students_PlanOfStudyId", - table: "Students", - column: "PlanOfStudyId"); - - migrationBuilder.CreateIndex( - name: "IX_Teachers_StorekeeperId", - table: "Teachers", - column: "StorekeeperId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Attestations"); - - migrationBuilder.DropTable( - name: "PlanOfStudyTeachers"); - - migrationBuilder.DropTable( - name: "Statements"); - - migrationBuilder.DropTable( - name: "StudentDisciplines"); - - migrationBuilder.DropTable( - name: "Disciplines"); - - migrationBuilder.DropTable( - name: "Students"); - - migrationBuilder.DropTable( - name: "Teachers"); - - migrationBuilder.DropTable( - name: "PlanOfStudys"); - - migrationBuilder.DropTable( - name: "Storekeepers"); - - migrationBuilder.DropTable( - name: "Workers"); - } - } -} diff --git a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs deleted file mode 100644 index f4e7517..0000000 --- a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs +++ /dev/null @@ -1,439 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -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", "8.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("FormOfEvaluation") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Score") - .HasColumnType("int"); - - b.Property("StudentId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("StudentId"); - - b.ToTable("Attestations"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Disciplines"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("FormOfStudy") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Profile") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("WorkerId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("WorkerId"); - - b.ToTable("PlanOfStudys"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PlanOfStudyId") - .HasColumnType("int"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PlanOfStudyId"); - - b.HasIndex("TeacherId"); - - b.ToTable("PlanOfStudyTeachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("TeacherId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Statements"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Storekeepers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PlanOfStudyId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PlanOfStudyId"); - - b.ToTable("Students"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DisciplineId") - .HasColumnType("int"); - - b.Property("StudentId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DisciplineId"); - - b.HasIndex("StudentId"); - - b.ToTable("StudentDisciplines"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AcademicDegree") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Position") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StorekeeperId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("StorekeeperId"); - - b.ToTable("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Workers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") - .WithMany("Attestations") - .HasForeignKey("StudentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Student"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("Disciplines") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Worker", "Worker") - .WithMany("PlanOfStudys") - .HasForeignKey("WorkerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Worker"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => - { - b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") - .WithMany("Teachers") - .HasForeignKey("PlanOfStudyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("PlanOfStudyTeachers") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("PlanOfStudy"); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") - .WithMany("Statements") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") - .WithMany("Students") - .HasForeignKey("PlanOfStudyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("PlanOfStudy"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") - .WithMany("Students") - .HasForeignKey("DisciplineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") - .WithMany("StudentDiscipline") - .HasForeignKey("StudentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Discipline"); - - b.Navigation("Student"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.HasOne("UniversityDatabaseImplement.Models.Storekeeper", "Storekeeper") - .WithMany("Teachers") - .HasForeignKey("StorekeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Storekeeper"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => - { - b.Navigation("Students"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => - { - b.Navigation("Students"); - - b.Navigation("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Storekeeper", b => - { - b.Navigation("Teachers"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => - { - b.Navigation("Attestations"); - - b.Navigation("StudentDiscipline"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => - { - b.Navigation("Disciplines"); - - b.Navigation("PlanOfStudyTeachers"); - - b.Navigation("Statements"); - }); - - modelBuilder.Entity("UniversityDatabaseImplement.Models.Worker", b => - { - b.Navigation("PlanOfStudys"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/University/UniversityDatabaseImplement/Models/Discipline.cs b/University/UniversityDatabaseImplement/Models/Discipline.cs index 6b12277..3a6ab0f 100644 --- a/University/UniversityDatabaseImplement/Models/Discipline.cs +++ b/University/UniversityDatabaseImplement/Models/Discipline.cs @@ -46,7 +46,7 @@ namespace UniversityDatabaseImplement.Models Name = model.Name, Description = model.Description, Students = model.StudentDisciplines.Select(x => new - StudentDiscipline + StudentDiscipline { Student = context.Students.First(y => y.Id == x.Key) }).ToList() diff --git a/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs index c9f7812..fe7ff64 100644 --- a/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs +++ b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs @@ -14,7 +14,7 @@ namespace UniversityDatabaseImplement.Models public class PlanOfStudy : IPlanOfStudyModel { public int Id { get; private set; } - public int WorkerId { get; private set; } + public int UserId { get; private set; } [Required] public string Profile { get; private set; } = string.Empty; [Required] @@ -37,7 +37,7 @@ namespace UniversityDatabaseImplement.Models public virtual List Teachers { get; set; } = new(); [ForeignKey("PlanOfStudyId")] public virtual List Students { get; set; } = new(); - public virtual Worker Worker { get; set; } = new(); + public virtual User User { get; set; } = new(); public static PlanOfStudy Create(UniversityDatabase context, PlanOfStudyBindingModel model) { return new PlanOfStudy() diff --git a/University/UniversityDatabaseImplement/Models/Storekeeper.cs b/University/UniversityDatabaseImplement/Models/Storekeeper.cs deleted file mode 100644 index e25b3e7..0000000 --- a/University/UniversityDatabaseImplement/Models/Storekeeper.cs +++ /dev/null @@ -1,83 +0,0 @@ -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 c658579..4fa24dd 100644 --- a/University/UniversityDatabaseImplement/Models/Student.cs +++ b/University/UniversityDatabaseImplement/Models/Student.cs @@ -15,7 +15,8 @@ namespace UniversityDatabaseImplement.Models public class Student : IStudentModel { public int Id { get; private set; } - public int PlanOfStudyId { get; private set; } + public int UserId { get; private set; } + public int? PlanOfStudyId { get; private set; } [Required] public string Name { get; set; } = string.Empty; [Required] @@ -25,26 +26,16 @@ namespace UniversityDatabaseImplement.Models [ForeignKey("StudentId")] public virtual List Attestations { get; set; } = new(); public virtual PlanOfStudy PlanOfStudy { get; set; } = new(); - public static Student? Create(StudentBindingModel model) + public virtual User User { get; set; } = new(); + public static Student? Create(UniversityDatabase context, StudentBindingModel model) { - if (model == null) - { - return null; - } return new Student() { Id = model.Id, + UserId = model.UserId, + User = context.Users.First(x => x.Id == model.UserId), PlanOfStudyId = model.PlanOfStudyId, - Name = model.Name, - PhoneNumber = model.PhoneNumber - }; - } - public static Student Create(StudentViewModel model) - { - return new Student - { - Id = model.Id, - PlanOfStudyId = model.PlanOfStudyId, + PlanOfStudy = model.PlanOfStudyId.HasValue ? context.PlanOfStudys.First(x => x.Id == model.PlanOfStudyId) : null, Name = model.Name, PhoneNumber = model.PhoneNumber }; diff --git a/University/UniversityDatabaseImplement/Models/Teacher.cs b/University/UniversityDatabaseImplement/Models/Teacher.cs index bcf1f68..e95ee11 100644 --- a/University/UniversityDatabaseImplement/Models/Teacher.cs +++ b/University/UniversityDatabaseImplement/Models/Teacher.cs @@ -16,14 +16,14 @@ namespace UniversityDatabaseImplement.Models { public int Id { get; private set; } [Required] - public int StorekeeperId { get; private set; } + public int UserId { 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 (); + public virtual User User { get; set; } = new (); [ForeignKey("TeacherId")] public virtual List Statements { get; set; } = new(); [ForeignKey("TeacherId")] @@ -39,7 +39,7 @@ namespace UniversityDatabaseImplement.Models return new Teacher() { Id = model.Id, - StorekeeperId = model.StorekeeperId, + UserId = model.UserId, Name = model.Name, AcademicDegree = model.AcademicDegree, Position = model.Position, @@ -50,7 +50,7 @@ namespace UniversityDatabaseImplement.Models return new Teacher() { Id = model.Id, - StorekeeperId = model.StorekeeperId, + UserId = model.UserId, Name = model.Name, AcademicDegree = model.AcademicDegree, Position = model.Position, @@ -63,7 +63,7 @@ namespace UniversityDatabaseImplement.Models return; } Id = model.Id; - StorekeeperId = model.StorekeeperId; + UserId = model.UserId; Name = model.Name; AcademicDegree = model.AcademicDegree; Position = model.Position; @@ -71,7 +71,7 @@ namespace UniversityDatabaseImplement.Models public TeacherViewModel GetViewModel => new() { Id = Id, - StorekeeperId = StorekeeperId, + UserId = UserId, Name = Name, AcademicDegree = AcademicDegree, Position = Position, diff --git a/University/UniversityDatabaseImplement/Models/User.cs b/University/UniversityDatabaseImplement/Models/User.cs new file mode 100644 index 0000000..c563460 --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/User.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityDataModels.Models; +using UniversityDataModels.Enums; + +namespace UniversityDatabaseImplement.Models +{ + public class User : IUserModel + { + public int Id { get; private set; } + + [Required] + public string Login { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public string Email { get; set; } = string.Empty; + [Required] + public UserRole Role { get; set; } + public static User Create(UserBindingModel model) + { + return new User + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Email = model.Email + }; + } + + public void Update(UserBindingModel model) + { + if (model == null) + { + return; + } + Login = model.Login; + Password = model.Password; + Email = model.Email; + } + public UserViewModel GetViewModel => new() + { + Id = Id, + Login = Login, + Password = Password, + Email = Email, + Role = Role + }; + } +} diff --git a/University/UniversityDatabaseImplement/Models/Worker.cs b/University/UniversityDatabaseImplement/Models/Worker.cs deleted file mode 100644 index e29807e..0000000 --- a/University/UniversityDatabaseImplement/Models/Worker.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UniversityContracts.BindingModels; -using UniversityContracts.ViewModels; -using UniversityDataModels.Models; - -namespace UniversityDatabaseImplement.Models -{ - public class Worker : IWorkerModel - { - 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("WorkerId")] - public virtual List PlanOfStudys { get; set; } = new(); - public static Worker? Create(WorkerBindingModel model) - { - if (model == null) - { - return null; - } - return new Worker() - { - Id = model.Id, - FirstName = model.FirstName, - LastName = model.LastName, - MiddleName = model.MiddleName, - PhoneNumber = model.PhoneNumber, - Email = model.Email, - - }; - } - public static Worker Create(WorkerViewModel model) - { - return new Worker - { - Id = model.Id, - FirstName = model.FirstName, - LastName = model.LastName, - MiddleName = model.MiddleName, - PhoneNumber = model.PhoneNumber, - Email = model.Email, - }; - } - public void Update(WorkerBindingModel model) - { - if (model == null) - { - return; - } - Id = model.Id; - FirstName = model.FirstName; - LastName = model.LastName; - MiddleName = model.MiddleName; - PhoneNumber = model.PhoneNumber; - Email = model.Email; - } - public WorkerViewModel GetViewModel => new() - { - Id = Id, - FirstName = FirstName, - LastName = LastName, - MiddleName = MiddleName, - PhoneNumber = PhoneNumber, - Email = Email, - }; - } -} diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index fd1fbaf..9d2b17f 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,15 +11,14 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR - optionsBuilder.UseSqlServer(@"Data Source=(localdb)\UniversityDatabase;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\UniversityDatabase;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } public virtual DbSet Students { set; get; } public virtual DbSet PlanOfStudys { set; get; } public virtual DbSet Attestations { set; get; } - public virtual DbSet Workers { set; get; } - public virtual DbSet Storekeepers { set; get; } + public virtual DbSet Users { set; get; } public virtual DbSet Teachers { set; get; } public virtual DbSet Disciplines { set; get; } public virtual DbSet Statements { set; get; }