private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            btnDelete.IsEnabled = false;

            var confirmResult = await DialogManager.ShowConfirmationDialog()
                                .ConfigureAwait(true);

            if (confirmResult != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
            {
                btnDelete.IsEnabled = true;
                return;
            }

            var result = await PostApi.Remove(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                CurrentPostData.Id)
                         .ConfigureAwait(true);

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

                btnDelete.IsEnabled = true;
                return;
            }

            Visibility = Visibility.Collapsed;

            RaiseEvent(new RoutedEventArgs(OnPostDeleted));

            btnDelete.IsEnabled = true;
        }
Esempio n. 2
0
        private async void Delete_Click(object sender,
                                        RoutedEventArgs e)
        {
            DeleteButton.IsEnabled = false;

            try
            {
                if (!CurrentPostData.OwnerId.HasValue || CurrentPostData.OwnerId == -1)
                {
                    return;
                }
                if (CurrentPostData.OwnerId != SettingsManager.PersistentSettings.CurrentUser.Id)
                {
                    return;
                }

                var confirmResult = await DialogManager.ShowConfirmationDialog()
                                    .ConfigureAwait(true);

                if (confirmResult != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
                {
                    return;
                }

                var result = await PostApi.Remove(
                    SettingsManager.PersistentSettings.CurrentUser.Token,
                    CurrentPostData.Id)
                             .ConfigureAwait(true);

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

                    return;
                }

                Visibility = Visibility.Collapsed;

                RaiseEvent(new RoutedEventArgs(PostDeleteEvent, sender));
            }
            finally
            {
                DeleteButton.IsEnabled = true;
            }
        }