From 15f995b6ce8f216b8a16926d24428034796485be 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 23:53:21 +0400 Subject: [PATCH] =?UTF-8?q?fixed=200.4=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B8=20=D0=B2=D0=BE=D1=81=D0=BA=D1=80=D0=B5?= =?UTF-8?q?=D1=81=D0=BB=D0=B8!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/CategoryProductLogic.cs | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs new file mode 100644 index 0000000..436daf2 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs @@ -0,0 +1,95 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.BusinessLogicContracts; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopBusinessLogic.BusinessLogic +{ + public class CategoryProductLogic : ICategoryProductLogic + { + private readonly ILogger _logger; + //private readonly ICategoryProductStorage _storage; + + // todo нет интерфейса хранилища + public CategoryProductLogic(ILogger logger) { + _logger = logger; + } + + public bool Create(CategoryProductBindingModel model) + { + CheckModel(model); + // todo _storage.Insert(model) == null + if (model == null) { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(CategoryProductBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation($"Delete. ID:{model.ID}"); + // todo _storage.Insert(model) == null + if (model == null) { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool Update(CategoryProductBindingModel model) + { + CheckModel(model); + // todo _storage.Insert(model) == null + if (model == null) { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public List? ReadList(CategoryProductSearchModel? model) + { + _logger.LogInformation($"ReadList. ID:{model?.ID}"); + // todo model == null _CategoryProductStorage.GetFullList() : _CategoryProductStorage.GetFilteredList(model); + var list = model; + if (list == null) { + _logger.LogWarning("ReadList return null list"); + return null; + } + // todo $"ReadList. Count:{list.count}" + _logger.LogInformation("ReadList. Count:{Count}"); + // todo return list; + return null; + } + + private void CheckModel(CategoryProductBindingModel 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($"CategoryProduct. Name:{model.Name}"); + /* + var element = _ CategoryProductStorage.GetElement(new CategoryProductSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.ID) + { + throw new InvalidOperationException("Категория с таким названием уже есть"); + } + */ + } + } +}