예제 #1
0
        public async Task <IActionResult> Index()
        {
            _logger.LogInformation($"{nameof(HomeController.Index)} called.");

            var indexViewModel = new IndexViewModel();

            // latest sensor data
            var latestTemperature = await _temperatureService.GetLatest();

            if (latestTemperature != null)
            {
                indexViewModel.SensorTemperature = new SensorTemperatureResponseModel(
                    latestTemperature.Temperature,
                    latestTemperature.Humidity,
                    latestTemperature.DateTime);
            }

            // forecast data
            var currentForecastData = await _forecastProvider.GetCurrentForecastAsync();

            indexViewModel.ForecastTemperature = new ForecastTemperatureResponseModel
            {
                Temperature    = currentForecastData.Temperature,
                Icon           = currentForecastData.Icon,
                MinTemperature = currentForecastData.MinTemperature,
                MaxTemperature = currentForecastData.MaxTemperature,
                TakenAtTime    = currentForecastData.TakenAtTime.ToString("HH:mm:ss")
            };

            return(View(indexViewModel));
        }