diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 84ccd87..6c5dea2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,7 +99,9 @@ namespace BlacksmithWorkshopView try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { Id = id }); + { + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 10ce8dc..039fefd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -51,8 +51,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model); - if ((int)model.Status > -1 || _orderStorage.UpdateOrderStatus(model) == null) + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; + if ((int)model.Status > -1) + { + model.Status = OrderStatus.Выполняется; + } + if (_orderStorage.UpdateOrderStatus(model) != null) { return true; } @@ -61,54 +66,43 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Take order in work operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } - model.Status = OrderStatus.Выполняется; - return true; } public bool FinishOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 0) { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Finish order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Finish order operation failed"); - return false; - } - model.Status = OrderStatus.Готов; - return true; } public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 1) { model.Status = OrderStatus.Выдан; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Delivery order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } - model.Status = OrderStatus.Выдан; - return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index fd915a1..40f6ee1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); + OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 68e7ece..e8a4b84 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,5 +96,17 @@ namespace BlacksmithWorkshopListImplement.Implements } return null; } + public OrderViewModel? UpdateOrderStatus(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.UpdateStatus(model); + return order.GetViewModel; + } + } + return null; + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 91747b1..20ea5d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -52,6 +52,7 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() {