Beispiel #1
0
 public int getWeather(DownloadWeather myWeather)
 {
     clouds     = myWeather.weather[0].description;
     temp       = myWeather.main.temp;
     feels_like = myWeather.main.feels_like;
     temp_min   = myWeather.main.temp_min;
     temp_max   = myWeather.main.temp_max;
     pressure   = myWeather.main.pressure;
     humidity   = myWeather.main.humidity;
     windSpeed  = myWeather.wind.speed;
     windDeg    = myWeather.wind.deg;
     id         = DateTime.Now.ToString("yyyyMMddHHmmssffff");
     name       = myWeather.name;
     return(0);
 }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var             context = new WeatherByCity();
            string          choosenCity;
            DownloadWeather myWeather = new DownloadWeather();
            DownloadWeather actualWeather;
            WeatherForDB    actualWeatherForDB = new WeatherForDB();

            Console.WriteLine("1. Sprawdz pogode \n2. Pokaz historie dla miasta");
            int caseSwitch = Convert.ToInt32(Console.ReadLine());

            switch (caseSwitch)
            {
            case 1:
                Console.WriteLine("Podaj miasto: ");
                choosenCity   = Console.ReadLine();
                actualWeather = JsonConvert.DeserializeObject <DownloadWeather>(myWeather.getWeather(choosenCity));
                actualWeatherForDB.getWeather(actualWeather);
                Console.WriteLine("Miasto: " + actualWeather.name);
                Console.WriteLine("Kraj: " + actualWeather.sys.country);
                Console.WriteLine("Temperatura: " + actualWeather.main.temp + "°C");
                Console.WriteLine("Zachmurzenie: " + actualWeather.weather[0].description);
                context.WeatherForDB.Add(actualWeatherForDB);
                context.SaveChanges();
                break;

            case 2:
                Console.WriteLine("Podaj miasto");
                choosenCity = Console.ReadLine();
                Console.WriteLine("SELECT * FROM WeatherForDB WHERE name = '" + choosenCity + "'");
                var pogody = context.WeatherForDB.FromSqlRaw("SELECT * FROM WeatherForDB WHERE name = '" + choosenCity + "'");//.ToList<DownloadWeather>();
                foreach (var pogoda in pogody)
                {
                    Console.WriteLine(pogoda.id.Substring(0, 4) + "-" + pogoda.id.Substring(4, 2) + "-" + pogoda.id.Substring(6, 2) + " Temperatura: " + pogoda.temp + "°C");//+" "+pogoda.id.Substring(0,4)+" ");
                }
                break;

            default:
                Console.WriteLine("Nie ma takiej opcji");
                break;
            }
        }