/// <summary> /// The method adds current weather to the CurrentWeather table. /// </summary> /// <param name="weather"></param> public void AddCurrentWeather(CurrentWeather weather) { using (_context = new WeatherDBContext()) { _context.CurrentWeather.Add(weather); _context.SaveChanges(); } }
/// <summary> /// Remove the city from FavoriteCity table. /// </summary> /// <param name="city"></param> /// <returns></returns> public bool DeleteFavorite(FavoriteCity city) { using (_context = new WeatherDBContext()) { FavoriteCity favorite = _context.FavoriteCity.Find(city.Id); if (favorite != null) { _context.FavoriteCity.Remove(favorite); _context.SaveChanges(); return(true); } else { return(false); } } }
/// <summary> /// The method adds city to FavoriteCity table. /// </summary> /// <param name="city"></param> /// <returns></returns> public Response AddFavorite(FavoriteCity city) { Response response = new Response(); using (_context = new WeatherDBContext()) { FavoriteCity favorite = _context.FavoriteCity.Where(l => l.Key == city.Key).Select(m => m).FirstOrDefault(); if (favorite == null) { _context.FavoriteCity.Add(city); _context.SaveChanges(); response.ErrorCode = 0; response.Message = "Favorite city was added successfully!"; } else { response.ErrorCode = 1; response.Message = "The favorite city already exists in the database !"; } } return(response); }