61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using ClientsContracts.BindingModels;
|
|
using ClientsContracts.BusinessLogicContracts;
|
|
using ClientsContracts.StorageContracts;
|
|
using ClientsContracts.ViewModels;
|
|
|
|
namespace ClientBusinessLogic.BusinessLogics
|
|
{
|
|
public class StatusLogic : IStatusLogic
|
|
{
|
|
private readonly IStatusStorage _statusStorage;
|
|
public StatusLogic(IStatusStorage statusStorage)
|
|
{
|
|
_statusStorage = statusStorage;
|
|
}
|
|
|
|
public void CreateOrUpdate(StatusBindingModel model)
|
|
{
|
|
var element = _statusStorage.GetElement(
|
|
new StatusBindingModel
|
|
{
|
|
Name = model.Name
|
|
});
|
|
if (element != null && element.Id != model.Id)
|
|
{
|
|
throw new Exception("Такой статус уже существует");
|
|
}
|
|
if (model.Id.HasValue)
|
|
{
|
|
_statusStorage.Update(model);
|
|
}
|
|
else
|
|
{
|
|
_statusStorage.Insert(model);
|
|
}
|
|
}
|
|
|
|
public void Delete(StatusBindingModel model)
|
|
{
|
|
var element = _statusStorage.GetElement(new StatusBindingModel { Id = model.Id });
|
|
if (element == null)
|
|
{
|
|
throw new Exception("Статус не найден");
|
|
}
|
|
_statusStorage.Delete(model);
|
|
}
|
|
|
|
public List<StatusViewModel> Read(StatusBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return _statusStorage.GetFullList();
|
|
}
|
|
if (model.Id.HasValue)
|
|
{
|
|
return new List<StatusViewModel> { _statusStorage.GetElement(model) };
|
|
}
|
|
return _statusStorage.GetFilteredList(model);
|
|
}
|
|
}
|
|
}
|