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("Категория с таким названием уже есть"); + } + */ + } + } +}