изменение логики смены статуса заказа

This commit is contained in:
Мк Игорь 2023-02-17 01:03:20 +04:00
parent 8bee3f0794
commit cdc9aca203
4 changed files with 23 additions and 65 deletions

View File

@ -32,15 +32,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status == OrderStatus.Неизвестен)
{
model.Status = OrderStatus.Принят;
}
else
{
_logger.LogWarning("Create order operation failed");
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Create order operation failed");
@ -58,16 +50,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
if (model.Status == OrderStatus.Принят)
{
model.Status = OrderStatus.Выполняется;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
else
{
_logger.LogWarning("Take order in work operation failed");
return false;
}
_logger.LogWarning("Take order in work operation failed");
return false;
}
public bool FinishOrder(OrderBindingModel model)
{
@ -80,16 +69,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
{
model.Status = OrderStatus.Готов;
model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
else
{
_logger.LogWarning("Finish order operation failed");
return false;
}
_logger.LogWarning("Finish order operation failed");
return false;
}
public bool DeliveryOrder(OrderBindingModel model)
{
@ -101,16 +87,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
if (model.Status == OrderStatus.Готов)
{
model.Status = OrderStatus.Выдан;
if (_orderStorage.Update(model) != null)
{
return true;
}
}
if (_orderStorage.UpdateOrderStatus(model) != null)
{
return true;
}
else
{
_logger.LogWarning("Delivery order operation failed");
return false;
}
_logger.LogWarning("Delivery order operation failed");
return false;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
@ -130,6 +113,10 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count));
}
if (model.Status != OrderStatus.Неизвестен)
{
throw new ArgumentException("Заказ не в статусе Неизвестен");
}
_logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id);
var element = _orderStorage.GetElement(new OrderSearchModel
{

View File

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

View File

@ -96,17 +96,5 @@ 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

@ -40,25 +40,9 @@ namespace BlacksmithWorkshopListImplement.Models
{
return;
}
ManufactureId = model.ManufactureId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public void UpdateStatus(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
}
}
public OrderViewModel GetViewModel => new()
{
Id = Id,