From b53646627e1a48e25d94793a25c91953eb5de350 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Wed, 8 May 2024 12:52:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D1=83=20=D0=B2=D1=80=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IceCreamShop/IceCreamShop/ShopForm.cs | 3 ++- .../BusinessLogic/OrderLogic.cs | 13 ++++++---- .../BusinessLogic/WorkModeling.cs | 24 +++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/IceCreamShop/IceCreamShop/ShopForm.cs b/IceCreamShop/IceCreamShop/ShopForm.cs index c0d4f89..4d15e83 100644 --- a/IceCreamShop/IceCreamShop/ShopForm.cs +++ b/IceCreamShop/IceCreamShop/ShopForm.cs @@ -105,8 +105,9 @@ namespace IceCreamShop Address = AddressTextBox.Text, DateOpen = DateTimePicker.Value.Date, MaxCapacity = Convert.ToInt32(CapacityUpDown.Value), - ShopIceCreams = null }; + if (_id.HasValue) + model.ShopIceCreams = null; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs index cfd154a..4840b1e 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -144,12 +144,19 @@ namespace IceCreamShopBusinessLogic.BusinessLogic _logger.LogWarning("Read operation failed"); return false; } - if (element.Status != status - 1 && status != OrderStatus.Ожидается) + if (element.Status != status - 1 && status != OrderStatus.Ожидается && element.Status != OrderStatus.Ожидается) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if(element.Status == OrderStatus.Выполняется) + model.Sum = element.Sum; + model.Count = element.Count; + model.IceCreamId = element.IceCreamId; + model.DateCreate = element.DateCreate; + model.DateImplement = element.DateImplement; + if (element.ImplementerId.HasValue && element.ImplementerId != 0) + model.ImplementerId = element.ImplementerId; + if (status == OrderStatus.Готов) { var icecream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = model.IceCreamId }); if (icecream == null) @@ -166,8 +173,6 @@ namespace IceCreamShopBusinessLogic.BusinessLogic } model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - if (element.ImplementerId.HasValue) - model.ImplementerId = element.ImplementerId; _orderStorage.Update(model); return true; } diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/WorkModeling.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/WorkModeling.cs index 0582aa9..89c4bcd 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/WorkModeling.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/WorkModeling.cs @@ -37,11 +37,6 @@ namespace IceCreamShopBusinessLogic.BusinessLogic Status = OrderStatus.Принят }); - if (orders == null || orders.Count == 0) - { - _logger.LogWarning("DoWork. Orders is null or empty"); - return; - } _logger.LogDebug("DoWork for {Count} orders", orders.Count); foreach (var implementer in implementers) { @@ -151,22 +146,25 @@ namespace IceCreamShopBusinessLogic.BusinessLogic } try { - var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + var orders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel { ImplementerId = implementer.Id, Status = OrderStatus.Ожидается, })); - if (order == null) + if (orders == null || orders.Count == 0) { return; } - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - _orderLogic.DeliveryOrder(new OrderBindingModel + foreach (var order in orders) { - Id = order.Id, - ImplementerId = implementer.Id - }); - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } } catch (InvalidOperationException ex) {