93 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UchetLabContracts.BindingModels;
using UchetLabContracts.BusinessLogicsContracts;
using UchetLabContracts.SearchModels;
using UchetLabContracts.StorageContracts;
using UchetLabContracts.ViewModels;
namespace UchetLabBusinessLogic.BusinessLogic
{
public class CheckerLogic : ICheckerLogic
{
ICheckerStorage _checkerStorage;
public CheckerLogic(ICheckerStorage checkerStorage)
{
_checkerStorage = checkerStorage;
}
public bool Create(CheckerBindingModel model)
{
CheckModel(model);
if (_checkerStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(CheckerBindingModel model)
{
CheckModel(model, false);
if (_checkerStorage.Delete(model) == null)
{
return false;
}
return true;
}
public CheckerViewModel? ReadElement(CheckerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _checkerStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<CheckerViewModel>? ReadList(CheckerSearchModel? model)
{
var list = model == null ? _checkerStorage.GetFullList() : _checkerStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public bool Update(CheckerBindingModel model)
{
CheckModel(model);
if (_checkerStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(CheckerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("проверяющий не указан", nameof(model.FIO));
}
}
}
}