From 4b0183ae9140fddd6cb3f715359bcfa9c0cf6ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 28 Apr 2024 21:20:10 +0400 Subject: [PATCH] =?UTF-8?q?Business=20logic=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=82=D1=8C=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=D1=89=D0=B5,=20=D1=83=D0=B1=D1=80=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B7=D0=B0=D1=82=D1=8B=D1=87=D0=BA=D0=B8!=200.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectronicsShop/ElectronicsShop.sln | 6 + .../BusinessLogic/ClientLogic.cs | 125 ++++++++++++++++++ .../ElectronicsShopBusinessLogic.csproj | 17 +++ .../SearchModels/ClientSearchModel.cs | 2 +- .../SearchModels/ShopAssistentSearchModel.cs | 2 +- 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs create mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/ElectronicsShopBusinessLogic.csproj diff --git a/ElectronicsShop/ElectronicsShop.sln b/ElectronicsShop/ElectronicsShop.sln index fbdc137..36142e6 100644 --- a/ElectronicsShop/ElectronicsShop.sln +++ b/ElectronicsShop/ElectronicsShop.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopDataModels", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopContracts", "ElectronicsShopContracts\ElectronicsShopContracts.csproj", "{69411E41-F304-4D1B-8F15-48DD08585C7A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopBusinessLogic", "ElectronicsShopBusinessLogic\ElectronicsShopBusinessLogic.csproj", "{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {69411E41-F304-4D1B-8F15-48DD08585C7A}.Debug|Any CPU.Build.0 = Debug|Any CPU {69411E41-F304-4D1B-8F15-48DD08585C7A}.Release|Any CPU.ActiveCfg = Release|Any CPU {69411E41-F304-4D1B-8F15-48DD08585C7A}.Release|Any CPU.Build.0 = Release|Any CPU + {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..8798048 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs @@ -0,0 +1,125 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.BusinessLogicContracts; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopBusinessLogic.BusinessLogic +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + //private readonly IClientStorage _storage; + + // todo нет интерфейса хранилища + public ClientLogic(ILogger logger) { + _logger = logger; + //storage = _storage; + } + + public bool Add(ClientBindingModel model) + { + CheckModel(model); + // todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null + if (model == null) { + _logger.LogWarning("Add operation failed"); + return false; + } + return true; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + // todo логика добавления в _clientStorage:_clientStorage.Update(model) == null + if (model == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation($"Delete.ID:{model.UserID}"); + // todo логика добавления в _clientStorage:_clientStorage.Delete(model) == null + if (model == null) { + _logger.LogWarning("Delete operation failes"); + return false; + } + return true; + + } + + public ClientViewModel? ReadElemet(ClientSearchModel? model) + { + if (model == null) { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation($"ReadElement: logint:{ model.Login}.ID:{model.UserID}"); + // todo element = _clientStorage.GetElement(model); + var element = model; + if (element == null) { + _logger.LogWarning("ReadElement: element not fount"); + return null; + } + _logger.LogInformation($"ReadElement: find.ID:{element.UserID}"); + // todo retun element; + return null; + } + + public List? ReadList(ClientSearchModel? model) + { + + _logger.LogInformation($"ReadList: ClientID:{model?.UserID}"); + // todo получение списка из хранилища, model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + var list = model; + if (list == null) { + _logger.LogWarning("ReadList: return null list"); + return null; + } + // toto ReadList. Count:{Count}, list.count + _logger.LogInformation("ReadList: Count:{Count}"); + // todo return list; + return null; + } + + private void CheckModel(ClientBindingModel 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.FirstName)) { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName)); + } + if (string.IsNullOrEmpty(model.LastName)) { + throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName)); + } + if (string.IsNullOrEmpty(model.Email)) { + throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) { + throw new ArgumentNullException("Нет пароля пользователя", nameof (model.Password)); + } + if (string.IsNullOrEmpty(model.PhoneNumber)) { + throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber)); + } + _logger.LogInformation($"Client: Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." + + $"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}"); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/ElectronicsShopBusinessLogic.csproj b/ElectronicsShop/ElectronicsShopBusinessLogic/ElectronicsShopBusinessLogic.csproj new file mode 100644 index 0000000..39bc039 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/ElectronicsShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs index c64d20c..206e3fd 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs @@ -8,7 +8,7 @@ namespace ElectronicsShopContracts.SearchModels { public class ClientSearchModel { - public int? ID { get; set; } + public int? UserID { get; set; } public string? Login { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs index e5096c9..9c495e9 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs @@ -8,7 +8,7 @@ namespace ElectronicsShopContracts.SearchModels { public class ShopAssistentSearchModel { - public int? ID { get; set; } + public int? UserID { get; set; } public string? Login { get; set; } } }