вроде работает

This commit is contained in:
Inohara 2023-04-09 20:36:57 +04:00
parent b489c47251
commit ccfced6fd3
2 changed files with 21 additions and 35 deletions

View File

@ -95,45 +95,32 @@ namespace IceCreamBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
}
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
public bool SetNewStatus(OrderBindingModel model, OrderStatus orderStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel
// Находим статус заказа по его айди
var vmodel = _orderStorage.GetElement(new() { Id = model.Id });
if (vmodel == null)
{
Id = rawModel.Id
});
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
throw new ArgumentNullException(nameof(model));
}
OrderBindingModel model = new OrderBindingModel
if ((int)vmodel.Status + 1 != (int)orderStatus)
{
Id = viewModel.Id,
IceCreamId = viewModel.IceCreamId,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum
};
if (rawModel.ImplementerId.HasValue)
{
model.ImplementerId = rawModel.ImplementerId;
throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
$"Текущий статус: {vmodel.Status} \n" +
$"Планируемый статус: {orderStatus} \n" +
$"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}");
}
CheckModel(model);
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
model.Status = orderStatus;
model.DateCreate = vmodel.DateCreate;
if (model.DateImplement == null)
model.DateImplement = vmodel.DateImplement;
if (vmodel.ImplementerId.HasValue)
model.ImplementerId = vmodel.ImplementerId;
model.IceCreamId = vmodel.IceCreamId;
model.Sum = vmodel.Sum;
model.Count = vmodel.Count;
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}

View File

@ -72,12 +72,11 @@ namespace IceCreamBusinessLogic.BusinessLogic
ImplementerId = implementer.Id
});
// делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
Thread.Sleep(implementer.WorkExperience * _rnd.Next(200, 500) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = order.Id,
ImplementerId = implementer.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
@ -121,7 +120,7 @@ namespace IceCreamBusinessLogic.BusinessLogic
// доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = runOrder.Id
});