public async Task <AccountSelectResult> SelectAsync(AccountSelectArgs args) { AccountSelectResult logicResult = new AccountSelectResult(); try { Expression <Func <Account, bool> > predicate = CreatePredicate(args); AccountDTO[] results = await _context.Set <Account>().Where(predicate) .Select(x => new AccountDTO { AccountId = x.AccountId, AccountCode = x.AccountCode, AccountName = x.AccountName, AccountDescription = x.AccountDescription, DebitOrCredit = x.DebitOrCredit.ToDomainType(), ParentAccountId = x.ParentAccountId, IsHidden = x.IsHidden }) .AsNoTracking() .ToArrayAsync() .ConfigureAwait(false); logicResult.Results = results; } catch (Exception ex) { logicResult.Exception = ex; } return(logicResult); }
private Expression <Func <Account, bool> > CreatePredicate(AccountSelectArgs args) { _ = args; Expression <Func <Account, bool> > predicate = PredicateBuilder.New <Account>(true); predicate = predicate.And(x => !x.MetaIsDeleted); return(predicate); }
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); }