94 lines
2.6 KiB
C#
94 lines
2.6 KiB
C#
|
using AccountsContracts.BindingModels;
|
|||
|
using AccountsContracts.BusinessLogicContracts;
|
|||
|
using AccountsContracts.SearchModels;
|
|||
|
using AccountsContracts.StorageContracts;
|
|||
|
using AccountsContracts.ViewModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace AccountsBusinessLogic.BusinessLogics
|
|||
|
{
|
|||
|
public class InterestLogic : IInterestLogic
|
|||
|
{
|
|||
|
private readonly IInterestStorage _interestStorage;
|
|||
|
|
|||
|
public InterestLogic(IInterestStorage interestStorage)
|
|||
|
{
|
|||
|
_interestStorage = interestStorage;
|
|||
|
}
|
|||
|
|
|||
|
public List<InterestViewModel>? ReadList(InterestSearchModel? model)
|
|||
|
{
|
|||
|
var list = model == null ? _interestStorage.GetFullList() : _interestStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public InterestViewModel? ReadElement(InterestSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
var element = _interestStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(InterestBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_interestStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(InterestBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_interestStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
public bool Delete(InterestBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_interestStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(InterestBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Name))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Нет названия интереса", nameof(model.Name));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|