public PortfolioSummary Overview_GetSummary_Adviser(string adviserUserId)
        {
            PortfolioSummary result = new PortfolioSummary()
            {
                investment = new SummaryItem()
                {
                    data = new List<DataNameAmountPair>(),
                },
                liability = new SummaryItem() { data = new List<DataNameAmountPair>() },
                networth = new SummaryItem() { data = new List<DataNameAmountPair>() }
            };

            //foreach (var assetType in db.BalanceTypes)
            //{

            //    var clientTransactions = this
            //        .GetAllTransactionsForAdviserWithAssetType(adviserUserId, assetType.ID);
            //    result.investment.data.Add(new DataNameAmountPair
            //    {
            //         //amount=clientTransactions



            //    });


            //}



            return new PortfolioSummary
            {
                investment = new SummaryItem
                {
                    data = new List<DataNameAmountPair>
                    {
                        new DataNameAmountPair{ amount= 12000, name="Australian Equity"},
                        new DataNameAmountPair { amount=2000, name="International Equity"}
                    },
                    total = 50000
                },
                liability = new SummaryItem
                {
                    data = new List<DataNameAmountPair>
                    {
                        new DataNameAmountPair{amount=20000,name="Mortgage & Investment Loans"},
                        new DataNameAmountPair{amount=30000,name="Margin Loans"}
                    },
                    total = 60000
                },
                networth = new SummaryItem
                {
                    data = new List<DataNameAmountPair>
                    {
                        new DataNameAmountPair{amount=30000, name="Investor Equity"},
                        new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                    }
                }
            };
        }
        public PortfolioSummary GenerateSummary(AssetsAndLiabilites assetsAndLiabilities) {
            List<AssetBase> assets = assetsAndLiabilities.assets;
            List<LiabilityBase> liabilities = assetsAndLiabilities.liabilities;

            PortfolioSummary summary = new PortfolioSummary {
                investment = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        new DataNameAmountPair{ amount = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Australian Equity"},
                        new DataNameAmountPair { amount =  assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="International Equity"},
                        new DataNameAmountPair { amount =  assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Managed Investment"},
                    }
                },
                liability = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        new DataNameAmountPair{amount =  liabilities.OfType<MortgageAndHomeLiability>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Mortgage & Investment Loans"},
                        new DataNameAmountPair{amount =  liabilities.OfType<MarginLending>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Margin Loans"},
                        new DataNameAmountPair{amount =  liabilities.OfType<Insurance>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Insurance"},
                        //new DataNameAmountPair{amount=30000,name="Margin Loans"}
                    }
                },
                networth = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        //new DataNameAmountPair{amount=30000, name="Investor Equity"},
                        //new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                    },
                }
            };

            summary.investment.total = summary.investment.data.Sum(d => d.amount);
            summary.liability.total = summary.liability.data.Sum(d => d.amount);
            summary.networth.total = summary.investment.total + summary.liability.total;

            return summary;
        }
        public PortfolioSummary GetPortfolioSummary_Adviser(string clientGroupId = null)
        {
            if (string.IsNullOrEmpty(clientGroupId))
            {
                List<GroupAccount> groupAccounts = edisRepo.getAllClientGroupAccountsForAdviser(User.Identity.GetUserId(), DateTime.Now);
                List<ClientAccount> clientAccounts = edisRepo.getAllClientAccountsForAdviser(User.Identity.GetUserId(), DateTime.Now);

                List<AssetBase> assets = new List<AssetBase>();
                List<LiabilityBase> liabilities = new List<LiabilityBase>();
                foreach (var account in groupAccounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }
                foreach (var account in clientAccounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }

                PortfolioSummary summary = new PortfolioSummary
                {
                    investment = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            new DataNameAmountPair{ amount = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Australian Equity"},
                            new DataNameAmountPair { amount =  assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="International Equity"},
                            new DataNameAmountPair { amount =  assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Managed Investment"},
                        },
                    },
                    liability = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            //new DataNameAmountPair{amount =  liabilities.OfType<MortgageAndHomeLiability>().Cast<LiabilityBase>().ToList(),name="Mortgage & Investment Loans"},
                            //new DataNameAmountPair{amount=30000,name="Margin Loans"}
                        },
                        total = 60000
                    },
                    networth = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            //new DataNameAmountPair{amount=30000, name="Investor Equity"},
                            //new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                        }
                    }
                };

                summary.investment.total = summary.investment.data.Sum(d => d.amount);
                summary.liability.total = summary.liability.data.Sum(d => d.amount);
                summary.networth.total = summary.networth.data.Sum(d => d.amount);

                return summary;

                //return repo.Overview_GetSummary_Adviser(User.Identity.GetUserId());
            }
            else
            {
                ClientGroup clientGroup = edisRepo.getClientGroupByGroupId(clientGroupId);
                List<GroupAccount> accounts = edisRepo.GetAccountsForClientGroupSync(clientGroup.ClientGroupNumber, DateTime.Now);

                List<AssetBase> assets = new List<AssetBase>();
                List<LiabilityBase> liabilities = new List<LiabilityBase>();
                foreach (var account in accounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }

                PortfolioSummary summary =  new PortfolioSummary
                {
                    investment = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            new DataNameAmountPair{ amount = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Australian Equity"},
                            new DataNameAmountPair { amount =  assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="International Equity"},
                            new DataNameAmountPair { amount =  assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Managed Investment"},
                        },
                    },
                    liability = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            //new DataNameAmountPair{amount =  liabilities.OfType<MortgageAndHomeLiability>().Cast<LiabilityBase>().ToList(),name="Mortgage & Investment Loans"},
                            //new DataNameAmountPair{amount=30000,name="Margin Loans"}
                        },
                        total = 60000
                    },
                    networth = new SummaryItem
                    {
                        data = new List<DataNameAmountPair>
                        {
                            //new DataNameAmountPair{amount=30000, name="Investor Equity"},
                            //new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                        }
                    }
                };

                summary.investment.total = summary.investment.data.Sum(d => d.amount);
                summary.liability.total = summary.investment.data.Sum(d => d.amount);
                summary.networth.total = summary.investment.data.Sum(d => d.amount);

                return summary;

                //return repo.Overview_GetSummary_Client(clientUserId);
            }
        }