From f9a38dd14071cb9b50bece67455e8683992f8aba Mon Sep 17 00:00:00 2001 From: "kagbie3nn@mail.ru" Date: Sat, 27 Apr 2024 17:46:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=D1=81=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=B4=D0=BD=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/JurasicZoo/JurasicZoo.sln | 6 + .../BusinessLogic/EmployeeLogic.cs | 112 +++++++++++++++++ .../BusinessLogic/PreserveLogic.cs | 113 ++++++++++++++++++ .../ZooBusinessLogic/ZooBusinessLogic.csproj | 17 +++ 4 files changed, 248 insertions(+) create mode 100644 git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs create mode 100644 git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs create mode 100644 git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj diff --git a/git/JurasicZoo/JurasicZoo.sln b/git/JurasicZoo/JurasicZoo.sln index f53e8dc..591cd76 100644 --- a/git/JurasicZoo/JurasicZoo.sln +++ b/git/JurasicZoo/JurasicZoo.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZooDataModels", "ZooDataMod EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZooDataBaseImplement", "ZooDataBaseImplement\ZooDataBaseImplement.csproj", "{599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZooBusinessLogic", "ZooBusinessLogic\ZooBusinessLogic.csproj", "{CE5F683C-D19D-43FD-A0DA-0E66BD228996}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Debug|Any CPU.Build.0 = Debug|Any CPU {599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Release|Any CPU.ActiveCfg = Release|Any CPU {599C34A0-51C7-4782-9F9C-F2EFCC02FFA2}.Release|Any CPU.Build.0 = Release|Any CPU + {CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE5F683C-D19D-43FD-A0DA-0E66BD228996}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs new file mode 100644 index 0000000..6bc4e04 --- /dev/null +++ b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using ZooContracts.BindingModels; +using ZooContracts.BuisnessLogicsContracts; +using ZooContracts.SearchModels; +using ZooContracts.StorageContracts; +using ZooContracts.ViewModels; + +namespace ZooBusinessLogic.BusinessLogic +{ + public class EmployeeLogic :IEmployeeLogic + { + private readonly ILogger _logger; + private readonly IEmployeeStorage _employeeStorage; + + public EmployeeLogic(ILogger logger, IEmployeeStorage employeeStorage) + { + _logger = logger; + _employeeStorage = employeeStorage; + } + public List? ReadList(EmployeeSearchModel? model) + { + _logger.LogInformation("ReadList. EmployeeFIO:{EmployeeFIO}. Id:{ Id}", model?.EmployeeFIO, model?.Id); + var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public EmployeeViewModel? ReadElement(EmployeeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. EmployeeFIO:{EmployeeFIO}.Id:{ Id}", model.EmployeeFIO, model.Id); + var element = _employeeStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(EmployeeBindingModel model) + { + CheckModel(model); + if (_employeeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(EmployeeBindingModel model) + { + CheckModel(model); + if (_employeeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(EmployeeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_employeeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(EmployeeBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина сотрудника", + nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); + } + _logger.LogInformation("Employee. EmployeeFIO:{EmployeeFIO}.Login:{ Login}.Password:{Password} Id: { Id}", model.EmployeeFIO, model.Login, model.Password, model.Id); + var element = _employeeStorage.GetElement(new EmployeeSearchModel + { + EmployeeFIO = model.EmployeeFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сотрудник с таким логином уже есть"); + } + } + } +} diff --git a/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs new file mode 100644 index 0000000..5faa36e --- /dev/null +++ b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/PreserveLogic.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZooContracts.BindingModels; +using ZooContracts.BuisnessLogicsContracts; +using ZooContracts.SearchModels; +using ZooContracts.StorageContracts; +using ZooContracts.ViewModels; + +namespace ZooBusinessLogic.BusinessLogic +{ + public class PreserveLogic : IPreserveLogic + { + private readonly ILogger _logger; + private readonly IPreserveStorage _preserveStorage; + + public PreserveLogic(ILogger logger, IPreserveStorage preserveStorage) + { + _logger = logger; + _preserveStorage = preserveStorage; + } + public List? ReadList(PreserveSearchModel? model) + { + _logger.LogInformation("ReadList. PreserveName:{PreserveName}. Id:{ Id}", model?.PreserveName, model?.Id); + var list = model == null ? _preserveStorage.GetFullList() : _preserveStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PreserveViewModel? ReadElement(PreserveSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PreserveName:{PreserveName}.Id:{ Id}", model.PreserveName, model.Id); + var element = _preserveStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(PreserveBindingModel model) + { + CheckModel(model); + if (_preserveStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PreserveBindingModel model) + { + CheckModel(model); + if (_preserveStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PreserveBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_preserveStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PreserveBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PreservePrice<=0) + { + throw new ArgumentNullException("Cтоимости посещения заповедника должна быть больше 0", + nameof(model.PreservePrice)); + } + _logger.LogInformation("Preserve. PreserveName:{PreserveName}.PreservePrice:{PreservePrice} Id: { Id}", model.PreserveName, model.PreservePrice, model.Id); + var element = _preserveStorage.GetElement(new PreserveSearchModel + { + PreserveName = model.PreserveName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Заповедник с таким названием уже есть"); + } + } + } +} diff --git a/git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj b/git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj new file mode 100644 index 0000000..4b3ad10 --- /dev/null +++ b/git/JurasicZoo/ZooBusinessLogic/ZooBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + +