From 3155cd0b0d824b30116857f851cb6f010d0ff27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 27 Feb 2023 03:19:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=201.=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FormMain.cs | 36 +++---------------- .../BusinessLogics/OrderLogic.cs | 11 +++--- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs index b175c4a..63f690d 100644 --- a/FlowerShop/FlowerShop/FormMain.cs +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -79,15 +79,7 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Processing'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { @@ -114,19 +106,11 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Ready'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { _logger.LogError("Error during changing order's status to 'Ready'"); - MessageBox.Show("Заказ должен быть в состоянии 'В работе'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заказ должен быть в состоянии 'Выполняется'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } @@ -147,16 +131,7 @@ namespace FlowerShop _logger.LogInformation("Order №{id}. Changing status to 'Delivered'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new - OrderBindingModel - { - Id = id, - BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { @@ -169,8 +144,7 @@ namespace FlowerShop catch (Exception ex) { _logger.LogError(ex, "Error during changing order's status to 'Delivered'"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs index 4a72073..9ef4477 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -59,7 +59,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Принят) + if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят) { _logger.LogWarning("Invalid order status"); return false; @@ -78,13 +78,14 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Выполняется) + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) { _logger.LogWarning("Invalid order status"); return false; } model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) { @@ -98,14 +99,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Готов) + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (order?.Status != OrderStatus.Готов) { _logger.LogWarning("Invalid order status"); return false; } model.Status = OrderStatus.Выдан; - model.DateImplement = DateTime.Now; + model.DateImplement = order.DateImplement; if (_orderStorage.Update(model) == null) {