AccountingWarehouseProducts.../AccountingWarehouseProducts/AccountingWarehouseProductsBusinessLogic/BusinessLogic/ShipmentLogic.cs

90 lines
2.5 KiB
C#

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 ShipmentLogic : IShipmentLogic
{
private readonly IShipmentStorage _shipmentStorage;
public ShipmentLogic(IShipmentStorage shipmentStorage)
{
_shipmentStorage = shipmentStorage;
}
public ShipmentViewModel? ReadElement(ShipmentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _shipmentStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<ShipmentViewModel>? ReadList(ShipmentSearchModel? model)
{
var list = model == null ? _shipmentStorage.GetFullList() : _shipmentStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Create(ShipmentBindingModel model)
{
CheckModel(model);
if (_shipmentStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(ShipmentBindingModel model)
{
CheckModel(model, false);
if (_shipmentStorage.Delete(model) == null)
{
return false;
}
return true;
}
public bool Update(ShipmentBindingModel model)
{
CheckModel(model);
if (_shipmentStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ShipmentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
}
}
}