Example #1
0
        private async void Like_Click(object sender,
                                      RoutedEventArgs e)
        {
            LikeButton.IsEnabled = false;

            try
            {
                ApiResponse <CountSchema> result;

                if (CurrentPostData.Likes.MyCount == 0)
                {
                    result = await PostApi.AddLike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }
                else
                {
                    result = await PostApi.RemoveLike(
                        SettingsManager.PersistentSettings.CurrentUser.Token,
                        CurrentPostData.Id)
                             .ConfigureAwait(true);
                }

                if (result.IsError)
                {
                    await DialogManager.ShowErrorDialog(result.Message)
                    .ConfigureAwait(true);

                    return;
                }

                if (CurrentPostData.Likes.MyCount == 0)
                {
                    ++CurrentPostData.Likes.MyCount;
                }
                else
                {
                    --CurrentPostData.Likes.MyCount;
                }

                CurrentPostData.Likes.TotalCount = result.Data.Count;
            }
            finally
            {
                LikeButton.IsEnabled = true;
            }
        }