From aab26ccc29f6578f7fcb23bd338e59dfc0c1a43f Mon Sep 17 00:00:00 2001 From: Ino Date: Mon, 30 Jan 2023 15:29:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20OrderLogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 49 ++++++++++++++----- IceCreamShop/IceCreamShop.sln | 2 +- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs index 417ac7f..c60bbb1 100644 --- a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs @@ -44,33 +44,41 @@ namespace IceCreamBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - throw new NotImplementedException(); + return SetNewStatus(model, OrderStatus.Готов); } public bool FinishOrder(OrderBindingModel model) { - throw new NotImplementedException(); - } - - public List? ReadList(OrderSearchModel? model) - { - throw new NotImplementedException(); + return SetNewStatus(model, OrderStatus.Выдан); } public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + return SetNewStatus(model, OrderStatus.Выполняется); } - private void CheckModel(OrderBindingModel model, bool withParams = true) + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderID:{IceCreamName}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(OrderBindingModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) + if (model.Id < 0) { - return; + throw new ArgumentNullException("Некорректный идентификатор заказа", nameof(model.Id)); } if (model.IceCreamId < 0) { @@ -86,5 +94,24 @@ namespace IceCreamBusinessLogic.BusinessLogics } _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId); } + + public bool SetNewStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } } } diff --git a/IceCreamShop/IceCreamShop.sln b/IceCreamShop/IceCreamShop.sln index 5222396..b6c01d0 100644 --- a/IceCreamShop/IceCreamShop.sln +++ b/IceCreamShop/IceCreamShop.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32922.545 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShop", "IceCreamShop\IceCreamShop.csproj", "{B91C88F0-28AC-47D1-8DDE-B5275C08CAC2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopView", "IceCreamShop\IceCreamShopView.csproj", "{B91C88F0-28AC-47D1-8DDE-B5275C08CAC2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopDataModels", "IceCreamShopDataModels\IceCreamShopDataModels.csproj", "{998D2482-F931-4FEF-86E9-C21D6757B73A}" EndProject