99 lines
2.9 KiB
C#
99 lines
2.9 KiB
C#
using Subd_4.BindingModels;
|
|
using Subd_4.BusinessLogicContracts;
|
|
using Subd_4.SearchModels;
|
|
using Subd_4.StoragesContracts;
|
|
using Subd_4.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConstructionFirmBusinessLogic.BusinessLogics
|
|
{
|
|
public class ConstructionMaterialLogic : IConstructionMaterialLogic
|
|
{
|
|
private readonly IConstructionMaterialStorage _ConstructionMaterialStorage;
|
|
|
|
public ConstructionMaterialLogic(IConstructionMaterialStorage ConstructionMaterialStorage)
|
|
{
|
|
_ConstructionMaterialStorage = ConstructionMaterialStorage;
|
|
}
|
|
public ConstructionMaterialViewModel? ReadElement(ConstructionMaterialSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
var element = _ConstructionMaterialStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<ConstructionMaterialViewModel>? ReadList(ConstructionMaterialSearchModel? model)
|
|
{
|
|
var list = model == null ? _ConstructionMaterialStorage.GetFullList() : _ConstructionMaterialStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Create(ConstructionMaterialBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_ConstructionMaterialStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(ConstructionMaterialBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_ConstructionMaterialStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Update(ConstructionMaterialBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_ConstructionMaterialStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(ConstructionMaterialBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.MaterialName))
|
|
{
|
|
throw new ArgumentNullException("Нет названия", nameof(model.MaterialName));
|
|
}
|
|
}
|
|
|
|
public void ClearEntity()
|
|
{
|
|
_ConstructionMaterialStorage.ClearEntity();
|
|
}
|
|
}
|
|
}
|