Example #1
0
        public static List<CorredoresModel> RecuperaCorredores()
        {
            List<CorredoresModel> corredores = new List<CorredoresModel>();

            var url = "http://54.94.187.233/senairunner/rest/runners";
            var cliente = new WebClient();
            var corredoresJson = cliente.DownloadString(url);

            var model = JsonConvert.DeserializeObject<List<CorredoresModel>>(corredoresJson);

            foreach (CorredoresModel c in model)
            {
                corredores.Add(c);
            }

            return corredores;
        }
        public static List<InscricaoModel> RecuperaInscricoes()
        {
            List<InscricaoModel> inscricoes = new List<InscricaoModel>();

            var url = "http://54.94.187.233/senairunner/rest/runsEntry";
            var cliente = new WebClient();
            var inscricoesJson = cliente.DownloadString(url);

            var model = JsonConvert.DeserializeObject<List<InscricaoModel>>(inscricoesJson);

            foreach (InscricaoModel i in model)
            {
                inscricoes.Add(i);
            }

            return inscricoes;
        }
        public static List<PrevisaoTempoModel> RecuperaPrevisaoDoTempo(string cidade)
        {
            List<PrevisaoTempoModel> previsaoTempo = new List<PrevisaoTempoModel>();

            var url = "http://api.openweathermap.org/data/2.5/forecast/daily?q=" + cidade + ",Brazil&cnt=15";
            var cliente = new WebClient();
            var previsao = cliente.DownloadString(url);

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(PrevisaoDoTempoModelJson));
              using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(previsao)))
              {
             var weatherData = (PrevisaoDoTempoModelJson)serializer.ReadObject(ms);

                foreach(List l in weatherData.list)
                {
                    previsaoTempo.Add(new PrevisaoTempoModel(){data = new DateTime(1970,1,1,0,0,0).AddSeconds(l.dt), temperaturaDia = Convert.ToString(l.temp.morn),
                    temperaturaTarde = Convert.ToString(l.temp.eve), temperaturaNoite = Convert.ToString(l.temp.night)});
                }
              }

            return previsaoTempo;
        }