Esempio n. 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     LibrarySystemEntities context = new LibrarySystemEntities();
     var categories = context.Categories.Include("Books").ToList();
     this.CategoriesList.DataSource = categories;
     this.DataBind();
 }
Esempio n. 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     string queryString = Convert.ToString(Request.Params["q"]);
     this.queryStringLiteral.Text = queryString;
     var context = new LibrarySystemEntities();
     var books = context.Books.Where(
         x => x.Title.Contains(queryString) || x.Author.Contains(queryString)).
         OrderBy(x => x.Title).ThenBy(x => x.Author).ToList();
     this.resultList.DataSource = books;
     this.resultList.DataBind();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     int bookId = Convert.ToInt32(Request.Params["id"]);
     var context = new LibrarySystemEntities();
     var book = context.Books.Find(bookId);
     this.titleLiteral.Text = book.Title;
     this.authorLiteral.Text = "by " + book.Author;
     this.isbnLiteral.Text = "ISBN " + book.ISBN;
     this.websiteLink.NavigateUrl = Server.HtmlEncode(book.WebSite);
     this.websiteLink.Text = Server.HtmlEncode(book.WebSite);
     this.discriptionLiteral.Text = book.Discription;
 }
Esempio n. 4
0
 protected void deleteBookButton_Command(object sender, CommandEventArgs e)
 {
     this.deleteBookPanel.Visible = true;
     this.newBookButton.Visible = false;
     int bookId = Convert.ToInt32(e.CommandArgument);
     LibrarySystemEntities context = new LibrarySystemEntities();
     Book book = context.Books.Find(bookId);
     try
     {
         this.deleteTitleBox.Text = book.Title;
         Session["bookId"] = bookId.ToString();
     }
     catch (Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
     }
 }
 protected void editCategoryButton_Command(object sender, CommandEventArgs e)
 {
     this.editCategoryPanel.Visible = true;
     this.newCategoryButton.Visible = false;
     int categoryId = Convert.ToInt32(e.CommandArgument);
     LibrarySystemEntities context = new LibrarySystemEntities();
     Category category = context.Categories.Find(categoryId);
     try
     {
         this.editCategoryBox.Text = category.Name;
         Session["categoryId"] = categoryId.ToString();
     }
     catch (Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
     }
 }
Esempio n. 6
0
 protected void editBookButton_Command(object sender, CommandEventArgs e)
 {
     this.editBookPanel.Visible = true;
     this.newBookButton.Visible = false;
     int bookId = Convert.ToInt32(e.CommandArgument);
     LibrarySystemEntities context = new LibrarySystemEntities();
     Book book = context.Books.Find(bookId);
     try
     {
         this.editTitleBox.Text = book.Title;
         this.editAuthorBox.Text = book.Author;
         this.editISBNBox.Text = book.ISBN;
         this.editWebSiteBox.Text = book.WebSite;
         this.editDescriptionBox.Text = book.Discription;
         this.allCategoriesList.DataSource = context.Categories.ToList();
         this.allCategoriesList.DataBind();
         Session["bookId"] = bookId.ToString();
         Session["categoryId"] = "1";
     }
     catch(Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
     }
 }
Esempio n. 7
0
 // The return type can be changed to IEnumerable, however to support
 // paging and sorting, the following parameters must be added:
 //     int maximumRows
 //     int startRowIndex
 //     out int totalRowCount
 //     string sortByExpression
 public IQueryable<BookLibrary.Models.Book> booksGrid_GetData()
 {
     LibrarySystemEntities context = new LibrarySystemEntities();
     return context.Books.Include("Category").OrderBy(x => x.BookId);
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
 protected void newBookButton_Click(object sender, EventArgs e)
 {
     this.newBookPanel.Visible = true;
     this.newBookButton.Visible = false;
     LibrarySystemEntities context = new LibrarySystemEntities();
     this.newAllCategoriesList.DataSource = context.Categories.ToList();
     this.newAllCategoriesList.DataBind();
     Session["categoryId"] = "1";
 }
 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);
     }
 }
 // The return type can be changed to IEnumerable, however to support
 // paging and sorting, the following parameters must be added:
 //     int maximumRows
 //     int startRowIndex
 //     out int totalRowCount
 //     string sortByExpression
 public IQueryable<BookLibrary.Models.Category> categoriesGrid_GetData()
 {
     LibrarySystemEntities context = new LibrarySystemEntities();
     return context.Categories.OrderBy(x => x.CategoryId);
 }
 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 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);
            }
        }