diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 2cda994..7c72a8b 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -108,12 +108,7 @@ namespace FurnitureAssembly { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - int furnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value); - int furnitureCount = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value); - if (!_shopLogic.AddFurnituresAtShops(new FurnitureBindingModel { Id = furnitureId }, furnitureCount)) { - MessageBox.Show("Магазины переполнены. Пополнение невозможно", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); @@ -121,11 +116,7 @@ namespace FurnitureAssembly { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } + LoadData(); } catch (Exception ex) @@ -142,8 +133,7 @@ namespace FurnitureAssembly if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs index 9bd343e..b39df00 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs @@ -17,11 +17,13 @@ namespace FurnitureAssemblyBusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; } private bool ChangeStatus(OrderBindingModel model, OrderStatus orderStatus) @@ -91,6 +93,13 @@ namespace FurnitureAssemblyBusinessLogic { return false; } + + if (!_shopLogic.AddFurnituresAtShops(new FurnitureBindingModel() { Id = model.FurnitureId}, model.Count)) + { + _logger.LogWarning("There are not empty places at shops. Replenishment is impossible"); + return false; + } + if (!ChangeStatus(model, OrderStatus.Выдан)) { _logger.LogWarning("Order's status is wrong"); @@ -101,7 +110,7 @@ namespace FurnitureAssemblyBusinessLogic return true; } - + public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id:{ Id}", model?.Id);