private void btnBookDelete_Click(object sender, EventArgs e) { if (dataGridViewBooks.SelectedRows.Count > 0) { int index = dataGridViewBooks.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridViewBooks[0, index].Value.ToString(), out id); if (converted == false) { return; } Book book = _db.Books.Find(id); _db.Books.Remove(book); _db.SaveChanges(); // delete book from search result if (SearchedBooks.Find(b => b.Id == id) != null) { SearchedBooks.Remove(book); } bindingSourceBookSearch.DataSource = null; bindingSourceBookSearch.DataSource = SearchedBooks; MessageBox.Show($"Book \"{book.Title}\" was deleted"); } }
protected override void Internal_UpdateInMemory(BookViewModel book) { BookFacade.Update(book); int index = BookSource.IndexOf(BookSource.Where(b => b.ID.Equals(book.ID)).Single()); BookSource[index] = book; if (SearchedBooks != null) { index = SearchedBooks.IndexOf(SearchedBooks.Where(b => b.ID.Equals(book.ID)).Single()); SearchedBooks[index] = book; } RaisePropertyChanged(PropertyNameUtility.GetPropertyName(() => OnStage)); }
private async void btnBookSearch_Click(object sender, EventArgs e) { BookSearchForm bookSearchForm = new BookSearchForm(); DialogResult result = bookSearchForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } SearchedBooks.Clear(); SearchedBooks = await SearchBooks(bookSearchForm); bindingSourceBookSearch.DataSource = SearchedBooks; dataGridViewBooks.DataSource = bindingSourceBookSearch; }