PIbd-32_Bulatova_K.R._COP_10/COP/ClientBusinessLogic/BusinessLogics/StatusLogic.cs
2024-10-29 09:22:02 +04:00

88 lines
2.3 KiB
C#

using ClientsContracts.BindingModels;
using ClientsContracts.BusinessLogicContracts;
using ClientsContracts.SearchModels;
using ClientsContracts.StorageContracts;
using ClientsContracts.ViewModels;
namespace ClientBusinessLogic.BusinessLogics
{
public class StatusLogic : IStatusLogic
{
private readonly IStatusStorage _statusStorage;
public StatusLogic(IStatusStorage statusStorage)
{
_statusStorage = statusStorage;
}
public bool Create(StatusBindingModel model)
{
CheckModel(model);
if (_statusStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(StatusBindingModel model)
{
CheckModel(model, false);
if (_statusStorage.Delete(model) == null)
{
return false;
}
return true;
}
public StatusViewModel? ReadElement(StatusSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _statusStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<StatusViewModel>? ReadList()
{
var list = _statusStorage.GetFullList();
if (list == null)
{
return null;
}
return list;
}
public bool Update(StatusBindingModel model)
{
CheckModel(model);
if (_statusStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(StatusBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.StatusName))
{
throw new ArgumentNullException("Status's name is missing!", nameof(model.StatusName));
}
}
}
}