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; namespace AccountBusinessLogic.BusinessLogic { public class RoleLogic : IRoleLogic { private readonly IRoleStorage _roleStorage; public RoleLogic(IRoleStorage roleStorage) { _roleStorage = roleStorage; } public bool Create(RoleBindingModel model) { CheckModel(model); if (_roleStorage.Insert(model) == null) { return false; } return true; } public bool Delete(RoleBindingModel model) { CheckModel(model, false); if (_roleStorage.Delete(model) == null) { return false; } return true; } public RoleViewModel? ReadElement(RoleSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _roleStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList() { var list = _roleStorage.GetFullList(); if (list == null) { return null; } return list; } public bool Update(RoleBindingModel model) { CheckModel(model); if (_roleStorage.Update(model) == null) { return false; } return true; } private void CheckModel(RoleBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.RoleName)) { throw new ArgumentNullException("Role's name is missing!", nameof(model.RoleName)); } } } }