/// <summary> /// 通过本地获取 /// </summary> /// <param name="item"></param> /// <returns></returns> public async Task<MyCityPageModel> GetWeatherByClient(Model.UserCity item) { weatherRespose = await weatherService.GetWeatherByClientAsync(item.CityId.ToString()).ConfigureAwait(false); MyCityPageModel model = new MyCityPageModel(); model.CityId = item.CityId; model.CityName = item.CityName; model.Temp = weatherRespose == null ? null : weatherRespose.result.today.temperature; model.TodayPic = weatherRespose == null ? null : weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa).TodayPic; return model; }
/// <summary> /// 只获取城市ID和名称 /// </summary> /// <param name="item"></param> /// <returns></returns> public MyCityPageModel GetWeatherByNo(Model.UserCity item) { MyCityPageModel model = new MyCityPageModel() { CityId = item.CityId, CityName = item.CityName, Temp = null, TodayPic = null, }; return model; }
/// <summary> /// 通过网络获取 /// </summary> /// <param name="item"></param> /// <returns></returns> public async Task<MyCityPageModel> GetWeatherByNet(Model.UserCity item) { //不存在当天的天气数据,就从网络获取数据 IGetWeatherRequest request = GetWeatherRequestFactory.CreateGetWeatherRequest(GetWeatherMode.City, item.CityName); weatherRespose = await weatherService.GetWeatherAsync(request); await DeleteFile(item.CityId); await weatherService.SaveWeather<GetWeatherRespose>(weatherRespose, item.CityId.ToString()); MyCityPageModel model = new MyCityPageModel() { CityId = item.CityId, CityName = item.CityName, Temp = weatherRespose == null ? null : weatherRespose.result.today.temperature, TodayPic = weatherRespose == null ? null : weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa).TodayPic }; return model; }