Esempio n. 1
0
        private List <ViewModels.BusinessProfileLegalEntity> GetLegalEntityChildren(string parentLegalEntityId)
        {
            _logger.LogDebug(LoggingEvents.Get, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name);
            _logger.LogDebug(LoggingEvents.Get, "parentLegalEntityId: {accouparentLegalEntityIdntId}");

            List <ViewModels.BusinessProfileLegalEntity> children = null;
            var childEntitiesFilter = $"_adoxio_legalentityowned_value eq {parentLegalEntityId}";
            var expandList          = new List <string> {
                "adoxio_ShareholderAccountID", "adoxio_Account"
            };

            try
            {
                children = _dynamicsClient.Legalentities
                           .Get(filter: childEntitiesFilter, expand: expandList).Value
                           .Select(le =>
                {
                    var legalEntity = le.ToViewModel();
                    var entity      = new ViewModels.BusinessProfileLegalEntity
                    {
                        AdoxioLegalEntity = legalEntity,
                        Account           = le.AdoxioShareholderAccountID == null ? le.AdoxioAccount.ToViewModel() : le.AdoxioShareholderAccountID.ToViewModel()
                    };
                    var tiedHouse = _dynamicsClient.Tiedhouseconnections
                                    .Get(filter: $"_adoxio_accountid_value eq {entity.Account.id}")
                                    .Value.FirstOrDefault();
                    if (tiedHouse != null)
                    {
                        entity.TiedHouse = tiedHouse.ToViewModel();
                    }
                    if (entity.AdoxioLegalEntity.isShareholder == true && entity.AdoxioLegalEntity.isindividual == false)
                    {
                        entity.ChildEntities = GetLegalEntityChildren(entity.AdoxioLegalEntity.id);
                    }
                    return(entity);
                })
                           .ToList();
                _logger.LogDebug(LoggingEvents.Get, "LegalEntityChildren: " +
                                 JsonConvert.SerializeObject(children, Formatting.Indented, new JsonSerializerSettings {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }));
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, $"Error getting legal entity children for parentLegalEntityId {parentLegalEntityId}. ");
                children = null;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error getting legal entity children for parentLegalEntityId");
                return(null);
            }


            return(children);
        }
Esempio n. 2
0
        public IActionResult GetBusinessProfile(string accountId)
        {
            _logger.LogDebug(LoggingEvents.HttpGet, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name);
            _logger.LogDebug(LoggingEvents.HttpGet, "accountId: {accountId}");

            List <BusinessProfileLegalEntity> legalEntities;

            var expand = new List <string> {
                "primarycontactid"
            };
            var account = (_dynamicsClient.Accounts.Get(filter: "", expand: expand).Value.FirstOrDefault()).ToViewModel();

            _logger.LogDebug(LoggingEvents.HttpGet, "Account details: " + JsonConvert.SerializeObject(account));

            // get legal entities
            var entityFilter = $"_adoxio_account_value eq {accountId}";
            var expandList   = new List <string> {
                "adoxio_ShareholderAccountID"
            };

            try
            {
                legalEntities = _dynamicsClient.Legalentities.Get(filter: entityFilter, expand: expandList).Value
                                .Select(le =>
                {
                    var legalEntity = le.ToViewModel();
                    var entity      = new ViewModels.BusinessProfileLegalEntity
                    {
                        AdoxioLegalEntity = legalEntity,
                        Account           = le.AdoxioShareholderAccountID == null ? account : le.AdoxioShareholderAccountID.ToViewModel(),
                    };
                    entity.corporateDetailsFilesExists      = FileUploadExists(entity.Account.id, entity.Account.name, "Corporate Information").Result;
                    entity.organizationStructureFilesExists = FileUploadExists(entity.Account.id, entity.Account.name, "Organization Structure").Result;
                    entity.keyPersonnelFilesExists          = FileUploadExists(entity.Account.id, entity.Account.name, "Key Personnel").Result;
                    entity.financialInformationFilesExists  = FileUploadExists(entity.Account.id, entity.Account.name, "Financial Information").Result;
                    entity.shareholderFilesExists           = FileUploadExists(entity.Account.id, entity.Account.name, "Central Securities Register").Result;
                    var tiedHouse = _dynamicsClient.Tiedhouseconnections
                                    .Get(filter: $"_adoxio_accountid_value eq {entity.Account.id}")
                                    .Value.FirstOrDefault();
                    if (tiedHouse != null)
                    {
                        entity.TiedHouse = tiedHouse.ToViewModel();
                    }
                    entity.ChildEntities = GetLegalEntityChildren(entity.AdoxioLegalEntity.id);
                    return(entity);
                })
                                .ToList();
            }
            catch (HttpOperationException httpOperationException)
            {
                _logger.LogError(httpOperationException, "Error getting legal entities for the account {accountId}. ");
                return(null);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error getting legal entities for the account");
                return(null);
            }

            var profile = new BusinessProfile
            {
                Account       = account,
                LegalEntities = legalEntities
            };

            var isComplete = legalEntities.Select(le =>
            {
                var valid = new ProfileValidation
                {
                    LegalEntityId = le.AdoxioLegalEntity.id,
                    IsComplete    = (le.IsComplete())
                };
                return(valid);
            }).ToList();

            _logger.LogDebug(LoggingEvents.HttpGet, "BusinessProfile.isComplete: " +
                             JsonConvert.SerializeObject(isComplete, Formatting.Indented, new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
            return(new JsonResult(isComplete));
        }