Example #1
0
        public WeatherData GetWeatherDataByCityName(string cityName)
        {
            WeatherData weatherData      = new WeatherData();
            WeatherDataMapDataContext db = new WeatherDataMapDataContext(DbConnection.Instance.GetFixedConnectionString());

            var query = (from w in db.WEATHER_DATAs
                         where w.CITY_NAME == cityName
                         select w).FirstOrDefault();

            weatherData.Name = query == null ? string.Empty : query.CITY_NAME;

            return(weatherData);
        }
Example #2
0
        public int GetNextId()
        {
            int id = 0;
            WeatherDataMapDataContext db = new WeatherDataMapDataContext(DbConnection.Instance.GetFixedConnectionString());

            var query = db.WEATHER_DATAs.OrderByDescending(i => i.Id).FirstOrDefault();

            if (query != null)
            {
                id = query.Id + 1;
            }

            return(id);
        }
Example #3
0
        public WeatherData GetWeatherDataByCityNameAndUpdateDate(string cityName, DateTime updateDate)
        {
            WeatherData weatherData      = null;
            WeatherDataMapDataContext db = new WeatherDataMapDataContext(DbConnection.Instance.GetFixedConnectionString());

            var query = from w in db.WEATHER_DATAs
                        where w.CITY_NAME == cityName && w.UPDATE_DATE > updateDate
                        select w;

            foreach (var q in query)
            {
                weatherData            = new WeatherData();
                weatherData.Name       = q.CITY_NAME;
                weatherData.Sunrise    = q.SUNRISE.Value;
                weatherData.Sunset     = q.SUNSET.Value;
                weatherData.UpdateDate = q.UPDATE_DATE.Value;
                weatherData.IsCloud    = q.IS_CLOUD.Value;
                weatherData.IsRain     = q.IS_RAIN.Value;
            }
            return(weatherData);
        }