From 52a214bb7f8f9eaa60989a65adc4adf7af517a4d Mon Sep 17 00:00:00 2001 From: dimazhelovanov Date: Wed, 17 May 2023 12:24:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/WorkModeling.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs index 3424475..16453bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -73,22 +73,25 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics try { _logger.LogDebug("DoWork. Worker {Id} try get order { Order}", implementer.Id, order.Id); - // пытаемся назначить заказ на исполнителя -_orderLogic.TakeOrderInWork(new OrderBindingModel -{ - Id = order.Id, - ImplementerId = implementer.Id -}); - - // делаем работу - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, - 1000) * order.Count); - _logger.LogDebug("DoWork. Worker {Id} finish order { Order} ", implementer.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel - { - Id = order.Id, - ImplementerId = implementer.Id - }); + // пытаемся назначить заказ на исполнителя + if ( + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + })) + { + + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, + 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order { Order} ", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + } } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex)