88 lines
2.3 KiB
C#
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 ClientLogic : IClientLogic
|
|||
|
{
|
|||
|
private readonly IClientStorage _clientStorage;
|
|||
|
|
|||
|
public ClientLogic(IClientStorage clientStorage)
|
|||
|
{
|
|||
|
_clientStorage = clientStorage;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_clientStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_clientStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public ClientViewModel? ReadElement(ClientSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
var element = _clientStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
|||
|
{
|
|||
|
var list = _clientStorage.GetFullList();
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(ClientBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_clientStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Name))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Client's name is missing!", nameof(model.Name));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|