예제 #1
0
        public async Task <ActionResult> GetPrevisaoTempo(string estadoEscolhido, string municipioEscolhido)
        {
            PrevisaoTempoAtualService service = new PrevisaoTempoAtualService();
            string parametros = service.MontarParametros(estadoEscolhido, municipioEscolhido);

            var retorno = await ApiHelper.GetPrevisaoTempoAtual(parametros);

            if (retorno.Sucesso)
            {
                string painel = RazorUtil.GetTemplate(retorno.Resultado);

                return(Json(new { OK = retorno.Sucesso, stringHtml = painel }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { OK = false, Mensagem = retorno.Mensagem, }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public static async Task <RestModelHgBrasil <PrevisaoTempoAtual> > GetPrevisaoTempoAtual(string parametros)
        {
            RestModelHgBrasil <PrevisaoTempoAtual> retorno = new RestModelHgBrasil <PrevisaoTempoAtual>();
            PrevisaoTempoAtualService service = new PrevisaoTempoAtualService();

            string url = ConfigHelper.UrlWeather + parametros;

            HttpResponseMessage response = await client.GetAsync(url);

            using (var responseStream = await response.Content.ReadAsStreamAsync())
            {
                string stringJson = new StreamReader(responseStream).ReadToEnd();
                retorno = JsonConvert.DeserializeObject <RestModelHgBrasil <PrevisaoTempoAtual> >(stringJson);

                if (response.IsSuccessStatusCode && retorno != null && retorno.Resultado != null)
                {
                    service.FormatarDados(retorno.Resultado);
                }

                retorno.Sucesso = response.IsSuccessStatusCode;
            }

            return(retorno);
        }