public void RemoveFromFavorites(RemoveFavoriteRequest request)
        {
            WeatherDbDataContext db = new WeatherDbDataContext(connectString);

            //Create new Employee

            favorite fav = db.favorites.FirstOrDefault(x => x.key == request.key);

            //Add new Employee to database
            db.favorites.DeleteOnSubmit(fav);

            //Save changes to Database.
            db.SubmitChanges();
        }
        public void AddToFavorites(AddFavoriteRequest request)
        {
            string connectString = System.Configuration.ConfigurationManager.ConnectionStrings["weatherConnectionString"].ToString();

            WeatherDbDataContext db = new WeatherDbDataContext(connectString);

            //Create new Employee

            favorite fav = new favorite();

            fav.key  = request.key;
            fav.name = request.name;

            //Add new Employee to database
            db.favorites.InsertOnSubmit(fav);

            //Save changes to Database.
            db.SubmitChanges();
        }
        public async Task <CurrentWeatherResponse> GetCurrentWeather(GetCurrentWeatherRequest request)
        {
            CurrentWeatherResponse result = null;
            string     content            = "";
            HttpClient client             = new HttpClient();

            client.BaseAddress = new Uri(baseUrl);
            WeatherDbDataContext db = new WeatherDbDataContext(connectString);

            //Create new Employee

            weather weather = db.weathers.FirstOrDefault(x => x.key == request.Key);

            if (weather != null)
            {
                return(new CurrentWeatherResponse {
                    text = weather.WeatherText, value = double.Parse(weather.celsius)
                });
            }
            else
            {
                HttpResponseMessage response = client.GetAsync(baseUrl + "currentconditions/v1/" + request.Key + "?apikey=" + apiKey).Result;
                if (response.IsSuccessStatusCode)
                {
                    content = await response.Content.ReadAsStringAsync();

                    var list = JsonConvert.DeserializeObject <List <CurrentWeather> >(content);
                    if (list.Count > 0)
                    {
                        result = new CurrentWeatherResponse {
                            text = list[0].WeatherText, value = list[0].temperature.metric.Value
                        };
                        db.weathers.InsertOnSubmit(new weather {
                            celsius = result.value.ToString(), key = request.Key, WeatherText = result.text
                        });
                        db.SubmitChanges();
                    }
                }
            }
            return(result);
        }