Exemple #1
0
        List<Weather> IOpenWeatherService.GetWeathers(IOpenWeatherService openWeatherService, IXmlService xmlService, XDocument weatherDocument, WeatherForecast weatherForecast)
        {
            List<Weather> weathers =
                   (from w in weatherDocument.Descendants("time")

                    select new Weather
                    {
                        ForecastDaysPlus = (int)(Convert.ToDateTime(w.Attribute("day").Value) - DateTime.Now.Date).TotalDays,
                        Date = Convert.ToDateTime(w.Attribute("day").Value),
                        Symbol = w.Element("symbol").Attribute("name").Value,
                        WeatherForecast = weatherForecast,
                        Clouds = CreateClouds(xmlService, w),
                        Humidity = CreateHumidity(xmlService, w),
                        Precipitation = CreatePrecipitation(xmlService, w),
                        Pressure = CreatePressure(xmlService, w),
                        Temperature = new Temperature
                                        {
                                            Day = Convert.ToDecimal(w.Element("temperature").Attribute("day").Value, CultureInfo.InvariantCulture),
                                            Morn = Convert.ToDecimal(w.Element("temperature").Attribute("morn").Value, CultureInfo.InvariantCulture),
                                            Eve = Convert.ToDecimal(w.Element("temperature").Attribute("eve").Value, CultureInfo.InvariantCulture),
                                            Night = Convert.ToDecimal(w.Element("temperature").Attribute("night").Value, CultureInfo.InvariantCulture),
                                            Max = Convert.ToDecimal(w.Element("temperature").Attribute("max").Value, CultureInfo.InvariantCulture),
                                            Min = Convert.ToDecimal(w.Element("temperature").Attribute("min").Value, CultureInfo.InvariantCulture)
                                        },
                        Wind = CreateWind(xmlService, w),
                    }).ToList<Weather>();

            return weathers;
        }
Exemple #2
0
 public void SaveWeather(WeatherForecast weatherForecast, MeteoContext meteoContext)
 {
     try
     {
         meteoContext.WeatherForecasts.Add(weatherForecast);
         meteoContext.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         throw;
     }
 }
Exemple #3
0
        public WeatherForecast GetWeatherForecast(IOpenWeatherService openWeatherService, IXmlService xmlService, XDocument weatherDocument, List<Location> currentLocations, int forecastDaysCount)
        {
            Location location = openWeatherService.GetLocation(weatherDocument, currentLocations);

            WeatherForecast weatherForecast = new WeatherForecast()
            {
                Location = location,
                Time = DateTime.Now,
                ForecastDaysQuantity = forecastDaysCount
            };

            List<Weather> weathers = openWeatherService.GetWeathers(openWeatherService, xmlService, weatherDocument, weatherForecast);
            weatherForecast.Weathers = weathers;
            return weatherForecast;
        }