public async Task <AccountSearchResult> Handle(AccountSearchCommand command, CancellationToken cancellationToken) { AccountSearchResult logicResult = new AccountSearchResult(); try { AccountSelectArgs accountSelectArgs = new AccountSelectArgs(); AccountSelectResult accountSelectResult = await _accountRepository.SelectAsync(accountSelectArgs) .ConfigureAwait(false); accountSelectResult.EnsureSuccess(); logicResult.Results = accountSelectResult.Results; } catch (Exception ex) { logicResult.Exception = ex; } return(logicResult); }
public async Task <AccountGetHierarchyResult> Handle(AccountGetHierarchyCommand command, CancellationToken cancellationToken) { AccountGetHierarchyResult logicResult = new AccountGetHierarchyResult(); try { AccountSelectArgs accountSelectArgs = new AccountSelectArgs(); AccountSelectResult accountSelectResult = await _accountRepository.SelectAsync(accountSelectArgs) .ConfigureAwait(false); accountSelectResult.EnsureSuccess(); IDictionary <Guid, AccountDTO> accountDictionary = new Dictionary <Guid, AccountDTO> { { Guid.Empty, new AccountDTO() } }; IDictionary <Guid, ICollection <Guid> > accountChildDictionary = new Dictionary <Guid, ICollection <Guid> >(); foreach (AccountDTO account in accountSelectResult.Results) { accountDictionary[account.AccountId] = account; Guid parentAccountId = account.ParentAccountId ?? Guid.Empty; { if (accountChildDictionary.ContainsKey(parentAccountId)) { accountChildDictionary[parentAccountId].Add(account.AccountId); } else { accountChildDictionary[parentAccountId] = new List <Guid> { account.AccountId }; } } } AccountDTO rootAccount = GetChildAccounts(Guid.Empty, accountDictionary, accountChildDictionary); logicResult.Results = rootAccount.ChildAccounts .ToArray(); } catch (Exception ex) { logicResult.Exception = ex; } return(logicResult); }