Beispiel #1
0
        public async Task <List <LegalEntity> > GetLegalEntitiesForAccount(string accountId)
        {
            var listOfEntities = await _client.GetLegalEntitiesConnectedToAccount(accountId);

            var list = new List <LegalEntity>();

            if (listOfEntities.Count == 0)
            {
                return(list);
            }

            foreach (var entity in listOfEntities)
            {
                var legalEntityViewModel = await _client.GetLegalEntity(accountId, Convert.ToInt64(entity.Id));

                list.Add(new LegalEntity
                {
                    Name = legalEntityViewModel.Name,
                    RegisteredAddress = legalEntityViewModel.Address,
                    Source            = legalEntityViewModel.SourceNumeric,
                    Code = legalEntityViewModel.Code,
                    Id   = legalEntityViewModel.LegalEntityId,
                    AccountLegalEntityPublicHashedId = legalEntityViewModel.AccountLegalEntityPublicHashedId
                });
            }

            return(list);
        }
Beispiel #2
0
        private async Task <LegalEntityViewModel> GetLegalEntity(long accountId, long maLegalEntityId)
        {
            var hashedAccountId = _encodingService.Encode(accountId, EncodingType.AccountId);
            var legalEntity     = await _accountApiClient.GetLegalEntity(hashedAccountId, maLegalEntityId);

            return(legalEntity);
        }
        public async Task <IEnumerable <LegalEntityViewModel> > GetLegalEntitiesConnectedToAccountAsync(string accountId)
        {
            try
            {
                var accounts = await _accountApiClient.GetLegalEntitiesConnectedToAccount(accountId);

                var legalEntitiesTasks = accounts.Select(r => _accountApiClient.GetLegalEntity(accountId, long.Parse(r.Id)));

                await Task.WhenAll(legalEntitiesTasks.ToArray());

                var entities = legalEntitiesTasks.Select(t => t.Result);

                return(entities);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to retrieve account information for account Id: {accountId}");
                throw;
            }
        }
        public async Task <List <LegalEntity> > GetLegalEntitiesForAccount(string accountId)
        {
            var listOfEntities = await _accountsApiClient.GetLegalEntitiesConnectedToAccount(accountId);

            if (listOfEntities.Count == 0)
            {
                return(new List <LegalEntity>());
            }

            var bag = new ConcurrentBag <LegalEntity>();

            await listOfEntities.ParallelForEachAsync(async entity =>
            {
                var legalEntityViewModel =
                    await _accountsApiClient.GetLegalEntity(accountId, Convert.ToInt64(entity.Id));

                bag.Add(new LegalEntity
                {
                    Name = legalEntityViewModel.Name,
                    RegisteredAddress = legalEntityViewModel.Address,
                    Source            = legalEntityViewModel.SourceNumeric,
                    Agreements        =
                        legalEntityViewModel.Agreements.Select(agreementSource => new Agreement
                    {
                        Id                    = agreementSource.Id,
                        SignedDate            = agreementSource.SignedDate,
                        SignedByName          = agreementSource.SignedByName,
                        Status                = (EmployerAgreementStatus)agreementSource.Status,
                        TemplateVersionNumber = agreementSource.TemplateVersionNumber
                    }).ToList(),
                    Code = legalEntityViewModel.Code,
                    Id   = legalEntityViewModel.LegalEntityId,
                    AccountLegalEntityPublicHashedId = legalEntityViewModel.AccountLegalEntityPublicHashedId
                });
            },
                                                      MaxConcurrentThreads
                                                      );

            return(bag.OrderBy(le => le.Id).ToList());
        }
        public async Task <List <LegalEntity> > GetLegalEntitiesForAccount(string accountId)
        {
            var listOfEntities = await _client.GetLegalEntitiesConnectedToAccount(accountId);

            var list = new List <LegalEntity>();

            if (listOfEntities.Count == 0)
            {
                return(list);
            }

            foreach (var entity in listOfEntities)
            {
                var legalEntityViewModel = await _client.GetLegalEntity(accountId, Convert.ToInt64(entity.Id));

                list.Add(new LegalEntity
                {
                    Name = legalEntityViewModel.Name,
                    RegisteredAddress = legalEntityViewModel.Address,
                    Source            = legalEntityViewModel.SourceNumeric,
                    Agreements        =
                        legalEntityViewModel.Agreements.Select(agreementSource => new Agreement
                    {
                        Id                    = agreementSource.Id,
                        SignedDate            = agreementSource.SignedDate,
                        SignedByName          = agreementSource.SignedByName,
                        Status                = (EmployerAgreementStatus)agreementSource.Status,
                        TemplateVersionNumber = agreementSource.TemplateVersionNumber
                    }).ToList(),
                    Code = legalEntityViewModel.Code,
                    Id   = legalEntityViewModel.LegalEntityId,
                    AccountLegalEntityPublicHashedId = legalEntityViewModel.AccountLegalEntityPublicHashedId
                });
            }

            return(list);
        }
 public async Task <LegalEntityViewModel> GetLegalEntity(string accountId, long id)
 {
     return(await _inner.GetLegalEntity(accountId, id));
 }