Временный рабочий вариант

This commit is contained in:
Мк Игорь 2023-02-15 00:03:28 +04:00
parent 84ae8be0ee
commit 7db5841339
5 changed files with 36 additions and 26 deletions

View File

@ -99,7 +99,9 @@ namespace BlacksmithWorkshopView
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ Id = id });
{
Id = id
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");

View File

@ -51,8 +51,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model);
if ((int)model.Status > -1 || _orderStorage.UpdateOrderStatus(model) == null)
OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id });
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if ((int)model.Status > -1)
{
model.Status = OrderStatus.Выполняется;
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
@ -61,54 +66,43 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
_logger.LogWarning("Take order in work operation failed");
return false;
}
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Take order in work operation failed");
return false;
}
model.Status = OrderStatus.Выполняется;
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model);
OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id });
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if ((int)model.Status > 0)
{
model.Status = OrderStatus.Готов;
model.DateImplement = DateTime.Now;
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
else
{
_logger.LogWarning("Finish order operation failed");
return false;
}
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Finish order operation failed");
return false;
}
model.Status = OrderStatus.Готов;
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
CheckModel(model);
OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id });
model.Status = vm?.Status ?? OrderStatus.Неизвестен;
if ((int)model.Status > 1)
{
model.Status = OrderStatus.Выдан;
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
else
{
_logger.LogWarning("Delivery order operation failed");
return false;
}
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Delivery order operation failed");
return false;
}
model.Status = OrderStatus.Выдан;
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{

View File

@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
OrderViewModel? UpdateOrderStatus(OrderBindingModel model);
}
}

View File

@ -96,5 +96,17 @@ namespace BlacksmithWorkshopListImplement.Implements
}
return null;
}
public OrderViewModel? UpdateOrderStatus(OrderBindingModel model)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
order.UpdateStatus(model);
return order.GetViewModel;
}
}
return null;
}
}
}

View File

@ -52,6 +52,7 @@ namespace BlacksmithWorkshopListImplement.Models
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{