From e017eb770974c6b507e09460892b9c9a07787e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 19:36:42 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/OrderLogic.cs | 12 ++++++------ ConfectionaryBusinessLogic/WorkModeling.cs | 11 +++++++---- Confectionery/FormMain.cs | 8 ++++---- .../BusinessLogicsContracts/IOrderLogic.cs | 7 ++++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ConfectionaryBusinessLogic/OrderLogic.cs b/ConfectionaryBusinessLogic/OrderLogic.cs index a345091..260c988 100644 --- a/ConfectionaryBusinessLogic/OrderLogic.cs +++ b/ConfectionaryBusinessLogic/OrderLogic.cs @@ -41,9 +41,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return true; } - public bool TakeOrderInWork(OrderBindingModel model) => SetOrderStatus(model, OrderStatus.Выполняется); - public bool DeliveryOrder(OrderBindingModel model) => SetOrderStatus(model, OrderStatus.Выдан); - public bool FinishOrder(OrderBindingModel model) + public OrderStatus? TakeOrderInWork(OrderBindingModel model) => SetOrderStatus(model, OrderStatus.Выполняется); + public OrderStatus? DeliveryOrder(OrderBindingModel model) => SetOrderStatus(model, OrderStatus.Выдан); + public OrderStatus? FinishOrder(OrderBindingModel model) { model.DateImplement = DateTime.Now; return SetOrderStatus(model, OrderStatus.Готов); @@ -84,7 +84,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return true; } - private bool SetOrderStatus(OrderBindingModel model, OrderStatus orderStatus) + private OrderStatus? SetOrderStatus(OrderBindingModel model, OrderStatus orderStatus) { // Находим статус заказа по его айди var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); @@ -125,9 +125,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics if (_orderStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); - return false; + return null; } - return true; + return orderStatus; } public OrderViewModel? ReadElement(OrderSearchModel model) diff --git a/ConfectionaryBusinessLogic/WorkModeling.cs b/ConfectionaryBusinessLogic/WorkModeling.cs index 5aee2dc..086925a 100644 --- a/ConfectionaryBusinessLogic/WorkModeling.cs +++ b/ConfectionaryBusinessLogic/WorkModeling.cs @@ -72,8 +72,12 @@ namespace ConfectioneryBusinessLogic } await RunOrderInWork(implementer); - await Task.Run(() => - { + await Task.Run(() => RunWorkToOrders(implementer, orders)); + + } + + private void RunWorkToOrders(ImplementerViewModel implementer, List orders) + { foreach (var order in orders) { try @@ -107,8 +111,7 @@ namespace ConfectioneryBusinessLogic // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } - }); - } + } /// /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 842aba3..9d8489f 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -87,8 +87,8 @@ namespace ConfectioneryView _logger.LogInformation(" No{id}. ' '", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }) ; + if (operationResult == null) { throw new Exception(" . ."); } @@ -116,7 +116,7 @@ namespace ConfectioneryView Id = id, Status = orderStatus }); - if (!operationResult) + if (operationResult == null) { throw new Exception(" . ."); } @@ -141,7 +141,7 @@ namespace ConfectioneryView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) + if (operationResult == null) { throw new Exception(" . ."); } diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs index dfd1797..3de0a87 100644 --- a/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,6 +1,7 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; namespace ConfectioneryContracts.BusinessLogicsContracts { @@ -9,8 +10,8 @@ namespace ConfectioneryContracts.BusinessLogicsContracts List? ReadList(OrderSearchModel? model); OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); - bool TakeOrderInWork(OrderBindingModel model); - bool FinishOrder(OrderBindingModel model); - bool DeliveryOrder(OrderBindingModel model); + OrderStatus? TakeOrderInWork(OrderBindingModel model); + OrderStatus? FinishOrder(OrderBindingModel model); + OrderStatus? DeliveryOrder(OrderBindingModel model); } }