Exemplo n.º 1
0
        public async Task <List <FundInfo> > GetAllFunds()
        {
            List <FundInfo> fundInfo = new List <FundInfo>();

            using (var context = new InvestmentTrackerDbContext())
            {
                var                 funds             = context.FundPurchased.ToList();
                var                 fundgroups        = funds.GroupBy(x => x.SchemeCode);
                MutualFundProxy     proxy             = new MutualFundProxy();
                CurrencyConverter   currencyConverter = new CurrencyConverter();
                FundPriceCalculator calculator        = new FundPriceCalculator();
                foreach (var group in fundgroups)
                {
                    var latestPrice = await FetchLatestNavPrice(group.Key);

                    foreach (var fund in group)
                    {
                        var info = calculator.Calculate(latestPrice, fund);
                        info.IsReinvestedAmount  = fund.IsReinvestedAmount ?? false;
                        info.AmountInvestedInNZD = await currencyConverter.ConvertAsync(Currency.INR, Currency.NZD, info.AmountInvested);

                        info.CurrentValueInNZD = await currencyConverter.ConvertAsync(Currency.INR, Currency.NZD, info.CurrentValue);

                        fundInfo.Add(info);
                    }
                }
            }
            return(fundInfo);
        }