86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
using Contracts.BindingModels;
|
||
using Contracts.BusinessLogicContracts;
|
||
using Contracts.SearchModels;
|
||
using Contracts.StorageContracts;
|
||
using Contracts.ViewModels;
|
||
|
||
namespace BusinessLogic
|
||
{
|
||
public class CityLogic : ICityStatusLogic
|
||
{
|
||
ICityStorage _orderStorage;
|
||
|
||
public CityLogic(ICityStorage orderStorage)
|
||
{
|
||
_orderStorage = orderStorage;
|
||
}
|
||
|
||
public bool Create(CityBindingModel model)
|
||
{
|
||
CheckModel(model, false);
|
||
if (_orderStorage.Insert(model) == null)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public bool Delete(CityBindingModel model)
|
||
{
|
||
CheckModel(model, false);
|
||
if (_orderStorage.Delete(model) == null)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public CityViewModel? ReadElement(CitySearchModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return null;
|
||
}
|
||
var element = _orderStorage.GetElement(model);
|
||
if (element == null)
|
||
{
|
||
return null;
|
||
}
|
||
return element;
|
||
}
|
||
|
||
public List<CityViewModel>? ReadList(CitySearchModel? model)
|
||
{
|
||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||
if (list == null)
|
||
{
|
||
return null;
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public bool Update(CityBindingModel model)
|
||
{
|
||
CheckModel(model, false);
|
||
if (_orderStorage.Update(model) == null) { return false; }
|
||
return true;
|
||
}
|
||
|
||
private void CheckModel(CityBindingModel model, bool param = true)
|
||
{
|
||
if (model == null)
|
||
{
|
||
throw new ArgumentNullException($"Объект \"{model}\" нулл");
|
||
}
|
||
if (!param)
|
||
{
|
||
return;
|
||
}
|
||
if (model.Name == null || string.IsNullOrEmpty(model.Name))
|
||
{
|
||
throw new ArgumentNullException("Что-то с именем клиента - его нет почему-то");
|
||
}
|
||
}
|
||
}
|
||
}
|