private void OnDeleteCommand(object obj) { if (IsLoading) { ToastHelper.ShowMessage("加载中,请稍后"); return; } var localItem = obj as LocalBookItemViewModel; if (localItem == null) { return; } IsLoading = true; Task.Run(() => { var reslut = DbLocalBook.DeleteBook(AppDataPath.GetLocalBookDbPath(), localItem.CurrentBook.BookId); DispatcherHelper.CheckBeginInvokeOnUI(() => { if (!reslut) { ToastHelper.ShowMessage($"{localItem.CurrentBook.BookName}删除失败,请重试", false); return; } localItem.IsDeleted = true; LocalBooks.Remove(localItem); IsLoading = false; }); }); }
public void InserOrUpdateBook(Book book) { if (book == null) { return; } var temp = LocalBooks.FirstOrDefault(p => p.CurrentBook.BookId == book.BookId); DbLocalBook.InsertOrUpdatBook(AppDataPath.GetLocalBookDbPath(), book); DispatcherHelper.CheckBeginInvokeOnUI(() => { if (temp != null) { LocalBooks.Remove(temp); } LocalBooks.Insert(0, new LocalBookItemViewModel(book)); }); if (!IsInit) { GetLocalBookFromDb(); } }