Исправления алгоритма обновления статуса заказа.

This commit is contained in:
Programmist73 2023-02-24 11:58:18 +04:00
parent e41554b69c
commit d11fc9960b
2 changed files with 19 additions and 22 deletions

View File

@ -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<OrderStatus>(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<OrderStatus>(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<OrderStatus>(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)

View File

@ -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--;