diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 9dcfd5d..b90dd14 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,15 +32,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status == OrderStatus.Неизвестен) - { - model.Status = OrderStatus.Принят; - } - else - { - _logger.LogWarning("Create order operation failed"); - return false; - } + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Create order operation failed"); @@ -58,16 +50,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Принят) { model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } + _logger.LogWarning("Take order in work operation failed"); + return false; } public bool FinishOrder(OrderBindingModel model) { @@ -80,16 +69,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Finish order operation failed"); - return false; - } + _logger.LogWarning("Finish order operation failed"); + return false; } public bool DeliveryOrder(OrderBindingModel model) { @@ -101,16 +87,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Готов) { model.Status = OrderStatus.Выдан; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } + _logger.LogWarning("Delivery order operation failed"); + return false; } private void CheckModel(OrderBindingModel model, bool withParams = true) { @@ -130,6 +113,10 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count)); } + if (model.Status != OrderStatus.Неизвестен) + { + throw new ArgumentException("Заказ не в статусе Неизвестен"); + } _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); var element = _orderStorage.GetElement(new OrderSearchModel { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index 3b385e4..d6e3ec4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,6 +12,5 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); - OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index e8a4b84..68e7ece 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,17 +96,5 @@ 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 935da6e..82309c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -40,25 +40,9 @@ namespace BlacksmithWorkshopListImplement.Models { return; } - ManufactureId = model.ManufactureId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } - public void UpdateStatus(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.DateImplement != null) - { - DateImplement = model.DateImplement; - } - } public OrderViewModel GetViewModel => new() { Id = Id,