public ManagedInvestmentCompanyProfileModel GetCompanyProfiles_Client()
        {
            Client client = edisRepo.GetClientSync(User.Identity.GetUserId(), DateTime.Now);
            ClientGroup clientGroup = edisRepo.GetClientGroupSync(client.ClientGroupId, DateTime.Now);
            if (clientGroup.MainClientId == client.Id)
            {
                List<GroupAccount> groupAccounts = edisRepo.GetAccountsForClientGroupSync(clientGroup.ClientGroupNumber, DateTime.Now);
                List<ClientAccount> clientAccounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now);

                List<ManagedInvestmentCompanyProfileItem> itemList = new List<ManagedInvestmentCompanyProfileItem>();

                List<AssetBase> assets = new List<AssetBase>();
                foreach (var account in groupAccounts)
                {
                    assets.AddRange(account.GetAssetsSync().OfType<ManagedInvestment>().Cast<AssetBase>().ToList());
                }
                foreach (var account in clientAccounts)
                {
                    assets.AddRange(account.GetAssetsSync().OfType<ManagedInvestment>().Cast<AssetBase>().ToList());
                }
                var managedAssets = assets.OfType<ManagedInvestment>();

                var ratios = assets.GetAverageRatiosFor<ManagedInvestment>();

                foreach (var asset in managedAssets)
                {
                    itemList.Add(new ManagedInvestmentCompanyProfileItem
                    {
                        ticker = asset.Ticker,
                        beta = ratios.Beta,
                        company = asset.Name,
                        currentRatio = ratios.CurrentRatio,
                        debtEquityRatio = ratios.DebtEquityRatio,
                        earningsStability = ratios.EarningsStability,
                        fiveYearReturn = ratios.FiveYearReturn,
                        threeYearReturn = ratios.ThreeYearReturn,
                        oneYearReturn = ratios.OneYearReturn,
                        franking = ratios.Frank,
                        interestCover = ratios.InterestCover,
                        payoutRatio = ratios.PayoutRatio,
                        priceEarningsRatio = ratios.PriceEarningRatio,
                        quickRatio = ratios.QuickRatio,
                        returnOnAsset = ratios.ReturnOnAsset,
                        returnOnEquity = ratios.ReturnOnEquity
                    });
                }

                ManagedInvestmentCompanyProfileModel model = new ManagedInvestmentCompanyProfileModel
                {
                    data = itemList,
                    totalCostInvestment = assets.GetTotalCost().Total,
                    totalMarketValue = assets.GetTotalMarketValue()
                };
                return model;
            }
            else
            {
                List<ClientAccount> accounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now);

                List<ManagedInvestmentCompanyProfileItem> itemList = new List<ManagedInvestmentCompanyProfileItem>();

                List<AssetBase> assets = new List<AssetBase>();
                foreach (var account in accounts)
                {
                    assets.AddRange(account.GetAssetsSync().OfType<ManagedInvestment>().Cast<AssetBase>().ToList());
                }
                var managedAssets = assets.OfType<ManagedInvestment>();

                var ratios = assets.GetAverageRatiosFor<ManagedInvestment>();

                foreach (var asset in managedAssets)
                {
                    itemList.Add(new ManagedInvestmentCompanyProfileItem
                    {
                        ticker = asset.Ticker,
                        beta = ratios.Beta,
                        company = asset.Name,
                        currentRatio = ratios.CurrentRatio,
                        debtEquityRatio = ratios.DebtEquityRatio,
                        earningsStability = ratios.EarningsStability,
                        fiveYearReturn = ratios.FiveYearReturn,
                        threeYearReturn = ratios.ThreeYearReturn,
                        oneYearReturn = ratios.OneYearReturn,
                        franking = ratios.Frank,
                        interestCover = ratios.InterestCover,
                        payoutRatio = ratios.PayoutRatio,
                        priceEarningsRatio = ratios.PriceEarningRatio,
                        quickRatio = ratios.QuickRatio,
                        returnOnAsset = ratios.ReturnOnAsset,
                        returnOnEquity = ratios.ReturnOnEquity
                    });
                }

                ManagedInvestmentCompanyProfileModel model = new ManagedInvestmentCompanyProfileModel
                {
                    data = itemList,
                    totalCostInvestment = assets.GetTotalCost().Total,
                    totalMarketValue = assets.GetTotalMarketValue()
                };
                return model;
            }
        }
        public ManagedInvestmentCompanyProfileModel GenerateProfilesModel(List<AssetBase> assets) {
            List<ManagedInvestmentCompanyProfileItem> itemList = new List<ManagedInvestmentCompanyProfileItem>();

            foreach (var asset in assets.OfType<ManagedInvestment>()) {
                var itemIndex = itemList.FindIndex(i => i.ticker == asset.Ticker);

                if (itemIndex < 0) {
                    itemList.Add(new ManagedInvestmentCompanyProfileItem {
                        ticker = asset.Ticker,
                        beta = asset.F0Ratios.Beta,
                        company = asset.Name,
                        currentRatio = asset.F0Ratios.CurrentRatio,
                        debtEquityRatio = asset.F0Ratios.DebtEquityRatio,
                        earningsStability = asset.F0Ratios.EarningsStability,
                        fiveYearReturn = asset.F0Ratios.FiveYearReturn,
                        threeYearReturn = asset.F0Ratios.ThreeYearReturn,
                        oneYearReturn = asset.F0Ratios.OneYearReturn,
                        franking = asset.F0Ratios.Frank,
                        interestCover = asset.F0Ratios.InterestCover,
                        payoutRatio = asset.F0Ratios.PayoutRatio,
                        priceEarningsRatio = asset.F0Ratios.PriceEarningRatio,
                        quickRatio = asset.F0Ratios.QuickRatio,
                        returnOnAsset = asset.F0Ratios.ReturnOnAsset,
                        returnOnEquity = asset.F0Ratios.ReturnOnEquity,
                        marketPrice = asset.LatestPrice,
                        marketValue = asset.GetTotalMarketValue(),
                        totalCostValue = asset.GetCost().Total,
                        costValue = asset.GetCost().AssetCost,
                        companySuitabilityToInvestor = asset.GetRating().TotalScore
                    });
                } else {
                    itemList[itemIndex].marketValue += asset.GetTotalMarketValue();
                    itemList[itemIndex].totalCostValue += asset.GetCost().Total;
                    itemList[itemIndex].costValue += asset.GetCost().AssetCost;
                }
            }

            ManagedInvestmentCompanyProfileModel model = new ManagedInvestmentCompanyProfileModel {
                data = itemList,
                totalCostInvestment = assets.GetTotalCost().Total,
                totalMarketValue = assets.GetTotalMarketValue(),
            };
            return model;
        }