From e2dd3b3b4fc0e98769e350d3d983e919387bbbf6 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: Tue, 30 Apr 2024 21:31:36 +0400 Subject: [PATCH] Business Logic fix 0.3 --- .../BusinessLogic/ProductLogic.cs | 19 +++++++++++++------ .../BusinessLogic/UserLogic.cs | 14 +++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs index 27ef70e..f99298b 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -83,17 +83,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic private void CheckModel(ProductBindingModel model, bool withParams = true) { - if (model == null) throw new ArgumentNullException(nameof(model)); - if (!withParams) return; - if (string.IsNullOrEmpty(model.ProductName)) + if (model == null) { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) { + return; + } + if (string.IsNullOrEmpty(model.ProductName)) { throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); - if (model.Price <= 0) + } + if (model.Price <= 0) { throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); - _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.Count:{model.Count}" + + } + _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}" + $".CategoryID:{model.CategoryID}"); var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); - if (element != null && element.ID != model.ID) + if (element != null && element.ID != model.ID) { throw new InvalidOperationException("Продукт с таким названием уже есть"); + } } } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs index c043001..70eeff3 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs @@ -51,7 +51,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic _logger.LogInformation($"Delete.ID:{model.ID}"); if (_storage.Delete(model) == null) { - _logger.LogWarning("Delete operation failes"); + _logger.LogWarning("Delete operation failed"); return false; } return true; @@ -64,28 +64,28 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}"); + _logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}"); var element = _storage.GetElement(model); if (element == null) { - _logger.LogWarning("ReadElement element not fount"); + _logger.LogWarning("ReadElement. element not fount"); return null; } - _logger.LogInformation($"ReadElement: find.ID:{element.ID}"); + _logger.LogInformation($"ReadElement.find.ID:{element.ID}"); return element; } public List? ReadList(UserSearchModel? model) { - _logger.LogInformation($"ReadList: ClientID:{model?.ID}"); + _logger.LogInformation($"ReadList. ClientID:{model?.ID}"); var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ; if (list == null) { - _logger.LogWarning("ReadList: return null list"); + _logger.LogWarning("ReadList. return null list"); return null; } - _logger.LogInformation($"ReadList:Count:{list.Count}"); + _logger.LogInformation($"ReadList.Count:{list.Count}"); return list; }