diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/DisciplineLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/DisciplineLogic.cs new file mode 100644 index 0000000..b913209 --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/DisciplineLogic.cs @@ -0,0 +1,111 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class DisciplineLogic : IDisciplineLogic + { + private readonly ILogger _logger; + private readonly IDisciplineStorage _disciplineStorage; + public DisciplineLogic(ILogger logger, IDisciplineStorage disciplineStorage) + { + _logger = logger; + _disciplineStorage = disciplineStorage; + } + public bool Create(DisciplineBindingModel model) + { + CheckModel(model); + + if (_disciplineStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(DisciplineBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_disciplineStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public DisciplineViewModel? ReadElement(DisciplineSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}.Id:{ Id}", model.Title, model.Id); + var element = _disciplineStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(DisciplineSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _disciplineStorage.GetFullList() : _disciplineStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(DisciplineBindingModel model) + { + CheckModel(model); + if (_disciplineStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(DisciplineBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Нет названия дисциплины", nameof(model.Title)); + } + + _logger.LogInformation("Discipline. Title:{Title}.Id:{Id}", model.Title, model.Id); + var element = _disciplineStorage.GetElement(new DisciplineSearchModel + { + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Дисциплина с таким названием уже есть"); + } + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/GroupLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/GroupLogic.cs new file mode 100644 index 0000000..2d4a49e --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/GroupLogic.cs @@ -0,0 +1,111 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class GroupLogic : IGroupLogic + { + private readonly ILogger _logger; + private readonly IGroupStorage _groupStorage; + public GroupLogic(ILogger logger, IGroupStorage groupStorage) + { + _logger = logger; + _groupStorage = groupStorage; + } + public bool Create(GroupBindingModel model) + { + CheckModel(model); + + if (_groupStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(GroupBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_groupStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public GroupViewModel? ReadElement(GroupSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Title:{Title}.Id:{ Id}", model.Title, model.Id); + var element = _groupStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(GroupSearchModel? model) + { + _logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id); + var list = model == null ? _groupStorage.GetFullList() : _groupStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(GroupBindingModel model) + { + CheckModel(model); + if (_groupStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(GroupBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Title)) + { + throw new ArgumentNullException("Нет названия группы", nameof(model.Title)); + } + + _logger.LogInformation("Group. Title:{Title}.Id:{Id}", model.Title, model.Id); + var element = _groupStorage.GetElement(new GroupSearchModel + { + Title = model.Title + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Группа с таким названием уже есть"); + } + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/ResultOfControlLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/ResultOfControlLogic.cs new file mode 100644 index 0000000..593b122 --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/ResultOfControlLogic.cs @@ -0,0 +1,109 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class ResultOfControlLogic : IResultOfControlLogic + { + private readonly ILogger _logger; + private readonly IResultOfControlStorage _resultStorage; + public ResultOfControlLogic(ILogger logger, IResultOfControlStorage resultStorage) + { + _logger = logger; + _resultStorage = resultStorage; + } + public bool Create(ResultOfControlBindingModel model) + { + CheckModel(model); + if (_resultStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Delete(ResultOfControlBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_resultStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public ResultOfControlViewModel? ReadElement(ResultOfControlSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _resultStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public List? ReadList(ResultOfControlSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _resultStorage.GetFullList() : _resultStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool Update(ResultOfControlBindingModel model) + { + CheckModel(model); + if (_resultStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(ResultOfControlBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Form)) + { + throw new ArgumentNullException("Нет формы", nameof(model.Form)); + } + if (string.IsNullOrEmpty(model.Mark)) + { + throw new ArgumentNullException("Нет оценки", nameof(model.Mark)); + } + if (model.StudentId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор студента", nameof(model.StudentId)); + } + if (model.StatementId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор ведомости", nameof(model.StatementId)); + } + + _logger.LogInformation("ResultOfControl. Form:{Form}.Mark:{Mark}.StudentId:{StudentId}.StatementId:{StatementId}.Id:{Id}", + model.Form, model.Mark, model.StudentId, model.StatementId, model.Id); + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StatementLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StatementLogic.cs new file mode 100644 index 0000000..27abf77 --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StatementLogic.cs @@ -0,0 +1,105 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class StatementLogic : IStatementLogic + { + private readonly ILogger _logger; + private readonly IStatementStorage _statementStorage; + public StatementLogic(ILogger logger, IStatementStorage statementStorage) + { + _logger = logger; + _statementStorage = statementStorage; + } + public bool Create(StatementBindingModel model) + { + CheckModel(model); + if (_statementStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Delete(StatementBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_statementStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public StatementViewModel? ReadElement(StatementSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _statementStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public List? ReadList(StatementSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _statementStorage.GetFullList() : _statementStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool Update(StatementBindingModel model) + { + CheckModel(model); + if (_statementStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(StatementBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.DisciplineId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор дисциплины", nameof(model.DisciplineId)); + } + if (model.GroupId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор группы", nameof(model.GroupId)); + } + if (model.TeacherId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор преподавателя", nameof(model.TeacherId)); + } + + _logger.LogInformation("Statement. DisciplineId:{DisciplineId}.GroupId:{GroupId}.TeacherId:{TeacherId}.Id:{Id}", + model.DisciplineId, model.GroupId, model.TeacherId, model.Id); + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StudentLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StudentLogic.cs new file mode 100644 index 0000000..ad61788 --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/StudentLogic.cs @@ -0,0 +1,109 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class StudentLogic : IStudentLogic + { + private readonly ILogger _logger; + private readonly IStudentStorage _studentStorage; + public StudentLogic(ILogger logger, IStudentStorage studentStorage) + { + _logger = logger; + _studentStorage = studentStorage; + } + public bool Create(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Delete(StudentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_studentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public StudentViewModel? ReadElement(StudentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id); + var element = _studentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public List? ReadList(StudentSearchModel? model) + { + _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool Update(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(StudentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени студента", nameof(model.Name)); + } + if (model.GroupId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор группы", nameof(model.GroupId)); + } + + _logger.LogInformation("Student. Name:{Name}.GroupId:{GroupId}.Id:{Id}", + model.Name, model.GroupId, model.Id); + var element = _studentStorage.GetElement(new StudentSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Студент с таким именем уже есть"); + } + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/TeacherLogic.cs b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/TeacherLogic.cs new file mode 100644 index 0000000..f6eb0d4 --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/BusinessLogic/TeacherLogic.cs @@ -0,0 +1,111 @@ +using ElectronicJournalContracts.BindingModels; +using ElectronicJournalContracts.BusinessLogicContracts; +using ElectronicJournalContracts.SearchModels; +using ElectronicJournalContracts.StorageContracts; +using ElectronicJournalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ElectronicJournalBusinessLogic.BusinessLogic +{ + public class TeacherLogic : ITeacherLogic + { + private readonly ILogger _logger; + private readonly ITeacherStorage _teacherStorage; + public TeacherLogic(ILogger logger, ITeacherStorage teacherStorage) + { + _logger = logger; + _teacherStorage = teacherStorage; + } + public bool Create(TeacherBindingModel model) + { + CheckModel(model); + + if (_teacherStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(TeacherBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_teacherStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public TeacherViewModel? ReadElement(TeacherSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id); + var element = _teacherStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(TeacherSearchModel? model) + { + _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _teacherStorage.GetFullList() : _teacherStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(TeacherBindingModel model) + { + CheckModel(model); + if (_teacherStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(TeacherBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени препеодавателя", nameof(model.Name)); + } + + _logger.LogInformation("Teacher. Name:{Name}.Id:{Id}", model.Name, model.Id); + var element = _teacherStorage.GetElement(new TeacherSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Преподаватель с таким именем уже есть"); + } + } + } +} diff --git a/SUBD/ElectronicJournalBusinessLogic/ElectronicJournalBusinessLogic.csproj b/SUBD/ElectronicJournalBusinessLogic/ElectronicJournalBusinessLogic.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SUBD/ElectronicJournalBusinessLogic/ElectronicJournalBusinessLogic.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SUBD/SUBD.sln b/SUBD/SUBD.sln index 75a0eea..cd327f9 100644 --- a/SUBD/SUBD.sln +++ b/SUBD/SUBD.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicJournalDataModels EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicJournalContracts", "ElectronicJournalContracts\ElectronicJournalContracts.csproj", "{374D708E-00B2-4680-8F92-F88173620B09}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicJournalDatabaseImplement", "ElectronicJournalDatabaseImplement\ElectronicJournalDatabaseImplement.csproj", "{E8170BDE-E00D-4BE3-B62E-C42136C1EB15}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicJournalDatabaseImplement", "ElectronicJournalDatabaseImplement\ElectronicJournalDatabaseImplement.csproj", "{E8170BDE-E00D-4BE3-B62E-C42136C1EB15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicJournalBusinessLogic", "ElectronicJournalBusinessLogic\ElectronicJournalBusinessLogic.csproj", "{8FB5F785-3199-4ABB-80AC-2A06DAA7ECFD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {E8170BDE-E00D-4BE3-B62E-C42136C1EB15}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8170BDE-E00D-4BE3-B62E-C42136C1EB15}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8170BDE-E00D-4BE3-B62E-C42136C1EB15}.Release|Any CPU.Build.0 = Release|Any CPU + {8FB5F785-3199-4ABB-80AC-2A06DAA7ECFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FB5F785-3199-4ABB-80AC-2A06DAA7ECFD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FB5F785-3199-4ABB-80AC-2A06DAA7ECFD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FB5F785-3199-4ABB-80AC-2A06DAA7ECFD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE