From 3a086dc54b5065067ef9b90a30ca0193a48f41b3 Mon Sep 17 00:00:00 2001 From: Allllen4a Date: Wed, 24 Apr 2024 14:02:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ClientLogic.cs | 156 ++++++++++++++++++ .../BusinessLogic/EvaluationLogic.cs | 107 ++++++++++++ .../BusinessLogic/OrderLogic.cs | 106 ++++++++++++ .../BusinessLogic/ProcedureLogic.cs | 123 ++++++++++++++ 4 files changed, 492 insertions(+) create mode 100644 BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs create mode 100644 BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs create mode 100644 BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..4c2b9c2 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs @@ -0,0 +1,156 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly int _passwordMaxLength = 50; + private readonly int _passwordMinLength = 10; + + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } + public bool Create(ClientBindingModel model) + { + CheckModel(model); + + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model.ClientLogin, model.ClientFIO, model.ClientEmail, model.Id); + + var element = _clientStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + + return element; + } + + public List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model?.ClientLogin, model?.ClientFIO, model?.ClientEmail, model?.Id); + + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + + return list; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.ClientLogin)) + { + throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientLogin)); + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.ClientEmail)) + { + throw new ArgumentNullException("Нет почты клиента", nameof(model.ClientEmail)); + } + if (string.IsNullOrEmpty(model.ClientPassword)) + { + throw new ArgumentNullException("Нет пароля", nameof(model.ClientPassword)); + } + if (model.ClientPassword.Length < _passwordMinLength) + { + throw new ArgumentNullException("Пароль слишком короткий", nameof(model.ClientPassword)); + } + if (model.ClientPassword.Length > _passwordMaxLength) + { + throw new ArgumentNullException("Пароль слишком длинный", nameof(model.ClientPassword)); + } + + _logger.LogInformation("Client. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model.ClientLogin, model.ClientFIO, model.ClientEmail, model.Id); + + var element = _clientStorage.GetElement(new ClientSearchModel + { + ClientEmail = model.ClientEmail + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с такой почтой уже есть"); + } + } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs new file mode 100644 index 0000000..8fd92f8 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs @@ -0,0 +1,107 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class EvaluationLogic : IEvaluationLogic + { + private readonly ILogger _logger; + private readonly IEvaluationStorage _evaluationStorage; + public EvaluationLogic(ILogger logger, IEvaluationStorage evaluationStorage) + { + _logger = logger; + _evaluationStorage = evaluationStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _evaluationStorage.GetNumberOfPages(userId, pageSize); + } + public List? ReadList(EvaluationSearchModel? model) + { + _logger.LogInformation("ReadList. Id: {Id}", + model?.Id); + var list = model == null ? _evaluationStorage.GetFullList() : + _evaluationStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public EvaluationViewModel? ReadElement(EvaluationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", model.Id); + var element = _evaluationStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(EvaluationBindingModel model) + { + CheckModel(model); + if (_evaluationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(EvaluationBindingModel model) + { + CheckModel(model); + if (_evaluationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(EvaluationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_evaluationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(EvaluationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PointsProcedure <= 0) + { + throw new ArgumentNullException("Оценки за процедуру должны быть больше 0", nameof(model.PointsProcedure)); + } + _logger.LogInformation("Rating. PointsProcedure: {PointsProcedure}}. Id: {Id}", + model.PointsProcedure, model.PointsCosmetics, model.Id); + } + } +} diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..a285fee --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,106 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _orderStorage.GetNumberOfPages(userId, pageSize); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. OrderDate: {OrderDate}. Id: {Id}", + model.OrderDate, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.OrderAmount <= 0) + { + throw new ArgumentNullException("Cумма заказа должна быть больше 0", + nameof(model.OrderAmount)); + } + } + } +} diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs new file mode 100644 index 0000000..dc036c6 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs @@ -0,0 +1,123 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class ProcedureLogic : IProcedureLogic + { + private readonly ILogger _logger; + private readonly IProcedureStorage _procedureStorage; + public ProcedureLogic(ILogger logger, IProcedureStorage procedureStorage) + { + _logger = logger; + _procedureStorage = procedureStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _procedureStorage.GetNumberOfPages(userId, pageSize); + } + + public List? ReadList(ProcedureSearchModel? model) + { + _logger.LogInformation("ReadList. ProcedureName: {ProcedureName}. Id: {Id}", + model?.ProcedureName, model?.Id); + var list = model == null ? _procedureStorage.GetFullList() : + _procedureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public ProcedureViewModel? ReadElement(ProcedureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProcedureName: {ProcedureName}. Id: {Id}", + model.ProcedureName, model.Id); + var element = _procedureStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(ProcedureBindingModel model) + { + CheckModel(model); + if (_procedureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProcedureBindingModel model) + { + CheckModel(model); + if (_procedureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProcedureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_procedureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProcedureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProcedureName)) + { + throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProcedureName)); + } + + if (model.ProcedurePrice <= 0) + { + throw new ArgumentNullException("Цена процедуры должна быть больше 0", + nameof(model.ProcedurePrice)); + } + _logger.LogInformation("Procedure. ProcedureName: {ProcedureName}. Cost: {Cost}. Id: {Id}", + model.ProcedureName, model.ProcedurePrice, model.Id); + var element = _procedureStorage.GetElement(new ProcedureSearchModel + { + ProcedureName = model.ProcedureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Процедура с таким названием уже есть"); + } + } + } +}