From cdc9aca2034308026c9b8331763fc2bf517f51a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 01:03:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 59 ++++++++----------- .../StoragesContracts/IOrderStorage.cs | 1 - .../Implements/OrderStorage.cs | 12 ---- .../Models/Order.cs | 16 ----- 4 files changed, 23 insertions(+), 65 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 9dcfd5d..b90dd14 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,15 +32,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status == OrderStatus.Неизвестен) - { - model.Status = OrderStatus.Принят; - } - else - { - _logger.LogWarning("Create order operation failed"); - return false; - } + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Create order operation failed"); @@ -58,16 +50,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Принят) { model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } + _logger.LogWarning("Take order in work operation failed"); + return false; } public bool FinishOrder(OrderBindingModel model) { @@ -80,16 +69,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Finish order operation failed"); - return false; - } + _logger.LogWarning("Finish order operation failed"); + return false; } public bool DeliveryOrder(OrderBindingModel model) { @@ -101,16 +87,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Готов) { model.Status = OrderStatus.Выдан; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } + _logger.LogWarning("Delivery order operation failed"); + return false; } private void CheckModel(OrderBindingModel model, bool withParams = true) { @@ -130,6 +113,10 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count)); } + if (model.Status != OrderStatus.Неизвестен) + { + throw new ArgumentException("Заказ не в статусе Неизвестен"); + } _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); var element = _orderStorage.GetElement(new OrderSearchModel { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index 3b385e4..d6e3ec4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,6 +12,5 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); - OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index e8a4b84..68e7ece 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,17 +96,5 @@ namespace BlacksmithWorkshopListImplement.Implements } return null; } - public OrderViewModel? UpdateOrderStatus(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.UpdateStatus(model); - return order.GetViewModel; - } - } - return null; - } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 935da6e..82309c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -40,25 +40,9 @@ namespace BlacksmithWorkshopListImplement.Models { return; } - ManufactureId = model.ManufactureId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } - public void UpdateStatus(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.DateImplement != null) - { - DateImplement = model.DateImplement; - } - } public OrderViewModel GetViewModel => new() { Id = Id,