Esempio n. 1
0
        public static async Task <string> BuildStringFromValuesAsync(IEnumerable <KeyValuePair <CurrencyEmoji, decimal> > values,
                                                                     CurrencyEmoji mainValue, decimal percents = DefaultValues.DefaultPercents)
        {
            var mainValuePair = values.First(t => t.Key.Currency == mainValue.Currency);

            // if percents are default (100), then don't also print the value currency, else - print it.
            var needed =
                percents == DefaultValues.DefaultPercents ? values.Where(t => !t.Equals(mainValuePair))
                : values;

            var str = await BuildStringFromValuesAsync(needed, percents);

            return($"Given value: {mainValuePair.Key.Emoji} {mainValuePair.Value} {mainValuePair.Key.Currency}" +
                   $"{Environment.NewLine}{Environment.NewLine}" + str);
        }
Esempio n. 2
0
 private async Task HandleCurrencyChangeAsync(long chatId, CurrencyEmoji ce)
 {
     await Repository.SetCurrencyAsync(ce.Currency, chatId);
 }
Esempio n. 3
0
 private void HandleCurrencyChange(long chatId, CurrencyEmoji ce)
 {
     Repository.SetCurrency(ce.Currency, chatId);
 }
Esempio n. 4
0
        public static async Task <IList <KeyValuePair <CurrencyEmoji, decimal> > > GetCurrenciesValuesAsync(decimal value, CurrencyEmoji valueCurrencyEmoji, ValCurs data, IEnumerable <CurrencyEmoji> neededCurrencies)
        {
            return(await Task.Run(() =>
            {
                var currency = valueCurrencyEmoji.Currency;

                var rub = ConvertToRub(value, currency, data); // whatever currency the value is, it is processed as rub

                var currencies = new List <KeyValuePair <ValCursValute, CurrencyEmoji> >(neededCurrencies.Count());

                foreach (var i in data.Valute)
                {
                    foreach (var j in neededCurrencies)
                    {
                        if (i.CharCode == j.Currency)
                        {
                            currencies.Add(new KeyValuePair <ValCursValute, CurrencyEmoji>(i, j));
                        }
                    }
                }

                var result = currencies.Select(
                    i =>
                {
                    var(valute, currencyEmoji) = i;

                    return new KeyValuePair <CurrencyEmoji, decimal>(
                        currencyEmoji,
                        rub / (decimal.Parse(valute.Value, DecimalFormatInfo) / valute.Nominal)
                        );
                }
                    ).ToList();

                var rubEmoji = neededCurrencies.FirstOrDefault(ce => ce.Currency == DefaultValues.APICurrency);

                if (rubEmoji != null)
                {
                    result
                    .Add(new KeyValuePair <CurrencyEmoji, decimal>(rubEmoji, rub));
                }

                if (!result.Any(el => el.Key.Emoji == valueCurrencyEmoji.Emoji))
                {
                    result.Add(new KeyValuePair <CurrencyEmoji, decimal>(valueCurrencyEmoji, value));
                }

                return result;
            }));
        }