2024-11-27 23:43:53 +04:00

86 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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("Что-то с именем клиента - его нет почему-то");
}
}
}
}