From c853623a812873e85c4ffc9fbb327bb4a033f80f Mon Sep 17 00:00:00 2001 From: Dasha Date: Sun, 12 May 2024 21:31:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=82=D1=81=D1=82=D1=83=D0=BF=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 164 +++++++++--------- .../Controllers/ClientController.cs | 98 +++++------ 2 files changed, 131 insertions(+), 131 deletions(-) diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index ef1e5d3..e05e7e3 100644 --- a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -9,44 +9,44 @@ using FishFactoryDataModels.Enums; namespace FishFactoryBusinessLogic.BusinessLogics { - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; private readonly AbstractMailWorker _mailWorker; private readonly IClientLogic _clientLogic; static readonly object _locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) { - _logger = logger; - _orderStorage = orderStorage; + _logger = logger; + _orderStorage = orderStorage; _mailWorker = mailWorker; _clientLogic = clientLogic; } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) - { - _logger.LogWarning("Insert operation failed. Order status incorrect."); - return false; - } - model.Status = OrderStatus.Принят; + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; var result = _orderStorage.Insert(model); if (result == null) { - model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Insert operation failed"); - return false; - } + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } SendOrderMessage(result.ClientId, $"Рыбный завод, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; - } + } - public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) - { + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (viewModel == null) { @@ -54,10 +54,10 @@ namespace FishFactoryBusinessLogic.BusinessLogics } if (viewModel.Status + 1 != newStatus) { - _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); - return false; - } - model.Status = newStatus; + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; else { @@ -67,45 +67,45 @@ namespace FishFactoryBusinessLogic.BusinessLogics var result = _orderStorage.Update(model); if (result == null) { - model.Status--; - _logger.LogWarning("Update operation failed"); - return false; - } + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } SendOrderMessage(result.ClientId, $"Рыбный завод, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); return true; - } + } - public bool TakeOrderInWork(OrderBindingModel model) - { - lock (_locker) - { - return StatusUpdate(model, OrderStatus.Выполняется); - } - - } + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (_locker) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } - public bool DeliveryOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Выдан); - } + } - public bool FinishOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Готов); - } + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } - 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 bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + 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) { @@ -125,29 +125,29 @@ namespace FishFactoryBusinessLogic.BusinessLogics } private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.CannedId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор у консервы", nameof(model.CannedId)); - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество консервы в заказе должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); - } - _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. CannedId: { CannedId}", model.Id, model.Sum, model.CannedId); - } + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.CannedId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у консервы", nameof(model.CannedId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество консервы в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. CannedId: { CannedId}", model.Id, model.Sum, model.CannedId); + } private bool SendOrderMessage(int clientId, string subject, string text) { diff --git a/FishFactory/FishFactoryRestApi/Controllers/ClientController.cs b/FishFactory/FishFactoryRestApi/Controllers/ClientController.cs index 469c4a0..fafffb9 100644 --- a/FishFactory/FishFactoryRestApi/Controllers/ClientController.cs +++ b/FishFactory/FishFactoryRestApi/Controllers/ClientController.cs @@ -7,68 +7,68 @@ using System.Net; namespace FishFactoryRestApi.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] - public class ClientController : Controller - { - private readonly ILogger _logger; + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; - private readonly IClientLogic _logic; + private readonly IClientLogic _logic; private readonly IMessageInfoLogic _mailLogic; public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { - _logger = logger; - _logic = logic; + _logger = logger; + _logic = logic; _mailLogic = mailLogic; } - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); Response.StatusCode = (int)HttpStatusCode.NotAcceptable; } - } + } - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } [HttpGet] public List? GetMessages(int clientId)