public CotizacionDto GetCotizacion([FromUri] string tipoMoneda) { var estrategia = this.GetEstrategia(((TipoMoneda)Enum.Parse(typeof(TipoMoneda), tipoMoneda))); var cotizacionDto = new CotizacionDto(); cotizacionDto.Value = estrategia.GetCotizacion(); return(cotizacionDto); }
public async Task <CotizacionDtoResponse> GetCotizacion(string moneda) { CotizacionDtoResponse result = null; var request = new HttpRequestMessage(HttpMethod.Get, "https://www.bancoprovincia.com.ar/Principal/Dolar"); var client = _clientFactory.CreateClient("virtualMind"); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { using (var stream = await response.Content.ReadAsStreamAsync()) { var jsonReader = new JsonTextReader(new StreamReader(stream)); var objDeserialize = new JsonSerializer().Deserialize <string[]>(jsonReader); if (objDeserialize != null) { var objServiceResponse = new CotizacionDto() { CambioDolarCompra = Convert.ToDecimal(objDeserialize[0]), CambioDolarVenta = Convert.ToDecimal(objDeserialize[1]), FechaActualizacion = objDeserialize[2] }; result = moneda.ToLower() switch { "dolar" => new CotizacionDtoResponse() { CambioCompra = objServiceResponse.CambioDolarCompra, CambioVenta = objServiceResponse.CambioDolarVenta, FechaActualizacion = objServiceResponse.FechaActualizacion }, "real" => new CotizacionDtoResponse() { CambioCompra = Math.Round(objServiceResponse.CambioDolarCompra / 4, 2), CambioVenta = Math.Round(objServiceResponse.CambioDolarVenta / 4, 2), FechaActualizacion = objServiceResponse.FechaActualizacion }, _ => null }; } } } return(await Task.FromResult(result)); } }
public MultiIndicadorDetailOutput GetCalculadorCotizaciones(CalculadorDetailInput input) { var indicadores = _indicadorRepository .GetAll() .OrderBy(i => i.Nombre) .ToList(); Indicador indicadorPivot = indicadores.FirstOrDefault(e => e.Id == input.IndicadorId); IndicadorDetailOutput cotizPivot; if (input.EsIndicadorDefault || indicadorPivot == null) { cotizPivot = new IndicadorDetailOutput() { Nombre = "Default", Id = input.IndicadorId, Cotizaciones = (new[] { new CotizacionDto() { ValorCotizacion = 1, FechaHoraCotizacion = input.FechaDesde, CreationTime = DateTime.Now, } }).ToList() }; } else { cotizPivot = GetIndicadorDetail(new IndicadorDetailInput() { IndicadorId = indicadorPivot.Id, FechaDesde = input.FechaDesde }); } if (cotizPivot.Cotizaciones.Any()) { var valorCotizPivot = cotizPivot.Cotizaciones.Last().ValorCotizacion; if (valorCotizPivot != decimal.Zero) { var cots = indicadores.Select(i => { var dto = new CotizacionDto() { IndicadorId = i.Id, FechaHoraCotizacion = input.FechaDesde, ValorCotizacion = decimal.Zero }; var cotizIndicador = GetIndicadorDetail(new IndicadorDetailInput() { IndicadorId = i.Id, FechaDesde = input.FechaDesde }); if (cotizIndicador.Cotizaciones.Any()) { var valorCotiz = cotizIndicador.Cotizaciones.LastOrDefault().ValorCotizacion; dto.ValorCotizacion = valorCotiz / valorCotizPivot; } return(dto); } ).ToList(); return(new MultiIndicadorDetailOutput() { Nombres = indicadores.ToDictionary(x => x.Id, x => x.Nombre), Cotizaciones = cots }); } } return(null); }