From 9c32f553ec4e48dd56b7a57b87dce527da372fdb Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 17:54:42 +0400 Subject: [PATCH 1/6] add user logic --- .../UniversityBuisnessLogic/UserLogic.cs | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 University/UniversityBuisnessLogic/UserLogic.cs diff --git a/University/UniversityBuisnessLogic/UserLogic.cs b/University/UniversityBuisnessLogic/UserLogic.cs new file mode 100644 index 0000000..7c0557d --- /dev/null +++ b/University/UniversityBuisnessLogic/UserLogic.cs @@ -0,0 +1,130 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic +{ + public class UserLogic : IUserLogic + { + private readonly ILogger _logger; + private readonly IUserStorage _userStorage; + + public UserLogic(ILogger logger, IUserStorage userStorage) + { + _logger = logger; + _userStorage = userStorage; + } + + public bool Create(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public UserViewModel? ReadElement(UserSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", 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 List? ReadList(UserSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", 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 bool Update(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Update(model) == null) + { + _logger.LogWarning("Update 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.Name)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name)); + } + else if (model.Password.Length < 6) + { + throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name)); + } + + _logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " + + "Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id); + + var element = _userStorage.GetElement(new UserSearchModel + { + Login = model.Login, + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким логином уже есть"); + } + } + } +} From e2c272c024ae19f8a75405cb4f2ff443c9c2b910 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 22:21:05 +0400 Subject: [PATCH 2/6] move files to buisnessLogic --- .../BuisnessLogic/ActivityLogic.cs | 102 ++++++++++++++ .../BuisnessLogic/DisciplineLogic.cs | 117 ++++++++++++++++ .../BuisnessLogic/ExaminationResultLogic.cs | 103 ++++++++++++++ .../BuisnessLogic/ReportTypeLogic.cs | 112 +++++++++++++++ .../BuisnessLogic/StatementLogic.cs | 101 ++++++++++++++ .../BuisnessLogic/StudentLogic.cs | 101 ++++++++++++++ .../BuisnessLogic/UserLogic.cs | 130 ++++++++++++++++++ 7 files changed, 766 insertions(+) create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/ActivityLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/DisciplineLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/ExaminationResultLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/ReportTypeLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/StatementLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/StudentLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/UserLogic.cs diff --git a/University/UniversityBuisnessLogic/BuisnessLogic/ActivityLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ActivityLogic.cs new file mode 100644 index 0000000..a145745 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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.BuisnessLogic +{ + 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/BuisnessLogic/DisciplineLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/DisciplineLogic.cs new file mode 100644 index 0000000..af96521 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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.BuisnessLogic +{ + 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/BuisnessLogic/ExaminationResultLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ExaminationResultLogic.cs new file mode 100644 index 0000000..51657c3 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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.BuisnessLogic +{ + 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/BuisnessLogic/ReportTypeLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ReportTypeLogic.cs new file mode 100644 index 0000000..d7120ee --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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.BuisnessLogic +{ + 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/BuisnessLogic/StatementLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/StatementLogic.cs new file mode 100644 index 0000000..e834537 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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 UniversityBuisnessLogic.BuisnessLogic +{ + 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/BuisnessLogic/StudentLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/StudentLogic.cs new file mode 100644 index 0000000..08145a7 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/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.BuisnessLogic +{ + 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/BuisnessLogic/UserLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/UserLogic.cs new file mode 100644 index 0000000..f59dbd0 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/UserLogic.cs @@ -0,0 +1,130 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic.BuisnessLogic +{ + public class UserLogic : IUserLogic + { + private readonly ILogger _logger; + private readonly IUserStorage _userStorage; + + public UserLogic(ILogger logger, IUserStorage userStorage) + { + _logger = logger; + _userStorage = userStorage; + } + + public bool Create(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public UserViewModel? ReadElement(UserSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", 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 List? ReadList(UserSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", 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 bool Update(UserBindingModel model) + { + CheckModel(model); + if (_userStorage.Update(model) == null) + { + _logger.LogWarning("Update 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.Name)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name)); + } + else if (model.Password.Length < 6) + { + throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name)); + } + + _logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " + + "Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id); + + var element = _userStorage.GetElement(new UserSearchModel + { + Login = model.Login, + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким логином уже есть"); + } + } + } +} From f29365f88c591480f709c8e902f4b8d815ffe249 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:28:50 +0400 Subject: [PATCH 3/6] delete files which out of folder BuisnessLogic --- .../UniversityBuisnessLogic/ActivityLogic.cs | 102 -------------- .../BuisnessLogic/ReportLogic.cs | 28 ++++ .../DisciplineLogic.cs | 117 ---------------- .../ExaminationResultLogic.cs | 103 -------------- .../ReportTypeLogic.cs | 112 --------------- .../UniversityBuisnessLogic/StatementLogic.cs | 101 -------------- .../UniversityBuisnessLogic/StudentLogic.cs | 101 -------------- .../UniversityBuisnessLogic/UserLogic.cs | 130 ------------------ 8 files changed, 28 insertions(+), 766 deletions(-) delete mode 100644 University/UniversityBuisnessLogic/ActivityLogic.cs create mode 100644 University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs delete mode 100644 University/UniversityBuisnessLogic/DisciplineLogic.cs delete mode 100644 University/UniversityBuisnessLogic/ExaminationResultLogic.cs delete mode 100644 University/UniversityBuisnessLogic/ReportTypeLogic.cs delete mode 100644 University/UniversityBuisnessLogic/StatementLogic.cs delete mode 100644 University/UniversityBuisnessLogic/StudentLogic.cs delete mode 100644 University/UniversityBuisnessLogic/UserLogic.cs diff --git a/University/UniversityBuisnessLogic/ActivityLogic.cs b/University/UniversityBuisnessLogic/ActivityLogic.cs deleted file mode 100644 index 77c9494..0000000 --- a/University/UniversityBuisnessLogic/ActivityLogic.cs +++ /dev/null @@ -1,102 +0,0 @@ -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/BuisnessLogic/ReportLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs new file mode 100644 index 0000000..277fee3 --- /dev/null +++ b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs @@ -0,0 +1,28 @@ +using UniversityContracts.BindingModels; +using UniversityContracts.BuisnessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace UniversityBuisnessLogic.BuisnessLogic +{ + public class ReportLogic : IReportLogic + { + ILogger _logger; + IDisciplineStorage _disciplineStorage; + + public ReportLogic(ILogger logger, IDisciplineStorage disciplineStorage) + { + _logger = logger; + _disciplineStorage = disciplineStorage; + } + + public List GetStudentDiscipline(ReportBindingModel model) + { + if (model == null || model.Students == null) return new(); + + var disciplines = _disciplineStorage.GetFullList(); + } + } +} diff --git a/University/UniversityBuisnessLogic/DisciplineLogic.cs b/University/UniversityBuisnessLogic/DisciplineLogic.cs deleted file mode 100644 index 96c643a..0000000 --- a/University/UniversityBuisnessLogic/DisciplineLogic.cs +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 2bacc00..0000000 --- a/University/UniversityBuisnessLogic/ExaminationResultLogic.cs +++ /dev/null @@ -1,103 +0,0 @@ -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 deleted file mode 100644 index 810ab19..0000000 --- a/University/UniversityBuisnessLogic/ReportTypeLogic.cs +++ /dev/null @@ -1,112 +0,0 @@ -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 deleted file mode 100644 index b2fb525..0000000 --- a/University/UniversityBuisnessLogic/StatementLogic.cs +++ /dev/null @@ -1,101 +0,0 @@ -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 deleted file mode 100644 index d321f98..0000000 --- a/University/UniversityBuisnessLogic/StudentLogic.cs +++ /dev/null @@ -1,101 +0,0 @@ -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/UserLogic.cs b/University/UniversityBuisnessLogic/UserLogic.cs deleted file mode 100644 index 7c0557d..0000000 --- a/University/UniversityBuisnessLogic/UserLogic.cs +++ /dev/null @@ -1,130 +0,0 @@ -using UniversityContracts.BindingModels; -using UniversityContracts.BuisnessLogicContracts; -using UniversityContracts.SearchModels; -using UniversityContracts.StoragesContracts; -using UniversityContracts.ViewModels; -using Microsoft.Extensions.Logging; - -namespace UniversityBuisnessLogic -{ - public class UserLogic : IUserLogic - { - private readonly ILogger _logger; - private readonly IUserStorage _userStorage; - - public UserLogic(ILogger logger, IUserStorage userStorage) - { - _logger = logger; - _userStorage = userStorage; - } - - public bool Create(UserBindingModel model) - { - CheckModel(model); - if (_userStorage.Insert(model) == null) - { - _logger.LogWarning("Insert 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; - } - - public UserViewModel? ReadElement(UserSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. Id:{Id}", 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 List? ReadList(UserSearchModel? model) - { - _logger.LogInformation("ReadList. Id:{Id}", 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 bool Update(UserBindingModel model) - { - CheckModel(model); - if (_userStorage.Update(model) == null) - { - _logger.LogWarning("Update 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.Name)) - { - throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name)); - } - if (string.IsNullOrEmpty(model.Surname)) - { - throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name)); - } - if (string.IsNullOrEmpty(model.Login)) - { - throw new ArgumentNullException("Нет логина", nameof(model.Name)); - } - if (string.IsNullOrEmpty(model.Password)) - { - throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name)); - } - else if (model.Password.Length < 6) - { - throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name)); - } - - _logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " + - "Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id); - - var element = _userStorage.GetElement(new UserSearchModel - { - Login = model.Login, - }); - - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Пользователь с таким логином уже есть"); - } - } - } -} From 6abd26ea3c78b2568c7e29c69454c57cae356d30 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sat, 8 Apr 2023 23:34:04 +0400 Subject: [PATCH 4/6] make report logic student discipline --- .../BuisnessLogic/ReportLogic.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs index 277fee3..e0141ce 100644 --- a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs +++ b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs @@ -23,6 +23,27 @@ namespace UniversityBuisnessLogic.BuisnessLogic if (model == null || model.Students == null) return new(); var disciplines = _disciplineStorage.GetFullList(); + List result = new(); + + foreach(var student in model.Students) + { + var record = new ReportStudentDisciplineViewModel + { + StudentName = student.Name, + }; + + foreach(var discipline in disciplines) + { + if(student.Statements.ContainsKey(discipline.Id)) + { + record.Disciplines.Add(discipline.Name); + } + } + + result.Add(record); + } + + return result; } } } From 2bf631e109b481bb7acf0d56b6ec23498464fe70 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 00:38:43 +0400 Subject: [PATCH 5/6] finilized report logic --- .../BuisnessLogic/ReportLogic.cs | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs index e0141ce..e258b11 100644 --- a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs +++ b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs @@ -11,11 +11,58 @@ namespace UniversityBuisnessLogic.BuisnessLogic { ILogger _logger; IDisciplineStorage _disciplineStorage; + IStatementStorage _statementStorage; + IExaminationResultStorage _examinationResultStorage; - public ReportLogic(ILogger logger, IDisciplineStorage disciplineStorage) + public ReportLogic(ILogger logger, IDisciplineStorage disciplineStorage, + IStatementStorage statementStorage, IExaminationResultStorage examinationResultStorage) { _logger = logger; _disciplineStorage = disciplineStorage; + _statementStorage = statementStorage; + _examinationResultStorage = examinationResultStorage; + } + + public List GetStudens(ReportBindingModel model) + { + if (model == null) return new(); + + var results = _examinationResultStorage.GetFilteredList(new ExaminationResultSearchModel + { + From = model.From, + To = model.To, + }); + + var statements = _statementStorage.GetFilteredList(new StatementSearchModel + { + From = model.From, + To = model.To, + }); + + List list = new(); + + foreach (var result in results) + { + foreach(var student in result.Students.Values) + { + foreach(var statement in statements) + { + if (!student.Statements.ContainsKey(statement.Id)) continue; + + list.Add(new ReportStudentsViewModel + { + StudentName = student.Name, + ExaminationForm = result.ExaminationForm, + mark = result.Mark, + ExaminationResultDate = result.Date, + HoursCount = statement.HoursCount, + StatementDate = statement.Date + }); + } + } + } + + return list; } public List GetStudentDiscipline(ReportBindingModel model) @@ -45,5 +92,20 @@ namespace UniversityBuisnessLogic.BuisnessLogic return result; } + + public void SaveStudentsToExcel() + { + throw new NotImplementedException("Реализация в следующем этапе"); + } + + public void SaveStudentsToPdf() + { + throw new NotImplementedException("Реализация в следующем этапе"); + } + + public void SaveStudentsToWord() + { + throw new NotImplementedException("Реализация в следующем этапе"); + } } } From 6c8921128b2c762ef6c4709d3e685069f0fcc026 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Sun, 9 Apr 2023 01:18:06 +0400 Subject: [PATCH 6/6] fix reportLogic --- .../UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs index e258b11..7a64775 100644 --- a/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs +++ b/University/UniversityBuisnessLogic/BuisnessLogic/ReportLogic.cs @@ -81,9 +81,13 @@ namespace UniversityBuisnessLogic.BuisnessLogic foreach(var discipline in disciplines) { - if(student.Statements.ContainsKey(discipline.Id)) + foreach (var statement in discipline.DisciplineStatements) { - record.Disciplines.Add(discipline.Name); + if(student.Statements.ContainsKey(statement.Key)) + { + record.Disciplines.Add(discipline.Name); + break; + } } }