Пример #1
0
        private async void RemoveImageFromAlbum_Click(object sender, RoutedEventArgs e)
        {
            var files = imagesGridView.SelectedItems;

            string title   = "Remove image";
            string message = $"Are you sure you want to remove this image from {SelectedContentFolder?.Name}?";

            if (files.Count == 0)
            {
                return;
            }
            else if (files.Count > 1)
            {
                title   = "Remove images";
                message = $"Are you sure you want to remove those images from {SelectedContentFolder?.Name}?";
            }

            ContentDialog removeImageDialog = new ContentDialog
            {
                Title             = title,
                Content           = message,
                PrimaryButtonText = "Remove",
                CloseButtonText   = "Cancel"
            };
            ContentDialogResult result = await removeImageDialog.ShowAsync();

            // Delete the file if the user clicked the primary button.
            /// Otherwise, do nothing.
            if (result == ContentDialogResult.Primary)
            {
                foreach (var file in files)
                {
                    if (file is ImageItem imageItem)
                    {
                        try
                        {
                            await DatabaseAccessService.DeleteImageAsync(imageItem.DatabaseId);
                        }
                        catch (Exception)
                        {
                            var messageDialog = new MessageDialog("Operation failed");
                            await messageDialog.ShowAsync();
                        }
                    }
                }
                await SelectedContentFolder.UpdateQueryAsync();
            }
        }