protected void yesBookButton_Click(object sender, EventArgs e) { var bookId = Convert.ToInt32(Session["bookId"]); Session["bookId"] = null; LibrarySystemEntities context = new LibrarySystemEntities(); Book book = context.Books.Find(bookId); try { context.Books.Remove(book); context.SaveChanges(); this.booksGrid.PageIndex = 0; this.deleteBookPanel.Visible = false; this.newBookButton.Visible = true; ErrorSuccessNotifier.AddSuccessMessage("Book was successfully deleted."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void saveNewBookButton_Click(object sender, EventArgs e) { try { var title = this.newTitleBox.Text; var author = this.newAuthorBox.Text; if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(author)) { throw new ArgumentNullException( "The title or the author of a book could not be null or white space"); } var isbn = this.newISBNBox.Text; var website = this.newWebSiteBox.Text; var pattern = @"^(https?|ftp|file)://.+$"; if (!Regex.IsMatch(website, pattern)) { throw new ArgumentOutOfRangeException( "The book web site url is not valid"); } var description = this.newDescriptionBox.Text; var categoryId = Convert.ToInt32(Session["categoryId"]); Session["categoryId"] = null; LibrarySystemEntities context = new LibrarySystemEntities(); Book book = new Book() { Title = title, Author = author, ISBN = isbn, WebSite = website, Discription = description }; Category category = context.Categories.Find(categoryId); category.Books.Add(book); context.SaveChanges(); this.booksGrid.PageIndex = 0; this.newBookPanel.Visible = false; this.newBookButton.Visible = true; ErrorSuccessNotifier.AddSuccessMessage("Book was successfully added."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void yesCategoryButton_Click(object sender, EventArgs e) { try { var categoryId = Convert.ToInt32(Session["categoryId"]); Session["categoryId"] = null; LibrarySystemEntities context = new LibrarySystemEntities(); Category category = context.Categories.Find(categoryId); context.Books.RemoveRange(category.Books); context.Categories.Remove(category); context.SaveChanges(); this.categoriesGrid.PageIndex = 0; this.deleteCategoryPanel.Visible = false; this.newCategoryButton.Visible = true; ErrorSuccessNotifier.AddSuccessMessage("Category was successfully deleted."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void saveCategoryButton_Click(object sender, EventArgs e) { try { var name = this.editCategoryBox.Text; if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException( "The name of a category could not be null or white space"); } var categoryId = Convert.ToInt32(Session["categoryId"]); Session["categoryId"] = null; LibrarySystemEntities context = new LibrarySystemEntities(); Category category = context.Categories.Find(categoryId); category.Name = name; context.SaveChanges(); this.categoriesGrid.PageIndex = 0; this.editCategoryPanel.Visible = false; this.newCategoryButton.Visible = true; ErrorSuccessNotifier.AddSuccessMessage("Category was successfully edeted."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }
protected void saveNewCategoryButton_Click(object sender, EventArgs e) { try { var name = this.newCategoryBox.Text; if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException( "The name of a category could not be null or white space"); } LibrarySystemEntities context = new LibrarySystemEntities(); Category category = new Category { Name = name }; context.Categories.Add(category); context.SaveChanges(); this.categoriesGrid.PageIndex = 0; this.newCategoryPanel.Visible = false; this.newCategoryButton.Visible = true; ErrorSuccessNotifier.AddSuccessMessage("Category was successfully added."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } }