public async Task <GenericCommandResult> Handle(ExchangeResgisterCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Valores de entrada inválidos", new { })); } CoinloreExchangeRateDTO coinlore = await _exchangeRateQuery.GetDataExchangeRate(Settings.COINLORE_EXCHANGE_RATE_URL); if (coinlore is null) { return(new GenericCommandResult(false, "Taxa de cambio não localizada! ;(", new { })); } decimal Exchangerate = _exchangeRateService.GetExchangeRate(command.Replacement.Symbol, command.Applied.Symbol, coinlore); Currencies currencies = new Currencies( value: command.Value, appliedSymbol: command.Applied.Symbol, replacementSymbol: command.Replacement.Symbol, date: $"{DateTime.Now.Day}/{DateTime.Now.Month}/{DateTime.Now.Year} às {DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second} hrs", outputValue: Exchangerate * (decimal)command.Value, appliedName: command.Applied.Name, replacementName: command.Replacement.Name ); await _exchangeRateService.Register(currencies); return(new GenericCommandResult(true, "Valores calculados, troca concluída com sucesso!", new { })); }
public decimal GetExchangeRate(string typeExchangeRate, string typeApplied, CoinloreExchangeRateDTO coinlore) { decimal value = 0; coinlore.Pairs.ForEach(pair => { if (pair.Base == typeApplied && pair.Quote == typeExchangeRate) { value = pair.Price; } }); return(value); }
public async Task <(List <CurrencyNameDTO>, List <CurrencyNameDTO>)> GetListCurrencyNames(string urlCurrencies, string urlExchangeRate) { CoinloreCurrenciesDTO currencyObject = await GetDataCurrencies(urlCurrencies); CoinloreExchangeRateDTO exchangeRateObject = await GetDataExchangeRate(urlExchangeRate); if (exchangeRateObject.Pairs.Count > 0) { var currenciesReplacement = FilterReplacement(currencyObject, exchangeRateObject); var currenciesApplied = FilterApplied(currenciesReplacement, currencyObject, exchangeRateObject); return(currenciesApplied, currenciesReplacement); } return(null, null); }
public List <CurrencyNameDTO> FilterApplied(List <CurrencyNameDTO> data, CoinloreCurrenciesDTO currencies, CoinloreExchangeRateDTO exchanges) { var initial = new List <CurrencyNameDTO>(); var result = new List <CurrencyNameDTO>(); exchanges.Pairs.ForEach(pair => { if (!initial.Any(currency => currency.Symbol == pair.Base)) { if (!(pair.Base is null) && InvalidSymbols(pair.Base)) { initial.Add(new CurrencyNameDTO() { Symbol = pair.Base }); } } }); result = ValidationApplied(initial, data, exchanges); result.ForEach(data => { data = SetCurrencyName(data, currencies); }); return(result); }
public List <CurrencyNameDTO> FilterReplacement(CoinloreCurrenciesDTO currencies, CoinloreExchangeRateDTO exchanges) { var result = new List <CurrencyNameDTO>(); exchanges.Pairs.ForEach(pair => { if (!result.Any(currency => currency.Symbol == pair.Quote)) { if (!(pair.Quote is null)) { result.Add(new CurrencyNameDTO() { Symbol = pair.Quote }); } } }); result.ForEach(data => { data = SetCurrencyName(data, currencies); }); return(result); }
public List <CurrencyNameDTO> ValidationApplied(List <CurrencyNameDTO> applied, List <CurrencyNameDTO> replacement, CoinloreExchangeRateDTO exchanges) { var result = new List <CurrencyNameDTO>(); bool status = true; string symbol = ""; applied.ForEach(applied => { replacement.ForEach(replacement => { exchanges.Pairs.ForEach(pair => { // Validação para verificar se a moédade de aplicação consta para todas as moédas de troco // Porém, não a combinação para todas. // Logo resulta em lista vazia /* * if * (pair.Quote == replacement.Symbol && pair.Base == applied.Symbol && status) * { symbol = applied.Symbol; } * else * { status = false; } */ // Por isso, filtro alternativo if (pair.Quote == replacement.Symbol && pair.Base == applied.Symbol) { symbol = applied.Symbol; } }); }); if (!result.Any(currency => currency.Symbol == symbol) && status) { result.Add(new CurrencyNameDTO() { Symbol = symbol }); status = true; } }); return(result); }