コード例 #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);
        }
コード例 #2
0
        public async Task Add(FundPurchased fund)
        {
            using (var context = new InvestmentTrackerDbContext())
            {
                MutualFundProxy proxy = new MutualFundProxy();
                fund.NavPurchasePrice = await proxy.GetPrice(fund.SchemeCode, fund.PurchaseDate);

                context.FundPurchased.Add(fund);
                context.SaveChanges();
            }
        }
コード例 #3
0
        public async Task <ActionResult> Search(SearchViewModel model)
        {
            MutualFundProxy proxy   = new MutualFundProxy();
            List <FundData> results = await proxy.Search(model.Text);

            SearchResults viewModel = new SearchResults
            {
                Funds  = results,
                Search = model
            };

            return(View(viewModel));
        }
コード例 #4
0
        private async Task <decimal> FetchLatestNavPrice(string schemecode)
        {
            decimal        price           = 0;
            LatestNavPrice lastestNavPrice = FetchCachedPrice(schemecode);

            if (lastestNavPrice != null)
            {
                price = lastestNavPrice.NavPrice;
            }
            else
            {
                MutualFundProxy proxy = new MutualFundProxy();
                NavHistory      nav   = await proxy.GetLatestPrice(schemecode);

                UpdateCache(schemecode, nav);
                price = nav.nav;
            }
            return(price);
        }