From f4e845ee60b6de438bdf17fb5e5e10c9d8f019e2 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 19:25:02 +0400 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=BF=D1=80=D0=BE=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index e1017b4..b6ef1fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -29,6 +29,28 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogInformation("Readlist. Count: {Count}", list.Count); return list; } + public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus) + { + OrderViewModel? vm = _orderStorage.GetElement(new() + { + Id = model.Id + }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; + if ((int)model.Status == (int)newstatus - 1) + { + model.Status = newstatus; + if (newstatus == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + if (_orderStorage.Update(model) != null) + { + return true; + } + } + _logger.LogWarning($"Changing order status of order {model.Id} to {newstatus} failed"); + return false; + } public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -43,61 +65,9 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Create order operation failed"); return false; } - public bool TakeOrderInWork(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Принят) - { - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Take order in work operation failed"); - return false; - } - public bool FinishOrder(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Выполняется) - { - model.Status = OrderStatus.Готов; - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Finish order operation failed"); - return false; - } - public bool DeliveryOrder(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Готов) - { - model.Status = OrderStatus.Выдан; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Delivery order operation failed"); - return false; - } + public bool TakeOrderInWork(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выполняется); + public bool FinishOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Готов); + public bool DeliveryOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выдан); private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null)