AccountingWarehouseProducts.../AccountingWarehouseProducts/AccountingWarehouseProductsBusinessLogic/BusinessLogic/OrderLogic.cs

137 lines
4.0 KiB
C#
Raw Normal View History

using AccountingWarehouseProductsContracts.BindingModels;
using AccountingWarehouseProductsContracts.BusinessLogicsContracts;
using AccountingWarehouseProductsContracts.SearchModels;
using AccountingWarehouseProductsContracts.StoragesContracts;
using AccountingWarehouseProductsContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AccountingWarehouseProductsBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly IOrderStorage _orderStorage;
public OrderLogic(IOrderStorage orderStorage)
{
_orderStorage = orderStorage;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _orderStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Create(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(OrderBindingModel model)
{
CheckModel(model, false);
if (_orderStorage.Delete(model) == null)
{
return false;
}
return true;
}
public bool Update(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool OrderedOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Заказан);
}
public bool ComeOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Пришёл);
}
public bool TakeOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Принят);
}
public bool ArrangeOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Расстановлен);
}
public bool ChekOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Проверен);
}
public bool DeliverOrder(OrderBindingModel model)
{
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Доставлен);
}
private bool StatusUpdate(OrderBindingModel model, AccountingWarehouseProductsDataModels.Enums.OrderStatus newStatus)
{
if (model.Status + 1 != newStatus)
{
return false;
}
model.Status = newStatus;
if (_orderStorage.Update(model) == null)
{
model.Status--;
return false;
}
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
}
}
}