Exemple #1
0
        public async Task <IActionResult> GetWeather([FromQuery] int weatherId = 0, float latitude = 0, float longitude = 0)
        {
            WeatherLogic   weatherLogic = new WeatherLogic();
            List <Weather> weathers     = await weatherLogic.GetWeather(weatherId, latitude, longitude);

            if (weathers == null)
            {
                return(BadRequest(weatherLogic.Response.ErrorMessage));
            }
            return(Ok(weathers));
        }
Exemple #2
0
        public async Task <IActionResult> InsertWeather([FromBody] InsertWeatherRequest request)
        {
            WeatherLogic weatherLogic = new WeatherLogic();
            int          id           = await weatherLogic.InsertWeather(request);

            if (id == 0)
            {
                return(BadRequest(weatherLogic.Response.ErrorMessage));
            }
            return(Ok(id));
        }
Exemple #3
0
        public async void SearchWeather(object sender, EventArgs e)
        {
            MainActivityIndicator.IsRunning = true;
            string cityName = searchEntry.Text;

            var weatherData = await WeatherLogic.GetWeatherDataByCity(cityName);

            weatherImage.Source             = $"http://openweathermap.org/img/wn/{weatherData.weather[0].icon}@4x.png";
            tempLabel.Text                  = WeatherLogic.ConvertToCelcius(weatherData.main.temp).ToString();
            tempTypeLabel.IsVisible         = true;
            conditionLabel.Text             = weatherData.weather[0].main;
            locationLabel.Text              = $"{weatherData.name}, {weatherData.sys.country}";
            MainActivityIndicator.IsRunning = false;
        }
Exemple #4
0
        private async void SetDataForScrollView(string placeName = null)
        {
            SetLoadingText();
            //create grid inside dataScrollView removing previous content
            Grid innerGrid = new Grid();

            dataScrollView.Content = innerGrid;

            //get weather data
            List <WeatherModel> weatherData = await WeatherLogic.GetWeatherDataFor(placeName ?? defaultPlaceName);

            //set place name label
            placeNameLabel.Text = placeName ?? defaultPlaceName;

            if (weatherData.Count == 0)
            {
                innerGrid.Children.Add(new Label()
                {
                    Text = $"No data for: {placeName ?? defaultPlaceName}."
                });
            }
            else
            {
                SetDataGridHeaders(innerGrid);

                for (int curr = 0; curr < weatherData.Count; curr++)
                {
                    innerGrid.Children.Add(new Label()
                    {
                        Text = weatherData[curr].WeatherDate.ToString("HH:mm")
                    }, 0, (curr + 1));
                    innerGrid.Children.Add(new Label()
                    {
                        Text = $"{weatherData[curr].Temperature.ToString("0.0")}°"
                    }, 1, (curr + 1));
                    innerGrid.Children.Add(new Label()
                    {
                        Text = $"{weatherData[curr].WeatherDescription}"
                    }, 2, (curr + 1));
                    innerGrid.Children.Add(new Image()
                    {
                        Source = $"http://openweathermap.org/img/w/{weatherData[curr].WeatherIconName}.png"
                    }, 3, (curr + 1));
                }
            }
        }
Exemple #5
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            try
            {
                var weatherData = await WeatherLogic.GetWeatherData();

                tempLabel.Text          = WeatherLogic.ConvertToCelcius(weatherData.main.temp).ToString();
                tempTypeLabel.IsVisible = true;
                conditionLabel.Text     = weatherData.weather[0].main;
                locationLabel.Text      = $"{weatherData.name}, {weatherData.sys.country}";
                weatherImage.Source     = $"http://openweathermap.org/img/wn/{weatherData.weather[0].icon}@4x.png";

                MainActivityIndicator.IsRunning = false;
            }

            catch (Exception e)
            {
                await DisplayAlert("Problem fetching data", "Please turn your location on and restart the app", "Ok");
            }
        }
 public WeatherController()
 {
     _weatherLogic = new WeatherLogic();
 }