90 lines
2.4 KiB
C#
90 lines
2.4 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 StandLogic : IStandLogic
|
|||
|
{
|
|||
|
private readonly IStandStorage _standStorage;
|
|||
|
|
|||
|
public StandLogic(IStandStorage standStorage)
|
|||
|
{
|
|||
|
_standStorage = standStorage;
|
|||
|
}
|
|||
|
public StandViewModel? ReadElement(StandSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
|
|||
|
var element = _standStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public List<StandViewModel>? ReadList(StandSearchModel? model)
|
|||
|
{
|
|||
|
var list = model == null ? _standStorage.GetFullList() : _standStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(StandBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_standStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(StandBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_standStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(StandBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_standStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(StandBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|