94 lines
2.7 KiB
C#
94 lines
2.7 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 WarehouseLogic : IWarehouseLogic
|
|
{
|
|
private readonly IWarehouseStorage _warehouseStorage;
|
|
|
|
public WarehouseLogic(IWarehouseStorage warehouseStorage)
|
|
{
|
|
_warehouseStorage = warehouseStorage;
|
|
}
|
|
public WarehouseViewModel? ReadElement(WarehouseSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
var element = _warehouseStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<WarehouseViewModel>? ReadList(WarehouseSearchModel? model)
|
|
{
|
|
var list = model == null ? _warehouseStorage.GetFullList() : _warehouseStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Create(WarehouseBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_warehouseStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(WarehouseBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_warehouseStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Update(WarehouseBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_warehouseStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(WarehouseBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.WarehouseName))
|
|
{
|
|
throw new ArgumentNullException("Нет названия", nameof(model.WarehouseName));
|
|
}
|
|
}
|
|
}
|
|
}
|