Esempio n. 1
0
        /// <summary>
        /// Deletes city from favorites after the user clicked on favorite button under weather details of the city
        /// and refreshes the content on the page
        /// </summary>
        /// <returns></returns>
        private async Task DeleteCityFromFavorites(int cityId)
        {
            // get the current favorites list
            await _firebaseHelper.GetFavoritesCities();

            // delete the city from favorites
            if (await _firebaseHelper.CityIsInFavorites(cityId))
            {
                await _firebaseHelper.DeleteCityFromFavorites(cityId);
            }
            else
            {
                // if the city is not in favorites for some reason, then show notification to the user
                // to contact with the developer
                await new MessageDialog("There is not such city in the database. \n " +
                                        "Let's try to contact with the autor of this application, please").ShowAsync();
            }

            // refresh the layout
            //await Task.Delay(TimeSpan.FromSeconds(5));
            await RefreshFavoriteCitiesList();
        }
        /// <summary>
        /// Adds city to the favorite cities list if the city doesn't belong to it
        /// Deletes city from the favorite cities list if the city belong to it
        /// </summary>
        /// <returns></returns>
        private async Task AddOrDeleteCityFromFavorites()
        {
            // get the current favorites list
            FirebaseHelper firebaseHelper = new FirebaseHelper();
            await firebaseHelper.GetFavoritesCities();

            // Add or delete the city form favorites
            if (await firebaseHelper.CityIsInFavorites(_weatherForecastService.CityId))
            {
                await firebaseHelper.DeleteCityFromFavorites(_weatherForecastService.CityId);
            }
            else
            {
                await firebaseHelper.PutFavoriteCity(
                    _weatherForecastService.CityName,
                    _weatherForecastService.CityId
                    );
            }

            // reload favorite icon
            await IsCityInFavorites();
        }