/// <summary> /// Get Bank Accounts List which is not in BankAccountsAccessList /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <List <BankAccountAccessListUnitDto> > GetBankAccountList(GetUserSecuritySettingsInputUnit input) { List <BankAccountCacheItem> bankAccountCacheItems; AutoSearchInput cacheInput = new AutoSearchInput() { OrganizationUnitId = input.OrganizationUnitId }; var values = Enum.GetValues(typeof(TypeOfBankAccount)).Cast <TypeOfBankAccount>().Select(x => x) .ToDictionary(u => u.ToDescription(), u => (int)u).Where(u => u.Value >= 1 && u.Value <= 10) .Select(u => u.Key).ToArray(); var strTypeOfbankAccount = string.Join(",", values); var user = await _userManager.GetUserByIdAsync(input.UserId); var organizationUnits = await _organizationExtendedUnitManager.GetExtendedOrganizationUnitsAsync(user, input.EntityClassificationId); var bankAccountCache = await _bankAccountCache.GetBankAccountCacheItemAsync( CacheKeyStores.CalculateCacheKey(CacheKeyStores.BankAccountKey, Convert.ToInt32(_customAppSession.TenantId))); if (!ReferenceEquals(input.Filters, null)) { Func <BankAccountCacheItem, bool> multiRangeExp = null; Func <BankAccountCacheItem, bool> filterCondition = null; var multiRangeFilters = input.Filters.Where(u => u.IsMultiRange == true).ToList(); if (multiRangeFilters.Count != 0) { multiRangeExp = ExpressionBuilder.GetExpression <BankAccountCacheItem>(Helper.GetMultiRangeFilters(multiRangeFilters), SearchPattern.Or).Compile(); input.Filters.RemoveAll(u => u.IsMultiRange == true); } var otherFilters = input.Filters.Where(u => u.IsMultiRange == false).ToList(); if (otherFilters.Count != 0) { filterCondition = ExpressionBuilder.GetExpression <BankAccountCacheItem>(otherFilters).Compile(); } bankAccountCacheItems = bankAccountCache.ToList().Where(u => strTypeOfbankAccount.Contains(u.TypeOfBankAccountId.ToString())) .WhereIf(multiRangeFilters.Count != 0, multiRangeExp) .WhereIf(otherFilters.Count != 0, filterCondition) .Where(p => !organizationUnits.Any(p2 => p2.Id == p.OrganizationUnitId)).ToList(); } else { bankAccountCacheItems = bankAccountCache.ToList() .Where(p => !organizationUnits.Any(p2 => p2.Id == p.OrganizationUnitId)).ToList(); } return(bankAccountCacheItems.Select(item => { var dto = new BankAccountAccessListUnitDto(); dto.BankAccountNumber = item.BankAccountNumber; dto.BankName = item.Description; dto.AccountName = item.BankAccountName; dto.OrganizationUnitId = item.OrganizationUnitId; dto.BankAccountId = item.BankAccountId; return dto; }).ToList()); }
/// <summary> /// Get Bank Accounts Access List By UserId /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <List <BankAccountAccessListUnitDto> > GetBankAccountAccessList(GetUserSecuritySettingsInputUnit input) { List <BankAccountCacheItem> bankAccountCacheItems = new List <BankAccountCacheItem>(); AutoSearchInput cacheInput = new AutoSearchInput() { OrganizationUnitId = input.OrganizationUnitId }; var bankAccountCache = await _bankAccountCache.GetBankAccountCacheItemAsync( CacheKeyStores.CalculateCacheKey(CacheKeyStores.BankAccountKey, Convert.ToInt32(_customAppSession.TenantId))); var user = await _userManager.GetUserByIdAsync(input.UserId); var organizationUnits = await _organizationExtendedUnitManager.GetExtendedOrganizationUnitsAsync(user, input.EntityClassificationId); var organizationUnitIds = organizationUnits.Select(ou => ou.Id); var strOrgIds = string.Join(",", organizationUnitIds.ToArray()); var values = Enum.GetValues(typeof(TypeOfBankAccount)).Cast <TypeOfBankAccount>().Select(x => x) .ToDictionary(u => u.ToDescription(), u => (int)u).Where(u => u.Value >= 1 && u.Value <= 10) .Select(u => u.Key).ToArray(); var strTypeOfbankAC = string.Join(",", values); if (!string.IsNullOrEmpty(strOrgIds)) { if (ReferenceEquals(input.Filters, null)) { input.Filters = new List <Filters>(); } var orgfilter = new Filters() { Property = "OrganizationUnitId", Comparator = 6,//In Operator SearchTerm = strOrgIds, DataType = DataTypes.Text }; input.Filters.Add(orgfilter); } if (!ReferenceEquals(input.Filters, null)) { Func <BankAccountCacheItem, bool> multiRangeExp = null; var multiRangeFilters = input.Filters.Where(u => u.IsMultiRange == true).ToList(); if (multiRangeFilters.Count != 0) { multiRangeExp = ExpressionBuilder.GetExpression <BankAccountCacheItem>(Helper.GetMultiRangeFilters(multiRangeFilters), SearchPattern.Or).Compile(); input.Filters.RemoveAll(u => u.IsMultiRange == true); } var filterCondition = ExpressionBuilder.GetExpression <BankAccountCacheItem>(input.Filters).Compile(); bankAccountCacheItems = bankAccountCache.ToList() .Where(u => strTypeOfbankAC.Contains(u.TypeOfBankAccountId.ToString())) .WhereIf(multiRangeFilters.Count != 0, multiRangeExp) .Where(filterCondition).ToList(); } return(bankAccountCacheItems.Select(item => { var dto = new BankAccountAccessListUnitDto { BankAccountNumber = item.BankAccountNumber, BankName = item.Description, AccountName = item.BankAccountName, OrganizationUnitId = item.OrganizationUnitId, BankAccountId = item.BankAccountId }; return dto; }).ToList()); }