コード例 #1
0
        public ActionResult CurrentWeather(GetCurrentWeather model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.NotFound   = false;
                ViewBag.Validation = false;
                return(View(model));
            }
            ViewBag.Validation = true;
            var result = weatherService.GetCurrentWeather(new GetWeatherModel
            {
                City    = model.City,
                Country = model.Country
            });

            if (result != null)
            {
                model.Humidity          = result.humidity;
                model.TemperatureFormat = result.temperature?.format;
                model.TemperatureValue  = result.temperature?.value ?? 0;
            }
            else
            {
                ViewBag.NotFound = true;
            }
            return(View(model));
        }
        public JsonResult GetCurrent()
        {
            var weather = new GetCurrentWeather();
            var result  = weather.GetTodayWeather();

            return(new JsonResult(result, new JsonSerializerSettings()
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            }));
        }