diff --git a/University/University.sln b/University/University.sln index 2aa590b..8cb9a6e 100644 --- a/University/University.sln +++ b/University/University.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDataModels", "Uni EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{BACEFD46-1073-4730-BC42-15B0D0D359C9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDatabaseImplement", "DatabaseImplement\UniversityDatabaseImplement.csproj", "{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDatabaseImplement", "DatabaseImplement\UniversityDatabaseImplement.csproj", "{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityBuisnessLogic", "UniversityBuisnessLogic\UniversityBuisnessLogic.csproj", "{F29FD127-9597-44ED-A9A2-3CFB8E856442}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Debug|Any CPU.Build.0 = Debug|Any CPU {E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Release|Any CPU.ActiveCfg = Release|Any CPU {E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Release|Any CPU.Build.0 = Release|Any CPU + {F29FD127-9597-44ED-A9A2-3CFB8E856442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F29FD127-9597-44ED-A9A2-3CFB8E856442}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F29FD127-9597-44ED-A9A2-3CFB8E856442}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F29FD127-9597-44ED-A9A2-3CFB8E856442}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/University/UniversityBuisnessLogic/ActivityLogic.cs b/University/UniversityBuisnessLogic/ActivityLogic.cs new file mode 100644 index 0000000..77c9494 --- /dev/null +++ b/University/UniversityBuisnessLogic/ActivityLogic.cs @@ -0,0 +1,102 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + public class ActivityLogic : IActivityLogic + { + private readonly ILogger _logger; + private readonly IActivityStorage _activityStorage; + + public ActivityLogic(ILogger logger, IActivityStorage activityStorage) + { + _logger = logger; + _activityStorage = activityStorage; + } + public bool Create(ActivityBindingModel model) + { + CheckModel(model); + if (_activityStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ActivityBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_activityStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ActivityViewModel? ReadElement(ActivitySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _activityStorage.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(ActivitySearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _activityStorage.GetFullList() : _activityStorage.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(ActivityBindingModel model) + { + CheckModel(model); + if (_activityStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ActivityBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Number <= 0) + { + throw new ArgumentNullException("Номер занятия должен быть больше 0", nameof(model.Number)); + } + + _logger.LogInformation("Activity. Number:{ComponentName}. Id: {Id}", model.Number, model.Id); + } + } +} diff --git a/University/UniversityBuisnessLogic/DisciplineLogic.cs b/University/UniversityBuisnessLogic/DisciplineLogic.cs new file mode 100644 index 0000000..96c643a --- /dev/null +++ b/University/UniversityBuisnessLogic/DisciplineLogic.cs @@ -0,0 +1,117 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + 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. DisciplineName:{Name}. Id:{Id}", model.Name, 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. DisciplineName: {Name}. Id:{Id}", model?.Name, 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.Name)) + { + throw new ArgumentNullException("Нет названия дисциплины", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Department)) + { + throw new ArgumentNullException("Нет названия кафедры", nameof(model.Name)); + } + + _logger.LogInformation("Discipline. Name:{Name}. Department:{Department}. Id: {Id}", model.Name, model.Department, model.Id); + + var element = _disciplineStorage.GetElement(new DisciplineSearchModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Дисциплина с таким названием уже есть"); + } + } + } +} diff --git a/University/UniversityBuisnessLogic/ExaminationResultLogic.cs b/University/UniversityBuisnessLogic/ExaminationResultLogic.cs new file mode 100644 index 0000000..2bacc00 --- /dev/null +++ b/University/UniversityBuisnessLogic/ExaminationResultLogic.cs @@ -0,0 +1,103 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + public class ExaminationResultLogic : IExaminationResultLogic + { + private readonly ILogger _logger; + private readonly IExaminationResultStorage _examinationResultStorage; + + public ExaminationResultLogic(ILogger logger, IExaminationResultStorage examinationResultStorage) + { + _logger = logger; + _examinationResultStorage = examinationResultStorage; + } + + public bool Create(ExaminationResultBindingModel model) + { + CheckModel(model); + if (_examinationResultStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ExaminationResultBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_examinationResultStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ExaminationResultViewModel? ReadElement(ExaminationResultSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _examinationResultStorage.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(ExaminationResultSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _examinationResultStorage.GetFullList() : _examinationResultStorage.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(ExaminationResultBindingModel model) + { + CheckModel(model); + if (_examinationResultStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ExaminationResultBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ExaminationForm)) + { + throw new ArgumentNullException("Нет формы испытания", nameof(model.ExaminationForm)); + } + + _logger.LogInformation("ExaminationResult. ExaminationForm: {ExaminationForm}. Id: {Id}", model.ExaminationForm, model.Id); + } + } +} diff --git a/University/UniversityBuisnessLogic/ReportTypeLogic.cs b/University/UniversityBuisnessLogic/ReportTypeLogic.cs new file mode 100644 index 0000000..810ab19 --- /dev/null +++ b/University/UniversityBuisnessLogic/ReportTypeLogic.cs @@ -0,0 +1,112 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + public class ReportTypeLogic : IReportTypeLogic + { + private readonly ILogger _logger; + private readonly IReportTypeStorage _reportTypeStorage; + + public ReportTypeLogic(ILogger logger, IReportTypeStorage reportTypeStorage) + { + _logger = logger; + _reportTypeStorage = reportTypeStorage; + } + + public bool Create(ReportTypeBindingModel model) + { + CheckModel(model); + if (_reportTypeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ReportTypeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_reportTypeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ReportTypeViewModel? ReadElement(ReportTypeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ReportTypeName: {Name}. Id:{Id}", model.Name, model.Id); + var element = _reportTypeStorage.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(ReportTypeSearchModel? model) + { + _logger.LogInformation("ReadList. ReportTypeName: {Name}. Id:{Id}", model?.Name, model?.Id); + var list = model == null ? _reportTypeStorage.GetFullList() : _reportTypeStorage.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(ReportTypeBindingModel model) + { + CheckModel(model); + if (_reportTypeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ReportTypeBindingModel 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("ReportType. ReportName:{Name}. Id: { Id}", model.Name, model.Id); + var element = _reportTypeStorage.GetElement(new ReportTypeSearchModel + { + Name = model.Name, + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Тип отчета с таким названием уже есть"); + } + } + } +} diff --git a/University/UniversityBuisnessLogic/StatementLogic.cs b/University/UniversityBuisnessLogic/StatementLogic.cs new file mode 100644 index 0000000..b2fb525 --- /dev/null +++ b/University/UniversityBuisnessLogic/StatementLogic.cs @@ -0,0 +1,101 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogicf +{ + 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; + } + f + 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.HoursCount <= 0) + { + throw new ArgumentNullException("Количество часов в ведомости должно быть больше 0", nameof(model.HoursCount)); + } + _logger.LogInformation("Statement. HoursCount:{HoursCount}. Id: { Id}", model.HoursCount, model.Id); + } + } +} diff --git a/University/UniversityBuisnessLogic/StudentLogic.cs b/University/UniversityBuisnessLogic/StudentLogic.cs new file mode 100644 index 0000000..d321f98 --- /dev/null +++ b/University/UniversityBuisnessLogic/StudentLogic.cs @@ -0,0 +1,101 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + 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. StudentName: {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. StudentName: {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)); + } + + _logger.LogInformation("Student. Name:{Name}. Id: { Id}", model.Name, model.Id); + } + } +} diff --git a/University/UniversityBuisnessLogic/UniversityBuisnessLogic.csproj b/University/UniversityBuisnessLogic/UniversityBuisnessLogic.csproj new file mode 100644 index 0000000..17fc860 --- /dev/null +++ b/University/UniversityBuisnessLogic/UniversityBuisnessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + +