protected void EditBookButton_Command(object sender, CommandEventArgs e) { try { var context = new LibrarySystemEntities(); int bookId = Convert.ToInt32(e.CommandArgument); var book = context.Books.Find(bookId); book.Title = this.TexboxForBookTitle.Text; book.Author = this.TexboxForBookAuthor.Text; book.ISBN = this.TexboxForBookISBN.Text; book.Description = this.TexboxForBookDescription.Text; book.WebSite = this.TexboxForBookWebSiet.Text; int selectedCategoryId = Convert.ToInt32(this.SelectForBookCategory.SelectedValue); Category selectedCategory = context.Categories.FirstOrDefault(c => c.Id == selectedCategoryId); book.Category = selectedCategory; context.SaveChanges(); ErrorSuccessNotifier.AddSuccessMessage("Book '" + book.Title + "' edited."); this.editBookConteiner.Visible = false; this.AllBooks.SelectMethod = "AllBooks_GetData"; this.AllBooks.DataBind(); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void EditCategoryButton_Command(object sender, CommandEventArgs e) { try { var context = new LibrarySystemEntities(); int categoryId = Convert.ToInt32(e.CommandArgument); var category = context.Categories.Find(categoryId); category.Title = this.TexboxForCategoryToEdit.Text; context.SaveChanges(); ErrorSuccessNotifier.AddSuccessMessage("Category '" + category.Title + "' edited successfuly."); this.editCategoryConteiner.Visible = false; } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } this.AllCategories.SelectMethod = "AllCategories_GetData"; this.AllCategories.DataBind(); }
protected void DeleteBookButton_Command(object sender, CommandEventArgs e) { try { var context = new LibrarySystemEntities(); int bookId = Convert.ToInt32(e.CommandArgument); var book = context.Books.Find(bookId); context.Books.Remove(book); context.SaveChanges(); this.AllBooks.SelectMethod = "AllBooks_GetData"; this.AllBooks.DataBind(); ErrorSuccessNotifier.AddInfoMessage("Book '" + book.Title + "' deleted."); this.deleteBookConteiner.Visible = false; } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void DeleteCategoryButton_Command(object sender, CommandEventArgs e) { try { var context = new LibrarySystemEntities(); int categoryId = Convert.ToInt32(e.CommandArgument); var category = context.Categories.Find(categoryId); context.Books.RemoveRange(category.Books); context.Categories.Remove(category); context.SaveChanges(); ErrorSuccessNotifier.AddInfoMessage("Category '" + category.Title + "' deleted along with all related books."); this.deleteCategoryConteiner.Visible = false; } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } this.AllCategories.SelectMethod = "AllCategories_GetData"; this.AllCategories.DataBind(); }
protected void CreateCategoryButton_Command(object sender, CommandEventArgs e) { try { var context = new LibrarySystemEntities(); Category category = new Category(); category.Title = this.TexboxForCategoryToCreate.Text; context.Categories.Add(category); context.SaveChanges(); ErrorSuccessNotifier.AddSuccessMessage("Category '" + category.Title + "' created."); this.createCategoryConteiner.Visible = false; } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } this.AllCategories.SelectMethod = "AllCategories_GetData"; this.AllCategories.DataBind(); }