diff --git a/AbazovApp/AccountsBusinessLogic/AccountsBusinessLogic.csproj b/AbazovApp/AccountsBusinessLogic/AccountsBusinessLogic.csproj new file mode 100644 index 0000000..fa98651 --- /dev/null +++ b/AbazovApp/AccountsBusinessLogic/AccountsBusinessLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AbazovApp/AccountsBusinessLogic/BusinessLogics/AccountLogic.cs b/AbazovApp/AccountsBusinessLogic/BusinessLogics/AccountLogic.cs new file mode 100644 index 0000000..a554301 --- /dev/null +++ b/AbazovApp/AccountsBusinessLogic/BusinessLogics/AccountLogic.cs @@ -0,0 +1,100 @@ +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.Threading.Tasks; + +namespace AccountsBusinessLogic.BusinessLogics +{ + public class AccountLogic : IAccountLogic + { + private readonly IAccountStorage _accountStorage; + + public AccountLogic(IAccountStorage accountStorage) + { + _accountStorage = accountStorage; + } + + public List? ReadList(AccountSearchModel? model) + { + var list = model == null ? _accountStorage.GetFullList() : _accountStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public AccountViewModel? ReadElement(AccountSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _accountStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public bool Create(AccountBindingModel model) + { + CheckModel(model); + if (_accountStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Update(AccountBindingModel model) + { + CheckModel(model); + if (_accountStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(AccountBindingModel model) + { + CheckModel(model, false); + if (_accountStorage.Delete(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(AccountBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет электронной почты пользователя", nameof(model.Email)); + } + } + } +} diff --git a/AbazovApp/AccountsBusinessLogic/BusinessLogics/InterestLogic.cs b/AbazovApp/AccountsBusinessLogic/BusinessLogics/InterestLogic.cs new file mode 100644 index 0000000..dfeeafe --- /dev/null +++ b/AbazovApp/AccountsBusinessLogic/BusinessLogics/InterestLogic.cs @@ -0,0 +1,93 @@ +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? 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)); + } + } + } +}