Esempio n. 1
0
        private async void CommandHandler(object sender, ExecutedRoutedEventArgs args)
        {
            if (inCommand)
            {
                return;
            }

            try
            {
                inCommand = true;
                var twitterStatus = StatusFromParameter(args.Parameter);
                if (twitterStatus is not null)
                {
                    if (twitterStatus.IsMyTweet)
                    {
                        return;
                    }

                    if (twitterStatus.Favorited)
                    {
                        await TwitterService.TwitterApi.DestroyFavorite(twitterStatus.Id).ConfigureAwait(true);

                        twitterStatus.FavoriteCount = Math.Max(0, twitterStatus.FavoriteCount - 1);
                        twitterStatus.Favorited     = false;
                    }
                    else
                    {
                        await TwitterService.TwitterApi.CreateFavorite(twitterStatus.Id).ConfigureAwait(true);

                        twitterStatus.FavoriteCount++;
                        twitterStatus.Favorited = true;
                    }

                    await FavoritesTimelineControlViewModel.UpdateAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                await MessageBoxService.ShowMessageBoxAsync(ex.Message).ConfigureAwait(false);
            }
            finally
            {
                inCommand = false;
            }
        }