예제 #1
0
        private async void CalculateTotal()
        {
            var targetCurrency = Model.TotalCurrency;

            if (Currency.IsNullOrEmpty(targetCurrency))
            {
                return;
            }

            Task <List <Quote> > getQuotesTask = QuoteService.FetchQuotesAsync(targetCurrency, App.Account);
            List <Quote>         quotes        = await getQuotesTask;

            if (quotes != null)
            {
                foreach (Quote quote in quotes)
                {
                    App.QuotesGraph.UpsertQuote(quote);
                }
            }

            decimal totalAmount = 0.0M;

            foreach (KeyValuePair <Currency, CurrencyAmount> tuple in App.Account)
            {
                decimal quoteValue = 0.0M;
                if (App.QuotesGraph.GetQuote(tuple.Key, targetCurrency, out quoteValue) != Result.Found)
                {
                    SetMessage(false, "MISSING QUOTE CANT CALCULATE TOTAL");
                    Model.TotalAmount = 0;
                    return;
                }
                totalAmount += tuple.Value.Amount * quoteValue;
            }
            Model.TotalAmount = totalAmount;
            return;
        }