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

This commit is contained in:
Programmist73 2023-02-24 11:49:17 +04:00
parent 3cd62dec9e
commit b187f20196
2 changed files with 18 additions and 21 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;
@ -144,9 +150,15 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
model.DateImplement = DateTime.Now;
}
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
//финальная проверка на возможность обновления
if(_orderStorage.Update(model) == null)
if (_orderStorage.Update(model) == null)
{
model.Status--;