コード例 #1
0
        public PartialViewResult ShowSearchResults(string searchQuery)
        {
            var httpClient     = new WeatherHTTPClientController();
            var resultForecast = httpClient.GetSearchResultsGetByQuery(searchQuery);

            //return View(resultForecast);
            return(PartialView("ShowSearchResultsPartial", resultForecast));
        }
コード例 #2
0
        public PartialViewResult ShowDetails(string cityId)
        {
            var httpClient     = new WeatherHTTPClientController();
            var detailedResult = httpClient.GetByCityForecast(cityId);

            var viewModel = new DetailedViewModel()
            {
                CityName = detailedResult.City.Name,
                CityId   = cityId
            };

            var testSplitDays = detailedResult.DetailedInformation.Select(x => x.Date.Day).Distinct().ToList();

            foreach (var value in testSplitDays)
            {
                var temperatures = detailedResult.DetailedInformation.Where(x => x.Date.Day == value).ToList();

                double maxForDay = 0;
                double minForDay = temperatures[0].Temperature.MinTemperature;


                foreach (var tempValue in temperatures)
                {
                    if (tempValue.Temperature.MinTemperature < minForDay)
                    {
                        minForDay = tempValue.Temperature.MinTemperature;
                    }

                    if (tempValue.Temperature.MaxTemperature > maxForDay)
                    {
                        maxForDay = tempValue.Temperature.MaxTemperature;
                    }
                }


                var item = detailedResult.DetailedInformation.FirstOrDefault(x => x.Date.Day == value && x.Date.Hour >= 14);

                if (item == null)
                {
                    item = detailedResult.DetailedInformation.FirstOrDefault(x => x.Date.Day == value);
                }

                var Info = new DetailedInformation();
                Info.Date           = item.Date;
                Info.TemperatureMax = Convert.ToInt32(maxForDay);
                Info.TemperatureMin = Convert.ToInt32(minForDay);
                Info.Weather        = item.Weather[0].WeatherDescription;
                Info.WeatherIconUrl = item.Weather[0].IconImageUrl;
                Info.Day            = item.Date.ToString("dddd", new CultureInfo("en-US"));

                viewModel.DetailedInformation.Add(Info);
            }

            return(PartialView("ShowDetailsPartial", viewModel));
        }
コード例 #3
0
        public async Task <PartialViewResult> ShowOverview(string searchQuery = "2673730") //Default startsida är stockholm
        {
            var httpClient = new WeatherHTTPClientController();
            var result     = httpClient.GetByCityToday(searchQuery);

            var viewModel = new OverviewViewModel()
            {
                Day         = result.Date,
                Date        = result.Date.ToString("dd/MMM", new CultureInfo("en-US")),
                CityId      = result.CityId,
                CityName    = result.CityName,
                CurrentTemp = Convert.ToInt32(result.Temperature.CurrentTemperature),
                Weather     = result.Weather[0].WeatherDescription,
                WeatherUrl  = result.Weather[0].IconImageUrl
            };

            return(PartialView("ShowOverviewPartial", viewModel));
        }
コード例 #4
0
        public IActionResult Main(string searchQuery = "2673730") //Default startsida är stockholm)
        {
            var httpClient = new WeatherHTTPClientController();
            var result     = httpClient.GetByCityToday(searchQuery);

            var viewModel = new OverviewViewModel()
            {
                Day         = result.Date,
                Date        = result.Date.ToString("dd/MMM"),
                CityId      = result.CityId,
                CityName    = result.CityName,
                CurrentTemp = Convert.ToInt32(result.Temperature.CurrentTemperature),
                Weather     = result.Weather[0].WeatherDescription,
                WeatherUrl  = result.Weather[0].IconImageUrl
            };

            return(View(viewModel));
        }