public async void _RemoveBook() { if (SelectedTableRow == null) { return; } Database.BookEntry book = SelectedTableRow; bool onDevice = SelectedDevice == null ? false : CombinedLibrary.Any(x => x.IsRemote && x.Id == book.Id); bool onPC = CombinedLibrary.Any(x => x.IsLocal && x.Id == book.Id); var dlg = new Dialogs.DeleteConfirm(book.Title, onDevice, onPC); await MaterialDesignThemes.Wpf.DialogHost.Show(dlg); if (dlg.DialogResult == false) { return; } if (dlg.DeleteFrom == 0 || dlg.DeleteFrom == 1) // device { Database.BookEntry remoteBook = SelectedDevice.Database.BOOKS.FirstOrDefault(x => x.Id == book.Id); try { SelectedDevice.DeleteBook(book.Id); } catch (Exception e) { var errDlg = new Dialogs.Error($"Unable to delete book from {SelectedDevice.Name}", e.Message); await MaterialDesignThemes.Wpf.DialogHost.Show(errDlg); return; } } if (dlg.DeleteFrom == 0 || dlg.DeleteFrom == 2) // pc { Database.BookEntry localBook = CombinedLibrary.FirstOrDefault(x => x.IsLocal && x.Id == book.Id); try { if (localBook != null) { try { App.LocalLibrary.DeleteBook(localBook); } catch (FileNotFoundException) { } catch (DirectoryNotFoundException) { } Utils.Files.CleanBackward(Path.GetDirectoryName(localBook.FilePath), App.LibraryDirectory); } App.LocalLibrary.Database.RemoveBook(book); } catch (Exception e) { var errDlg = new Dialogs.Error("Unable to delete book from library", e.Message); await MaterialDesignThemes.Wpf.DialogHost.Show(errDlg); return; } } string msg = dlg.DeleteFrom == 0 ? "PC & Kindle" : (dlg.DeleteFrom == 2 ? "PC" : "Kindle"); SnackBarQueue.Enqueue($"{book.Title} deleted from {msg}."); }