Example #1
0
    /// <summary>
    /// Gets the current exchange rate of USD and RMB and converts according to the selection given.
    /// </summary>
    /// <param name="inputValue"></param>
    private async void GetExchangeResult(double inputValue)
    {
        ExchangeSystem eSystem = new ExchangeSystem();
        ExchangeRate   eRate   = await eSystem.GetExchangeRate();

        if (conversionSelection == 1)
        {
            double newUSD = Math.Round((eRate.rates.USD / eRate.rates.CNY) * inputValue, 3);
            double newCNY = Math.Round((eRate.rates.CNY / eRate.rates.CNY) * inputValue, 3);
            string result = $"{newCNY}RMB : {newUSD}USD";
            NewResult?.Invoke(this, new ResultModel(result));
        }
        else if (conversionSelection == 0)
        {
            double newUSD = Math.Round((eRate.rates.USD / eRate.rates.USD) * inputValue, 3);
            double newCNY = Math.Round((eRate.rates.CNY / eRate.rates.USD) * inputValue, 3);
            string result = $"{newUSD}USD : {newCNY}RMB";
            NewResult?.Invoke(this, new ResultModel(result));
        }
        else
        {
            return;
        }
    }