internal void RemoveFromFavorites(string cityKey) { using (var ctx = new MyFavoritesWeatherEntities()) { var item = ctx.FavoritesCities.Where(x => x.CityKey.Equals(cityKey)).First(); if (item != null) { ctx.FavoritesCities.Remove(item); ctx.SaveChanges(); } } }
private void UpdateFavorites(string cityKey, WeatherDetails wd) { using (var ctx = new MyFavoritesWeatherEntities()) { var city = ctx.FavoritesCities.Where(x => x.CityKey == cityKey).First(); if (city != null) { city.CelsiusTemprature = wd.Temperature.Metric.Value; city.WeatherText = wd.WeatherText; } ctx.SaveChanges(); }; }
public List <City> GetAllFavorites() { using (var ctx = new MyFavoritesWeatherEntities()) { var dbCities = from x in ctx.FavoritesCities select x; if (dbCities != null && dbCities.Count() > 0) { var cities = new List <City>(); foreach (var city in dbCities) { cities.Add(ConvertDalCityToObjCity(city)); } return(cities); } } return(null); }
internal void AddToFavorites(City cityData) { using (var ctx = new MyFavoritesWeatherEntities()) { if (!ctx.FavoritesCities.Where(x => x.CityKey == cityData.Key).Any()) { var item = new FavoritesCity() { CityKey = cityData.Key, Name = cityData.LocalizedName, Status = (int)Enums.FavoriteStatus.Active }; ctx.FavoritesCities.Add(item); ctx.SaveChanges(); } }; }
internal WeatherDetails GetCurrentWeather(string cityKey) { var updateFavorites = false; using (var ctx = new MyFavoritesWeatherEntities()) { if (ctx.FavoritesCities.Where(x => x.CityKey == cityKey).Any()) { var city = ctx.FavoritesCities.Where(x => x.CityKey == cityKey).First(); if (city != null) { updateFavorites = true; if (city.CelsiusTemprature != null && !String.IsNullOrEmpty(city.WeatherText)) { return(ConvertDalCityToWeatherDetails(city)); } } } return(CallWeatherFromAccuWeather(cityKey, updateFavorites)); } }