From 0d95ebcaa051f17fe4966439c3a11cdd9feb2ed5 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Fri, 7 Apr 2023 03:03:14 +0400 Subject: [PATCH] =?UTF-8?q?+=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CaseAccounting/CaseAccounting.sln | 10 +- .../BusinessLogics/CaseLogic.cs | 122 +++++++++++++++++ .../BusinessLogics/ContractLogic.cs | 117 ++++++++++++++++ .../BusinessLogics/DealLogic.cs | 117 ++++++++++++++++ .../BusinessLogics/HearingLogic.cs | 117 ++++++++++++++++ .../BusinessLogics/LawyerLogic.cs | 127 ++++++++++++++++++ .../BusinessLogics/SpecializationLogic.cs | 112 +++++++++++++++ .../BusinessLogics/UserLogic.cs | 117 ++++++++++++++++ .../CaseAccountingBusinessLogic.csproj | 18 +++ .../SearchModels/CaseSearchModel.cs | 2 + 10 files changed, 857 insertions(+), 2 deletions(-) create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ContractLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/DealLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/HearingLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/LawyerLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/SpecializationLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/UserLogic.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj diff --git a/CaseAccounting/CaseAccounting.sln b/CaseAccounting/CaseAccounting.sln index cc9910f..fee8363 100644 --- a/CaseAccounting/CaseAccounting.sln +++ b/CaseAccounting/CaseAccounting.sln @@ -5,9 +5,11 @@ VisualStudioVersion = 17.5.33424.131 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseAccountingDataModels", "CaseAccountingDataModels\CaseAccountingDataModels.csproj", "{CAA81DB0-6CCA-4CBE-ABE2-94CDB190E05F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaseAccountingContracts", "CaseAccountingContracts\CaseAccountingContracts.csproj", "{5014C0D9-62EF-41AD-A8A1-22E89C43E062}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseAccountingContracts", "CaseAccountingContracts\CaseAccountingContracts.csproj", "{5014C0D9-62EF-41AD-A8A1-22E89C43E062}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaseAccountingDataBaseImplement", "CaseAccountingDataBaseImplement\CaseAccountingDataBaseImplement.csproj", "{09C614AF-5BF5-4969-9609-D6A23DD74AA8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseAccountingDataBaseImplement", "CaseAccountingDataBaseImplement\CaseAccountingDataBaseImplement.csproj", "{09C614AF-5BF5-4969-9609-D6A23DD74AA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaseAccountingBusinessLogic", "CaseAccountingBusinessLogics\CaseAccountingBusinessLogic.csproj", "{4D95FDCC-80B3-452F-86FD-D514655ED0FB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +29,10 @@ Global {09C614AF-5BF5-4969-9609-D6A23DD74AA8}.Debug|Any CPU.Build.0 = Debug|Any CPU {09C614AF-5BF5-4969-9609-D6A23DD74AA8}.Release|Any CPU.ActiveCfg = Release|Any CPU {09C614AF-5BF5-4969-9609-D6A23DD74AA8}.Release|Any CPU.Build.0 = Release|Any CPU + {4D95FDCC-80B3-452F-86FD-D514655ED0FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D95FDCC-80B3-452F-86FD-D514655ED0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D95FDCC-80B3-452F-86FD-D514655ED0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D95FDCC-80B3-452F-86FD-D514655ED0FB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs new file mode 100644 index 0000000..1b58584 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs @@ -0,0 +1,122 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class CaseLogic : ICaseLogic + { + private readonly ILogger _logger; + private readonly ICaseStorage _caseStorage; + + public CaseLogic(ILogger logger, ICaseStorage caseStorage) + { + _logger = logger; + _caseStorage = caseStorage; + } + + public bool Create(CaseBindingModel model) + { + CheckModel(model); + if (_caseStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(CaseBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_caseStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public CaseViewModel? ReadElement(CaseSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. CaseName:{Name}.Id:{ Id}", model.Name, model.Id); + var element = _caseStorage.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(CaseSearchModel? model) + { + _logger.LogInformation("ReadList. CaseName:{Name}.Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _caseStorage.GetFullList() : _caseStorage.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(CaseBindingModel model) + { + CheckModel(model); + if (_caseStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(CaseBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.SpecializationId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор специализации", + nameof(model.SpecializationId)); + } + if (model.Name == string.Empty) + { + throw new ArgumentNullException("Некорректное название дела", + nameof(model.Name)); + } + if(model.Date > DateTime.Now) + { + throw new ArgumentNullException("Некорректное время заведения дела", + nameof(model.Date)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ContractLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ContractLogic.cs new file mode 100644 index 0000000..78c5e07 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ContractLogic.cs @@ -0,0 +1,117 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class ContractLogic : IContractLogic + { + private readonly ILogger _logger; + private readonly IContractStorage _contractStorage; + + public ContractLogic(ILogger logger, IContractStorage contractStorage) + { + _logger = logger; + _contractStorage = contractStorage; + } + + public bool Create(ContractBindingModel model) + { + CheckModel(model); + if (_contractStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ContractBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_contractStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ContractViewModel? ReadElement(ContractSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _contractStorage.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(ContractSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _contractStorage.GetFullList() : _contractStorage.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(ContractBindingModel model) + { + CheckModel(model); + if (_contractStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ContractBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.Coast <= 0) + { + throw new ArgumentNullException("Некорректная стоимость услуги", + nameof(model.Coast)); + } + if (model.Service == string.Empty) + { + throw new ArgumentNullException("Некорректное название услуги", + nameof(model.Service)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/DealLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/DealLogic.cs new file mode 100644 index 0000000..1ff3356 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/DealLogic.cs @@ -0,0 +1,117 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class DealLogic : IDealLogic + { + private readonly ILogger _logger; + private readonly IDealStorage _dealStorage; + + public DealLogic(ILogger logger, IDealStorage dealStorage) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _dealStorage = dealStorage ?? throw new ArgumentNullException(nameof(dealStorage)); + } + + public bool Create(DealBindingModel model) + { + CheckModel(model); + if (_dealStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(DealBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_dealStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public DealViewModel? ReadElement(DealSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _dealStorage.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(DealSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _dealStorage.GetFullList() : _dealStorage.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(DealBindingModel model) + { + CheckModel(model); + if (_dealStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(DealBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.Subject == string.Empty) + { + throw new ArgumentNullException("Некорректный предмет договора", + nameof(model.Subject)); + } + if (model.Responsibilities == string.Empty) + { + throw new ArgumentNullException("Некорректно указаны обязанности договора", + nameof(model.Responsibilities)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/HearingLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/HearingLogic.cs new file mode 100644 index 0000000..017ee62 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/HearingLogic.cs @@ -0,0 +1,117 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class HearingLogic : IHearingLogic + { + private readonly ILogger _logger; + private readonly IHearingStorage _hearingStorage; + + public HearingLogic(ILogger logger, IHearingStorage hearingStorage) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _hearingStorage = hearingStorage ?? throw new ArgumentNullException(nameof(hearingStorage)); + } + + public bool Create(HearingBindingModel model) + { + CheckModel(model); + if (_hearingStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(HearingBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_hearingStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public HearingViewModel? ReadElement(HearingSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _hearingStorage.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(HearingSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _hearingStorage.GetFullList() : _hearingStorage.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(HearingBindingModel model) + { + CheckModel(model); + if (_hearingStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(HearingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.CaseId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор дела", + nameof(model.CaseId)); + } + if (model.Information == string.Empty) + { + throw new ArgumentNullException("Некорректна написана информация по делу", + nameof(model.Information)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/LawyerLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/LawyerLogic.cs new file mode 100644 index 0000000..faf7809 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/LawyerLogic.cs @@ -0,0 +1,127 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class LawyerLogic : ILawyerLogic + { + private readonly ILogger _logger; + private readonly ILawyerStorage _lawyerStorage; + + public LawyerLogic(ILogger logger, ILawyerStorage lawyerStorage) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _lawyerStorage = lawyerStorage ?? throw new ArgumentNullException(nameof(lawyerStorage)); + } + + public bool Create(LawyerBindingModel model) + { + CheckModel(model); + if (_lawyerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(LawyerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_lawyerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public LawyerViewModel? ReadElement(LawyerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _lawyerStorage.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(LawyerSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.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(LawyerBindingModel model) + { + CheckModel(model); + if (_lawyerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(LawyerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.SpecializationId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор специализации", + nameof(model.SpecializationId)); + } + if (model.Experience < 0) + { + throw new ArgumentNullException("Некорректно указан опыт работы", + nameof(model.Experience)); + } + if (model.Name == string.Empty) + { + throw new ArgumentNullException("Некорректное имя юриста", + nameof(model.Name)); + } + if (model.Surname == string.Empty) + { + throw new ArgumentNullException("Некорректная фамилия юриста", + nameof(model.Surname)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/SpecializationLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/SpecializationLogic.cs new file mode 100644 index 0000000..8f9121e --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/SpecializationLogic.cs @@ -0,0 +1,112 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class SpecializationLogic : ISpecializationLogic + { + private readonly ILogger _logger; + private readonly ISpecializationStorage _specializationStorage; + + public SpecializationLogic(ILogger logger, ISpecializationStorage specializationStorage) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _specializationStorage = specializationStorage ?? throw new ArgumentNullException(nameof(specializationStorage)); + } + + public bool Create(SpecializationBindingModel model) + { + CheckModel(model); + if (_specializationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(SpecializationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_specializationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public SpecializationViewModel? ReadElement(SpecializationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _specializationStorage.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(SpecializationSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _specializationStorage.GetFullList() : _specializationStorage.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(SpecializationBindingModel model) + { + CheckModel(model); + if (_specializationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(SpecializationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.UserId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор пользователя", + nameof(model.UserId)); + } + if (model.Name == string.Empty) + { + throw new ArgumentNullException("Некорректное название специализации", + nameof(model.Name)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/UserLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/UserLogic.cs new file mode 100644 index 0000000..0159efc --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/UserLogic.cs @@ -0,0 +1,117 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class UserLogic : IUserLogic + { + private readonly ILogger _logger; + private readonly IUserStorage _userStorage; + + public UserLogic(ILogger logger, IUserStorage userStorage) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _userStorage = userStorage ?? throw new ArgumentNullException(nameof(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 (model.RoleId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор роли", + nameof(model.RoleId)); + } + if (model.Login == string.Empty) + { + throw new ArgumentNullException("Некорректный ввод логина", + nameof(model.Login)); + } + if (model.Password == string.Empty) + { + throw new ArgumentNullException("Некорректный ввод пароля", + nameof(model.Password)); + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj new file mode 100644 index 0000000..8e556ce --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs index 2f22a7b..01ec57e 100644 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs +++ b/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs @@ -17,5 +17,7 @@ namespace CaseAccountingContracts.SearchModels public string? Defendant { get; set; } public DateTime? Date { get; set; } + + public int? UserId { get; set; } } }