From 7db58413395a939084fd7912e0b666244809831e 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: Wed, 15 Feb 2023 00:03:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 4 +- .../BusinessLogics/OrderLogic.cs | 44 ++++++++----------- .../StoragesContracts/IOrderStorage.cs | 1 + .../Implements/OrderStorage.cs | 12 +++++ .../Models/Order.cs | 1 + 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 84ccd87..6c5dea2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,7 +99,9 @@ namespace BlacksmithWorkshopView try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { Id = id }); + { + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 10ce8dc..039fefd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -51,8 +51,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model); - if ((int)model.Status > -1 || _orderStorage.UpdateOrderStatus(model) == null) + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; + if ((int)model.Status > -1) + { + model.Status = OrderStatus.Выполняется; + } + if (_orderStorage.UpdateOrderStatus(model) != null) { return true; } @@ -61,54 +66,43 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Take order in work operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } - model.Status = OrderStatus.Выполняется; - return true; } public bool FinishOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 0) { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Finish order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Finish order operation failed"); - return false; - } - model.Status = OrderStatus.Готов; - return true; } public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 1) { model.Status = OrderStatus.Выдан; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Delivery order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } - model.Status = OrderStatus.Выдан; - return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index fd915a1..40f6ee1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); + OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 68e7ece..e8a4b84 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,5 +96,17 @@ 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 91747b1..20ea5d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -52,6 +52,7 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() {