示例#1
0
 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();
         }
     }
 }
示例#2
0
 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();
     };
 }
示例#3
0
        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();
                }
            };
        }