using AccountContracts.BindingModels; using AccountContracts.BusinessLogicsContracts; using AccountContracts.SearchModels; using AccountContracts.StoragesContracts; using AccountContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static AccountBusinessLogic.BusinessLogic.AccountLogic; namespace AccountBusinessLogic.BusinessLogic { public class AccountLogic : IAccountLogic { private readonly IAccountStorage _accountStorage; public AccountLogic(IAccountStorage accountStorage) { _accountStorage = accountStorage; } public bool Create(AccountBindingModel model) { CheckModel(model); if (_accountStorage.Insert(model) == null) { return false; } return true; } public bool Delete(AccountBindingModel model) { CheckModel(model, false); if (_accountStorage.Delete(model) == null) { return false; } return true; } 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 List? ReadList(AccountSearchModel? model) { var list = _accountStorage.GetFullList(); if (list == null) { return null; } return list; } public bool Update(AccountBindingModel model) { CheckModel(model); if (_accountStorage.Update(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("Account's login is missing!", nameof(model.Login)); } } } }