diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 37a970d..a8faa65 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,12 +99,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].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()) + Id = id }); if (!operationResult) @@ -133,12 +128,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].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()) + Id = id }); if (!operationResult) @@ -167,12 +157,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].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()) + Id = id }); if (!operationResult) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index d1b08bb..ab54224 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -128,10 +128,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //обновление статуса заказа public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + //если не смогли найти указанный заказ по его Id + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } //проверка на возможность обновления статуса на следующий - if(model.Status + 1 != newOrderStatus) + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + " incorrect"); return false; @@ -140,13 +146,19 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.Status = newOrderStatus; //проверка на выдачу - if(model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Выдан) { model.DateImplement = DateTime.Now; } + else + { + model.DateImplement = viewModel.DateImplement; + } + + CheckModel(model, false); //финальная проверка на возможность обновления - if(_orderStorage.Update(model) == null) + if (_orderStorage.Update(model) == null) { model.Status--;