From 8770645a8284badf97f424250927157ee75dae22 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:09:52 +0400 Subject: [PATCH] Total dead --- .../BusinessLogic/OrderLogic.cs | 119 ++++++++++++++++++ .../BusinessLogic/RoleLogic.cs | 104 +++++++++++++++ .../{ClientLogic.cs => UserLogic.cs} | 23 +++- 3 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs rename ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/{ClientLogic.cs => UserLogic.cs} (87%) diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..17b8f7d --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,119 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.BusinessLogicContracts; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.StorageContracts; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Enums; +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 OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + //private readonly IOrderStorage _storage; + + // todo нет интерфейса хранилища + public OrderLogic(ILogger logger) { + _logger = logger; + //storage = _storage; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + model.Status = OrderStatus.Принят; + // todo _orderStorage.Insert(model) == null + if (model == null) { + _logger.LogInformation("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation($"ReadList:ID:{model?.ID}"); + // todo model == null? _orderStorage.GetFullList() : _orderStorage.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(OrderBindingModel model, bool withParams = true) { + if (model == null) { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) { + return; + } + if (string.IsNullOrEmpty((model.ID).ToString())) { + throw new ArgumentNullException("Нет ID заказа", nameof(model.ID)); + } + if (model.Sum <= 0) { + throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." + + $"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplemet}"); + } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) + { + CheckModel(model, false); + //todo + var viewModel = model; // model == _orderStorage.GetElement(new OrderSearchModel { ID = model.ID }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newOrderStatus) + { + _logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed."); + return false; + } + model.Status = newOrderStatus; + if (model.Status == OrderStatus.Готов) + { + //todo подключить бд + //model.DateImplement = DateTime.Now; + } + else + { + // todo подключить бд + //model.DateImplement = viewModel.DateImplement; + } + // todo + // _orderStorage.Update(model) == null + if (model == null) + { + _logger.LogWarning("Update operarion failed"); + return false; + } + return true; + } + } +} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs new file mode 100644 index 0000000..d0b888a --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs @@ -0,0 +1,104 @@ +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 RoleLogic : IRoleLogic + { + private readonly ILogger _logger; + //private readonly ICategoryProductStorage _storage; + + // todo нет интерфейса хранилища + public RoleLogic(ILogger logger) + { + _logger = logger; + } + + public bool Create(RoleBindingModel model) + { + CheckModel(model); + // todo _storage.Insert(model) == null + if (model == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(RoleBindingModel 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(RoleBindingModel model) + { + CheckModel(model); + // todo _storage.Insert(model) == null + if (model == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public List? ReadList(RoleSearchModel? model) + { + _logger.LogInformation($"ReadList. ID:{model?.ID}"); + // todo model == null _RoleStorage.GetFullList() : _RoleStorage.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(RoleBindingModel 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 = _RoleStorage.GetElement(new RoleSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.ID) + { + throw new InvalidOperationException("Такая роль уже есть"); + } + */ + } + } +} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs similarity index 87% rename from ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs rename to ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs index 8798048..df78d07 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs @@ -5,6 +5,7 @@ using ElectronicsShopContracts.ViewModels; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Data; using System.Linq; using System.Runtime.CompilerServices; @@ -13,13 +14,13 @@ using System.Threading.Tasks; namespace ElectronicsShopBusinessLogic.BusinessLogic { - public class ClientLogic : IClientLogic + public class UserLogic : IClientLogic { private readonly ILogger _logger; //private readonly IClientStorage _storage; // todo нет интерфейса хранилища - public ClientLogic(ILogger logger) { + public UserLogic(ILogger logger) { _logger = logger; //storage = _storage; } @@ -69,7 +70,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic // todo element = _clientStorage.GetElement(model); var element = model; if (element == null) { - _logger.LogWarning("ReadElement: element not fount"); + _logger.LogWarning("ReadElement element not fount"); return null; } _logger.LogInformation($"ReadElement: find.ID:{element.UserID}"); @@ -87,8 +88,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic _logger.LogWarning("ReadList: return null list"); return null; } - // toto ReadList. Count:{Count}, list.count - _logger.LogInformation("ReadList: Count:{Count}"); + // toto ReadList:Count:{list.count}, + _logger.LogInformation("ReadList:Count:{Count}"); // todo return list; return null; } @@ -118,8 +119,18 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic 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}." + + _logger.LogInformation($"Client. Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." + $"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}"); + /* + var element = _clientStorage.GetElement(new ClientSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.ID) + { + throw new InvalidOperationException("Клиент с таким логином уже есть"); + } + */ } } }