public void WeatherAction_returns_WeatherView() { var mockContext = new Mock <HttpContextBase>(); var mockSession = new Mock <HttpSessionStateBase>(); mockSession.SetupGet(m => m["parkID"]).Returns("CVNP"); mockSession.SetupGet(m => m["keepTempType"]).Returns("F"); mockContext.Setup(ctx => ctx.Session).Returns(mockSession.Object); //mockContext.Setup(m => m.SetSessionStateBehavior()) Mock <IWeatherDAL> mockDAL = new Mock <IWeatherDAL>(); Models.Weather w = new Models.Weather(); w.ParkCode = "CVNP"; List <Models.Weather> fakeList = new List <Models.Weather>(); fakeList.Add(w); mockDAL.Setup(m => m.Get5DaysOfWeather("CVNP")).Returns(fakeList); WeatherController c = new WeatherController(mockDAL.Object); c.ControllerContext = new ControllerContext(mockContext.Object, new RouteData(), c); var result = c.Weather("CVNP"); Assert.IsTrue(result is ViewResult); var view = result as ViewResult; Assert.AreEqual("Weather", view.ViewName); Assert.IsNotNull(view.Model); }
public async Task <IActionResult> Index(string city_one, string city_two) { if (city_one == null || city_two == null) { return(View("IndexEmpty")); } ; List <Models.Weather> weathers = new List <Models.Weather>(); // first city try { Models.Weather w = await ReturnCity(city_one); weathers.Add(w); } catch { return(Content($"Sorry but {city_one} cannot be found. Try Another!")); } // second city try { Models.Weather w2 = await ReturnCity(city_two); weathers.Add(w2); } catch { return(Content($"Sorry but {city_two} cannot be found. Try Another!")); } return(View(weathers)); }
public static Weather ConverToWeather(JsonObject jsonObj) { Weather wt = new Models.Weather(); wt.City = jsonObj["result"].Object["today"].Object["city"].Value; wt.Temperature = jsonObj["result"].Object["today"].Object["Temperature"].Value; wt.WeatherInfo = jsonObj["result"].Object["today"].Object["Weather"].Value; wt.Wind_strength = jsonObj["result"].Object["today"].Object["dressing_advice"].Value; wt.wind = jsonObj["result"].Object["today"].Object["wind"].Value; wt.week = jsonObj["result"].Object["today"].Object["week"].Value; return(wt); }
public async Task UpdateWeather() { HttpClient client = new HttpClient(); string response = await client.GetStringAsync(new Uri("http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID=111111111111")); try { WData = JsonConvert.DeserializeObject(response, typeof(Models.Weather)) as Models.Weather; } catch(Exception ex) { Debug.WriteLine(ex.Message); } }
public static Weather ConverToWearther(JsonObject jsonObj) { Weather wt = new Models.Weather(); wt.City = jsonObj["result"].Object["today"].Object["city"].Value; wt.TodayWeather = jsonObj["result"].Object["today"].Object["weather"].Value; wt.Temperature = jsonObj["result"].Object["today"].Object["temperature"].Value; wt.Humidity = jsonObj["result"].Object["sk"].Object["humidity"].Value; wt.Date_y = jsonObj["result"].Object["today"].Object["date_y"].Value; wt.Week = jsonObj["result"].Object["today"].Object["week"].Value; wt.Temp = jsonObj["result"].Object["sk"].Object["temp"].Value; wt.Time = jsonObj["result"].Object["sk"].Object["time"].Value; return(wt); }
public CurrentWeatherViewModel(DependencyObject dependency, Models.Current currentWeather) : base(dependency) { _currentWeather = currentWeather; _weather = _currentWeather.Weather.FirstOrDefault(); DateTime?sunrise = _currentWeather.Sys.SunriseDateTime, sunset = _currentWeather.Sys.SunsetDateTime; _isSunrise = DateTime.Now > sunset; SunRiseOrSet = _isSunrise ? $"{sunrise:h:mm tt}" : $"{sunset:h:mm tt}"; }
public async Task <IActionResult> Delete(string cityname) { Models.Weather weather = new Models.Weather(); weather = await _iweatherRepositroy.GetWeather(cityname); if (ModelState.IsValid) { await _iweatherRepositroy.Delete(weather); return(Ok(weather)); } else { return(BadRequest()); } }
public ActionResult Create([Bind(Include = "Id,HumidityPercent,Wind,Temperature,Date,City,Country")] Models.Weather weather) { if (ModelState.IsValid) { WeatherAppServices.Weather weatherService = new WeatherAppServices.Weather(); weatherService.Id = weather.Id; weatherService.HumidityPercent = weather.HumidityPercent; weatherService.Wind = weather.Wind; weatherService.Temperature = weather.Temperature; weatherService.Date = weather.Date; weatherService.City = weather.City; weatherService.Country = weather.Country; client.SubmitWeather(weatherService); return(RedirectToAction("Index")); } return(View(weather)); }
/// <summary> /// Guarda el clima de una ciudad en especifico /// </summary> /// <param name="id"></param> public static Models.Weather GetWeather(int id) { _id = id; Models.Weather weather = new Models.Weather(); string content = Task.Run(GetWeather).Result; WeatherAPI weathers = JsonConvert.DeserializeObject <WeatherAPI>(content); weather.IdExternal = weathers.weather[0].id; weather.Main = weathers.weather[0].main; weather.Description = weathers.weather[0].description; weather.Icon = weathers.weather[0].icon; weather.cod = weathers.cod; using (Y2kContext context = new Y2kContext()) { context.Weather.Add(weather); context.SaveChanges(); } return(weather); }
//[Route("create")] public async Task <IActionResult> Post(WeatherCreateViewModel model) { if (ModelState.IsValid) { Models.Weather weather = new Models.Weather() { CityName = model.City_Name, TempDate = model.Date.Date, TempTime = model.Time.TimeOfDay, Temperature = model.temprature, }; await _iweatherRepositroy.Create(weather); return(Ok(weather)); } else { return(BadRequest()); } }
public void WeatherAction_returns_WeatherView() { { Mock <IWeatherDAL> mockDAL = new Mock <IWeatherDAL>(); Models.Weather w = new Models.Weather(); w.ParkName = "CVNP"; List <Models.Weather> fakeList = new List <Models.Weather>(); fakeList.Add(w); mockDAL.Setup(m => m.Get5DaysOfWeather("CVNP")).Returns(fakeList); WeatherController c = new WeatherController(mockDAL.Object); var result = c.Weather("CVNP"); Assert.IsTrue(result is ViewResult); var view = result as ViewResult; Assert.AreEqual("Weather", view.ViewName); Assert.IsNotNull(view.Model); } }
// GET: Weathers/Edit/5 public ActionResult Edit(int?id) { WeatherAppServices.Weather weather = client.DeleteWeather(id); Models.Weather weatherWeb = new Models.Weather(); weatherWeb.Date = DateTime.Now; weatherWeb.Id = weather.Id; weatherWeb.HumidityPercent = weather.HumidityPercent; weatherWeb.Wind = weather.Wind; weatherWeb.Temperature = weather.Temperature; weatherWeb.City = weather.City; weatherWeb.Country = weather.Country; if (weatherWeb == null) { return(HttpNotFound()); } return(View(weatherWeb)); }
public ActionResult Index( ) { //建立http連線 using (HttpClient c = new HttpClient( )) { //基底網址uri c.BaseAddress = new Uri("https://opendata.cwb.gov.tw"); //.NET 4.5需手動添加建立 SSL/TLS 的安全通道 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //get,回傳HttpResponseMessage HttpResponseMessage response = c.GetAsync("/api/v1/rest/datastore/F-C0032-001?Authorization=CWB-422B0FA3-E374-492D-B54A-4D8942BE2B7E&format=JSON").Result; //以非同步作業方式將HTTP內容序列化為字串,回傳字串 string result = response.Content.ReadAsStringAsync( ).Result; //將JSON格式轉換成物件並放入Models.Weather Models.Weather w = JsonConvert.DeserializeObject <Models.Weather>(result); r = w.records; } return(View(r)); }
// GET: Weathers/Create public ActionResult Create() { Models.Weather weather = new Models.Weather(); weather.Date = DateTime.Now; return(View(weather)); }
public ForecastDay(DependencyObject dependency, Models.List listing, Models.Weather weather) : base(dependency) { _listing = listing; _weather = weather; }
public ForecastController(IHttpClientFactory clientFactory) { this.weather = new Models.Weather(clientFactory); }
public JsonResult GetWeather() { Models.Weather weath = new Models.Weather(); return(Json(weath.getWeatherForcast(), JsonRequestBehavior.AllowGet)); }