/// <summary> /// Removes the current favorite from the favorites list. /// </summary> private void RemoveFavorite() { // If the current view model is busy do nothing if (this.viewModel.IsBusy) { return; } // Prepare the data to be send to the server var request = new Json.JsonObject { { "montonera", this.favorite.Id } }; // Send request to the server this.viewModel.IsBusy = true; WebHelper.SendAsync( Uris.GetRemoveFromFavoritesUri(), request.AsHttpContent(), _ => { this.OnFavoriteRemoved(); this.viewModel.IsBusy = false; }, () => this.viewModel.IsBusy = false); }
/// <summary> /// Sets the current favorite as primary. /// </summary> private void SetAsPrimary() { // If the current view model is busy do nothing if (this.viewModel.IsBusy) { return; } // Prepare the data to be send to the server var request = new Json.JsonObject { { "montonera", this.favorite.Id }, { "principal", true } }; // Send request to the server this.viewModel.IsBusy = true; WebHelper.SendAsync( Uris.GetAddToFavoritesUri(), request.AsHttpContent(), _ => { this.IsPrimary = true; this.viewModel.IsBusy = false; }, () => this.viewModel.IsBusy = false); }
/// <summary> /// Sets the push notification token used for the current application. /// </summary> /// <param name="pushToken">The device push notification token.</param> internal static void SetPushToken(string pushToken) { // If push token have not been changed Debug.WriteLine("New push token available: " + pushToken); var currentPushToken = Settings.Instance.GetValue(Settings.PushToken, string.Empty); if (string.Compare(currentPushToken, pushToken, StringComparison.CurrentCultureIgnoreCase) == 0) { // Do nothing return; } // Get the current application instance var instance = Application.Current as App; if (instance != null) { // Set the push token instance.PushToken = pushToken; } // If user is logged in if (Settings.Instance.Contains(Settings.AccessToken)) { // Prepare the data to be send to the server var deviceId = instance?.DeviceId ?? string.Empty; var request = new Json.JsonObject { { "device", deviceId }, { "push_token", pushToken } }; // Send request to the server Debug.WriteLine("Update push token on server"); WebHelper.SendAsync( Uris.GetChangePushTokenUri(), request.AsHttpContent(), _ => Settings.Instance.SetValue(Settings.PushToken, pushToken)); } }