public async Task <IActionResult> GetCunrrencyUSDAsync() { try { NashResponse nashResponse = new NashResponse(); var currency = this.HttpContext.Request.Path.Value.ToString().Split("/")[2]; if (currency.ToLower().Equals(CurrenciesNameEnum.dolar.ToString("g"))) { nashResponse = await this.exchangerService.GetQuote(CurrenciesNameEnum.dolar, CurrenciesCodeEnum.USD); } else if (currency.ToLower().Equals(CurrenciesNameEnum.euro.ToString("g"))) { nashResponse = await this.exchangerService.GetQuote(CurrenciesNameEnum.euro, CurrenciesCodeEnum.EUR); } else { nashResponse = await this.exchangerService.GetQuote(CurrenciesNameEnum.real, CurrenciesCodeEnum.BRL); } return(Ok(nashResponse)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(BadRequest(ModelState)); } }
/// <summary> /// Get the quote of currency /// </summary> /// <param name="currencyName"></param> /// <param name="currencyCode"></param> /// <returns></returns> public async Task <NashResponse> GetQuote(CurrenciesNameEnum currencyName, CurrenciesCodeEnum currencyCode) { NashResponse nashResponse = new NashResponse(); CambioTodayModel cambioToday = new CambioTodayModel(); if (currencyCode.Equals(CurrenciesCodeEnum.USD)) { var EstadisticasBcraModel = await this.GetQuoteFromEstadisticasBcraAsync(); nashResponse.Precio = EstadisticasBcraModel.v; nashResponse.Moneda = currencyName.ToString("g"); } else { cambioToday = await this.GetQuoteFromCambiosTodayAsync(currencyCode); nashResponse.Moneda = currencyName.ToString("g"); nashResponse.Precio = cambioToday.Result.Value; } return(nashResponse); }