ISEbd-21 Melnikov I. O. Lab work 01 Base #1

Closed
Igor-Melnikov wants to merge 13 commits from lab1 into main
Showing only changes of commit f4e845ee60 - Show all commits

View File

@ -29,6 +29,28 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
_logger.LogInformation("Readlist. Count: {Count}", list.Count);
return list;
}
public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus)
{
OrderViewModel? vm = _orderStorage.GetElement(new()
{
Id = model.Id
});
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if ((int)model.Status == (int)newstatus - 1)
{
model.Status = newstatus;
if (newstatus == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) != null)
{
return true;
}
}
_logger.LogWarning($"Changing order status of order {model.Id} to {newstatus} failed");
return false;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
@ -43,61 +65,9 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
_logger.LogWarning("Create order operation failed");
return false;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
OrderViewModel? vm = _orderStorage.GetElement(new()
{
Id = model.Id
});
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if (model.Status == OrderStatus.Принят)
{
model.Status = OrderStatus.Выполняется;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
_logger.LogWarning("Take order in work operation failed");
return false;
}
public bool FinishOrder(OrderBindingModel model)
{
OrderViewModel? vm = _orderStorage.GetElement(new()
{
Id = model.Id
});
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if (model.Status == OrderStatus.Выполняется)
{
model.Status = OrderStatus.Готов;
model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
_logger.LogWarning("Finish order operation failed");
return false;
}
public bool DeliveryOrder(OrderBindingModel model)
{
OrderViewModel? vm = _orderStorage.GetElement(new()
{
Id = model.Id
});
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if (model.Status == OrderStatus.Готов)
{
model.Status = OrderStatus.Выдан;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
_logger.LogWarning("Delivery order operation failed");
return false;
}
public bool TakeOrderInWork(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выполняется);
public bool FinishOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Готов);
public bool DeliveryOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выдан);
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)