Exemplo n.º 1
0
        /// <summary>
        /// Get Accounts/Lines AccessList By UserId
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <List <AccountAccessListUnitDto> > GetAccountAccessList(GetUserSecuritySettingsInputUnit input)
        {
            List <AccountCacheItem> accountCacheItems = new List <AccountCacheItem>();

            var accountCache = await _accountCache.GetAccountCacheItemAsync(
                CacheKeyStores.CalculateCacheKey(CacheKeyStores.AccountKey, 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());

            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 <AccountCacheItem, bool> multiRangeExp = null;
                var multiRangeFilters = input.Filters.Where(u => u.IsMultiRange == true).ToList();
                if (multiRangeFilters.Count != 0)
                {
                    multiRangeExp = ExpressionBuilder.GetExpression <AccountCacheItem>(Helper.GetMultiRangeFilters(multiRangeFilters), SearchPattern.Or).Compile();
                    input.Filters.RemoveAll(u => u.IsMultiRange == true);
                }

                var filterCondition = ExpressionBuilder.GetExpression <AccountCacheItem>(input.Filters).Compile();
                accountCacheItems = accountCache.ToList().Where(u => u.ChartOfAccountId == input.ChartOfAccountId)
                                    .WhereIf(multiRangeFilters.Count != 0, multiRangeExp)
                                    .Where(filterCondition).ToList();
            }

            return(accountCacheItems.Select(item =>
            {
                var dto = new AccountAccessListUnitDto();
                dto.AccountNumber = item.AccountNumber;
                dto.Caption = item.Caption;
                dto.OrganizationUnitId = item.OrganizationUnitId;
                dto.AccountId = item.AccountId;
                return dto;
            }).ToList());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get Accounts/Lines List which is not in AccountAccessList
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <List <AccountAccessListUnitDto> > GetAccountList(GetUserSecuritySettingsInputUnit input)
        {
            List <AccountCacheItem> accountCacheItems = new List <AccountCacheItem>();
            AutoSearchInput         cacheInput        = new AutoSearchInput()
            {
                OrganizationUnitId = input.OrganizationUnitId
            };

            var user = await _userManager.GetUserByIdAsync(input.UserId);

            var organizationUnits = await _organizationExtendedUnitManager.GetExtendedOrganizationUnitsAsync(user, input.EntityClassificationId);

            var accountCache = await _accountCache.GetAccountCacheItemAsync(
                CacheKeyStores.CalculateCacheKey(CacheKeyStores.AccountKey, Convert.ToInt32(_customAppSession.TenantId)));


            if (!ReferenceEquals(input.Filters, null))
            {
                Func <AccountCacheItem, bool> multiRangeExp   = null;
                Func <AccountCacheItem, bool> filterCondition = null;
                var multiRangeFilters = input.Filters.Where(u => u.IsMultiRange == true).ToList();
                if (multiRangeFilters.Count != 0)
                {
                    multiRangeExp = ExpressionBuilder.GetExpression <AccountCacheItem>(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 <AccountCacheItem>(otherFilters).Compile();
                }
                accountCacheItems = accountCache.ToList()
                                    .Where(u => u.ChartOfAccountId == input.ChartOfAccountId)
                                    .WhereIf(multiRangeFilters.Count != 0, multiRangeExp)
                                    .WhereIf(otherFilters.Count != 0, filterCondition)
                                    .Where(p => !organizationUnits.Any(p2 => p2.Id == p.OrganizationUnitId)).ToList();
            }
            else
            {
                accountCacheItems = accountCache.ToList().Where(u => u.ChartOfAccountId == input.ChartOfAccountId)
                                    .Where(p => !organizationUnits.Any(p2 => p2.Id == p.OrganizationUnitId)).ToList();
            }


            return(accountCacheItems.Select(item =>
            {
                var dto = new AccountAccessListUnitDto();
                dto.AccountId = item.AccountId;
                dto.AccountNumber = item.AccountNumber;
                dto.Caption = item.Caption;
                dto.OrganizationUnitId = item.OrganizationUnitId;
                return dto;
            }).ToList());
        }