Пример #1
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var httpClient = new HttpClient();

                var req = await httpClient.GetAsync("http://192.168.39.106:31000/WeatherForecast");

                if (req.IsSuccessStatusCode)
                {
                    var response = await req.Content.ReadAsStringAsync();

                    var forecast = JsonConvert.DeserializeObject <List <WeatherForecast> >(response);

                    var viewModel = new WeatherForecastViewModel {
                        Forecasts = forecast
                    };

                    return(View(viewModel));
                }

                return(View(new WeatherForecastViewModel {
                    Forecasts = new List <WeatherForecast>()
                }));
            }
            catch (Exception ex)
            {
                return(View(new WeatherForecastViewModel {
                    Forecasts = new List <WeatherForecast>()
                }));
            }
        }
Пример #2
0
        public WeatherForecastPage()
        {
            InitializeComponent();
            BindingContext = new WeatherForecastViewModel();

            SetLayout(DeviceDisplay.MainDisplayInfo);
            DeviceDisplay.MainDisplayInfoChanged += DeviceDisplay_MainDisplayInfoChanged;
        }
Пример #3
0
 public WeatherForecastView()
 {
     InitializeComponent();
     ForecastViewModel = new WeatherForecastViewModel()
                         .LoadCurrent()
                         .LoadForecasts();
     DataContext    = this;
     CurrentWeather = $"The Current Temperature is {ForecastViewModel.CurrentWeather.Temperature} Celsius Degrees.";
 }
Пример #4
0
        private IEnumerable <WeatherForecastViewModel> GetForecastViewModels(IEnumerable <WeatherForecast> forecasts)
        {
            var forecastViewModels = new List <WeatherForecastViewModel>();

            for (int i = 0; i < forecasts.Count() - 1; i++)
            {
                var forecastViewModel = new WeatherForecastViewModel(forecasts.ToArray()[i], forecasts.ToArray()[i + 1].ForecastTime);
                forecastViewModels.Add(forecastViewModel);
            }
            return(forecastViewModels);
        }
Пример #5
0
        public async Task GivenValidRequestServiceCanCreateNewWeatherForecast()
        {
            const int    year         = 2020;
            const int    month        = 6;
            const int    day          = 1;
            const string summary      = "Balmy";
            const string locationName = "Ann Arbor, MI";
            const double temperatureC = 20;
            const string scale        = "c";

            var date = new DateTime(year, month, day);

            var expectedLocation = new LocationViewModel
            {
                Id        = 1,
                Latitude  = 40,
                Longitude = 80,
                Name      = locationName
            };

            var createWeatherForecastRequest = new CreateWeatherForecastRequest
            {
                Summary     = summary,
                Date        = date,
                Temperature = temperatureC,
                Location    = expectedLocation,
                Scale       = scale
            };

            var expectedResult = new WeatherForecastViewModel
            {
                Id          = 1,
                Summary     = summary,
                Date        = date,
                Temperature = (decimal)temperatureC,
                Scale       = scale,
                Location    = expectedLocation
            };

            var body = ToStringContent(createWeatherForecastRequest);

            var response = await _client.PostAsync("/weatherforecasts", body);

            response.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var responseBody = await response.Content.ReadAsStringAsync();

            var createWeatherForecastResponse = JsonConvert.DeserializeObject <WeatherForecastResponse>(responseBody);

            createWeatherForecastResponse.Should().NotBeNull();
            createWeatherForecastResponse.Forecast.Should().NotBeNull();

            createWeatherForecastResponse.Forecast.Should().BeEquivalentTo(expectedResult);
        }
        public void ModelForBelfast_GivenBelfastAsLocation()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            PartialViewResult        result = controller.LoadWeather("belfast") as PartialViewResult;
            WeatherForecastViewModel model  = result.Model as WeatherForecastViewModel;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(model);
            Assert.AreEqual("Belfast", model.Location);
        }
Пример #7
0
        private WeatherForecastViewModel GetWeatherData(string location)
        {
            IWeatherService service = new MetaWeatherService();

            var weatherItems = service.GetWeatherItems(location);
            var top5Items    = weatherItems.Count() > 4 ? weatherItems.Take(5) : weatherItems;

            WeatherForecastViewModel model = new WeatherForecastViewModel
            {
                WeatherItems = top5Items,
                Location     = location
            };

            return(model);
        }
        private ActionResult PrevisaoTempoYahoo(string cidadeUrl)
        {
            var objCidade = cidadeUrl != null?Cidade.GetCidadeByUrl(cidadeUrl) : null;

            var objWeather = WeatherSrv.GetWeatherForecastByLocation(objCidade != null ? objCidade.Id : 12);

            if (objWeather == null || (objWeather != null && objWeather.WeatherPrincipal == null && !objWeather.WeatherCities.Any()))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            else if (objWeather != null && objWeather.WeatherPrincipal == null && objWeather.WeatherCities.Any())
            {
                ViewBag.ErrorWeather = "<p><div><h2>Ops!</h2></div><div><h4>Não conseguimos carregar a previsão do tempo para sua cidade. Tente novamente mais tarde.</div></h4></p>";
            }

            var model = new WeatherForecastViewModel
            {
                WeatherPrincipal = objWeather.WeatherPrincipal,
                Title            = $"Previsão do tempo em {objCidade.Nome}-PR - Massa News",
                Description      = $"Confira a previsão do tempo em {objCidade.Nome}-PR. Sensação térmica, umidade, direção e velocidade do vento e muita mais.",
                Robots           = "index, follow",
                Canonical        = $"{Constants.UrlWeb}/previsao-do-tempo/{objCidade.Url}"
            };

            if (objWeather.WeatherCities.Count() > 1)
            {
                var result = (double)objWeather.WeatherCities.Count() / (double)2;

                var metadeTamanhoLista = Convert.ToInt32(Math.Ceiling(result));

                model.WeatherCities1 = objWeather.WeatherCities.Take(metadeTamanhoLista).ToList();
                model.WeatherCities2 = objWeather.WeatherCities.Skip(metadeTamanhoLista).ToList();
            }
            else
            {
                model.WeatherCities1 = objWeather.WeatherCities;
                model.WeatherCities2 = new List <WeatherCities>();
            }

            ViewBag.ActiveNav = "Previsão do tempo";

            return(View("PrevisaoTempo", model));
        }
Пример #9
0
        /// <inheritdoc />
        public WeatherForecastViewModel GetWeatherData()
        {
            var viewModel = new WeatherForecastViewModel();

            viewModel.ErrorMessage       = WeatherForecastAggregateService.UpdateDataFromOnlineServices();
            viewModel.CurrentTemperature = WeatherForecastAggregateService
                                           .GetCurrentTemperature();
            viewModel.CurrentTemperatureMatchForecast = WeatherForecastAggregateService
                                                        .CurrentTemperatureMatchForecast(DateTime.Now);
            viewModel.CurrentDayForecastAccuracy = WeatherForecastAggregateService
                                                   .GetCurrentDayForecastAccuracy();
            viewModel.MinDayTemperatures = WeatherForecastAggregateService
                                           .GetMinDayTemperatures();
            viewModel.MaxDayTemperatures = WeatherForecastAggregateService
                                           .GetMaxDayTemperatures();
            viewModel.MinNightTemperatures = WeatherForecastAggregateService
                                             .GetMinNightTemperatures();
            viewModel.MaxNightTemperatures = WeatherForecastAggregateService
                                             .GetMaxNightTemperatures();
            return(viewModel);
        }
Пример #10
0
        public IActionResult GetWeatherForecastReturnAsWeatherForecastViewModel()
        {
            //Weather Forecast service => go get the weather
            var rng = new Random();
            var weatherForecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            })
                                   .ToArray();

            //ViewModel builder => go build a ViewModel
            var viewModel = new WeatherForecastViewModel
            {
                Meta             = "I was built from the Micro Proxy API",
                WeatherForecasts = weatherForecasts.ToList()
            };

            return(new JsonResult(viewModel));
        }
Пример #11
0
        public async Task <IActionResult> IndexAsync(
            [FromServices] IHttpClientFactory p_Factory
            )
        {
            WeatherForecastViewModel v_Model = new WeatherForecastViewModel();

            try
            {
                string v_Endpoint = "WeatherForecast";
                var    v_Client   = p_Factory.CreateClient("weather");

                var v_Request = new HttpRequestMessage(
                    HttpMethod.Get,
                    new Uri(v_Client.BaseAddress + v_Endpoint)
                    );
                m_Logger.LogInformation("URL: " + new Uri(v_Client.BaseAddress + v_Endpoint));
                v_Request.SetPolicyExecutionContext(
                    new Context("GetWeather")
                    );
                var v_Response = await v_Client.SendAsync(v_Request);

                if (!v_Response.IsSuccessStatusCode)
                {
                    throw new ApplicationException("Echec requête");
                }

                v_Model.Forecast = JsonConvert.DeserializeObject <IEnumerable <WeatherForecast> >(
                    await v_Response.Content.ReadAsStringAsync()
                    );
                //v_Model.Forecast = await m_WeatherService.GetWeatherForecastAsync();
            }
            catch (Exception v_Ex)
            {
                m_Logger.LogError(v_Ex, "Failed to get weather forecast");

                v_Model.HasError = true;
            }

            return(View(v_Model));
        }
Пример #12
0
 public WeatherForecastPage()
 {
     this.DataContext = _viewModel = new WeatherForecastViewModel();
     this.InitializeComponent();
 }
Пример #13
0
 void openModal(int hash)
 {
     this.Model      = new WeatherForecastViewModel();
     this.modalTitle = "Cadastro de Venda";
     this.ModalOpen  = true;
 }
 public WeatherForecastControl()
 {
     this.InitializeComponent();
     ViewModel = new WeatherForecastViewModel(ViewModelLocator.Current.WeatherDataService);
 }
Пример #15
0
 public MainWindow(AppSecrets appSecrets, Location location)
 {
     InitializeComponent();
     DataContext = new WeatherForecastViewModel(appSecrets, location);
 }