public WeatherVM GetWeather(GetCityWeatherVM vm) { WeatherVM weatherVM = new WeatherVM(); DatabaseProvider <WeatherVM> dataBaseProvider = new DatabaseProvider <WeatherVM>(); base.command.CommandText = "GetCityWeather"; base.command.Parameters.AddWithValue("@p_CityKey", vm.CityKey); var result = dataBaseProvider.Get(base.command); if (result.Count == 0) { ServiceProvider <WeatherModel> dataServiceProvider = new ServiceProvider <WeatherModel>(); string apiCurrentConditions = "Accuweather.Api.CurrentConditions".GetWebConfigValue <string>(); apiCurrentConditions += vm.CityKey + "?apikey=" + base.apiKey; WeatherModel weatherModel = dataServiceProvider.Get(apiCurrentConditions).Single(); weatherVM = new WeatherVM { CityKey = vm.CityKey, WeatherText = weatherModel.WeatherText, Temperature = weatherModel.Temperature.Metric.Value }; base.command.CommandText = "InsertCityWeather"; base.command.Parameters.Clear(); base.command.Parameters.AddWithValue("@p_CityKey", weatherVM.CityKey); base.command.Parameters.AddWithValue("@p_WeatherText", weatherVM.WeatherText); base.command.Parameters.AddWithValue("@p_Temperature", weatherVM.Temperature); dataBaseProvider.Insert(base.command); } else { weatherVM = result.FirstOrDefault(); } return(weatherVM); }