public async Task <decimal> GetPriceForCurrency(CurrencyNames currencyName, decimal price) { var date = DateTime.Today.AddDays(-1).ToString("dd.MM.yyyy"); var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.privatbank.ua/p24api/exchange_rates?json&date={date}"); var response = await client.SendAsync(request).ConfigureAwait(false); var exchangeRates = JsonSerializer.Deserialize <ExchangeRatesResponse>(await response.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }); var currentCurrency = exchangeRates.ExchangeRates.FirstOrDefault(x => x.Currency == currencyName.ToString()); return(price / currentCurrency.SaleRate); }
/// <summary> /// Sets the value of the <c>Currency</c> attribute. /// </summary> /// <param name="val">A CurrencyNames object</param> /// <remarks> /// <para>The SIF specification defines the meaning of this attribute as: "Currency code. Where omitted, defaults to implementation-defined local currency, typically USD in the United States. "</para> /// <para>Version: 2.6</para> /// <para>Since: 2.0</para> /// </remarks> public void SetCurrency(CurrencyNames val) { SetField(HrfinDTD.FTAMOUNT_CURRENCY, val); }
/// <summary> /// Sets the value of the <c>Currency</c> attribute. /// </summary> /// <param name="val">A CurrencyNames object</param> /// <remarks> /// <para>Version: 2.6</para> /// <para>Since: 2.0</para> /// </remarks> public void SetCurrency(CurrencyNames val) { SetField(FoodDTD.SALESAMOUNT_CURRENCY, val); }
public void setCurNameSelector() { Currency selectCurrency1 = null; Currency selectCurrency2 = null; if (SelectedCurrency1 != null && SelectedCurrency2 != null) { selectCurrency1 = SelectedCurrency1; selectCurrency2 = SelectedCurrency2; } CurrencyNames.Clear(); result.Valute.RUB = new Currency(); result.Valute.RUB.CharCode = "RUB"; result.Valute.RUB.Value = 1; CurrencyNames.Add(result.Valute.RUB); CurrencyNames.Add(result.Valute.USD); CurrencyNames.Add(result.Valute.EUR); CurrencyNames.Add(result.Valute.AUD); CurrencyNames.Add(result.Valute.AZN); CurrencyNames.Add(result.Valute.GBP); CurrencyNames.Add(result.Valute.AMD); CurrencyNames.Add(result.Valute.BYN); CurrencyNames.Add(result.Valute.BGN); CurrencyNames.Add(result.Valute.BRL); CurrencyNames.Add(result.Valute.AMD); CurrencyNames.Add(result.Valute.HUF); CurrencyNames.Add(result.Valute.HKD); CurrencyNames.Add(result.Valute.DKK); CurrencyNames.Add(result.Valute.INR); CurrencyNames.Add(result.Valute.KZT); CurrencyNames.Add(result.Valute.CAD); CurrencyNames.Add(result.Valute.KGS); CurrencyNames.Add(result.Valute.CNY); CurrencyNames.Add(result.Valute.MDL); CurrencyNames.Add(result.Valute.NOK); CurrencyNames.Add(result.Valute.PLN); CurrencyNames.Add(result.Valute.RON); CurrencyNames.Add(result.Valute.XDR); CurrencyNames.Add(result.Valute.SGD); CurrencyNames.Add(result.Valute.TJS); CurrencyNames.Add(result.Valute.TRY); CurrencyNames.Add(result.Valute.TMT); CurrencyNames.Add(result.Valute.UZS); CurrencyNames.Add(result.Valute.UAH); CurrencyNames.Add(result.Valute.CZK); CurrencyNames.Add(result.Valute.SEK); CurrencyNames.Add(result.Valute.CHF); CurrencyNames.Add(result.Valute.ZAR); CurrencyNames.Add(result.Valute.KRW); CurrencyNames.Add(result.Valute.JPY); if (selectCurrency1 != null && selectCurrency2 != null) { foreach (Currency CurrencyName in CurrencyNames) { if (CurrencyName.CharCode == selectCurrency1.CharCode) { SelectedCurrency1 = CurrencyName; } if (CurrencyName.CharCode == selectCurrency2.CharCode) { SelectedCurrency2 = CurrencyName; } } } }