Esempio n. 1
0
        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);
            }

        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var searchQuery = Request.Params["q"];

            var context = new LibrarySystemEntities();

            if (!string.IsNullOrEmpty(searchQuery))
            {
                var results = context.Books
                    .Where(r => r.Title.Contains(searchQuery) || r.Author.Contains(searchQuery))
                    .OrderBy(b => b.Author)
                    .ThenBy(x => x.Author)
                    .ToList();

                this.searchResultsTitle.Text = searchQuery;

                this.searchResults.DataSource = results;
                this.searchResults.DataBind();
            }
            else
            {
                var results = context.Books
                .OrderBy(b => b.Author)
                .ThenBy(x => x.Author)
                .ToList();

                this.searchResultsTitle.Text = searchQuery;

                this.searchResults.DataSource = results;
                this.searchResults.DataBind();
            }
        }
Esempio n. 3
0
 protected void singleResult_Command(object sender, CommandEventArgs e)
 {
     int answerId = Convert.ToInt32(e.CommandArgument);
     using (LibrarySystemEntities context = new LibrarySystemEntities())
     {
         Book book = context.Books.FirstOrDefault(x => x.Id == answerId);
         Response.Redirect("SeeBookDetails.aspx?bookId=" +
             book.Id);
     }
 }
Esempio n. 4
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void AllCategories_DeleteItem(int id)
        {
            this.editCategoryConteiner.Visible = false;
            this.createCategoryConteiner.Visible = false;
            this.deleteCategoryConteiner.Visible = true;

            var context = new LibrarySystemEntities();

            var category = context.Categories.Find(id);

            this.NameOfDeleteCategory.Text = "Delete " + category.Title + " category";
            this.DeleteCategoryButton.CommandArgument = category.Id.ToString();
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new LibrarySystemEntities();

            int bookId = int.Parse(Request.Params["bookId"]);

            Book getBook = context.Books.FirstOrDefault(b => b.Id == bookId);

            this.BookTitle.Text = getBook.Title;
            this.BookAuthor.Text = getBook.Author;
            this.BookISBN.Text = getBook.ISBN;
            this.BookWebSite.Text = Server.HtmlEncode(getBook.WebSite);
            this.BookWebSite.NavigateUrl = getBook.WebSite;
            this.BookDescription.Text = getBook.Description;
        }
Esempio n. 6
0
        protected void AllCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.deleteCategoryConteiner.Visible = false;
            this.createCategoryConteiner.Visible = false;
            this.editCategoryConteiner.Visible = true;

            int categoryId = Convert.ToInt32(this.AllCategories.SelectedDataKey.Value);

            var context = new LibrarySystemEntities();

            var category = context.Categories.Find(categoryId);

            this.EditCategoryButton.CommandArgument = category.Id.ToString();
            this.NameOfEditCategory.Text = "Edit " + category.Title + " category";
            this.TexboxForCategoryToEdit.Text = category.Title;
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        protected void AllBooks_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.editBookConteiner.Visible = true;
            this.deleteBookConteiner.Visible = false;
            this.createCategoryConteiner.Visible = false;

            int bookId = Convert.ToInt32(this.AllBooks.SelectedDataKey.Value);

            var context = new LibrarySystemEntities();

            var book = context.Books.Find(bookId);

            this.TexboxForBookTitle.Text = book.Title;
            this.TexboxForBookAuthor.Text = book.Author;
            this.TexboxForBookISBN.Text = book.ISBN;
            this.TexboxForBookDescription.Text = book.Description;
            this.TexboxForBookWebSiet.Text = book.WebSite;

            this.SelectForBookCategory.DataSource = context.Categories.ToList();
            this.SelectForBookCategory.DataBind();
            this.SelectForBookCategory.Items.FindByValue(book.CategoryId.ToString()).Selected = true;

            this.EditBookButton.CommandArgument = book.Id.ToString();
        }
Esempio n. 9
0
        public IEnumerable<WebFormsExam.Models.Category> Category_GetData()
        {
            var context = new LibrarySystemEntities();

            return context.Categories;
        }
Esempio n. 10
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void AllBooks_DeleteItem(int id)
        {
            this.deleteBookConteiner.Visible = true;
            this.editBookConteiner.Visible = false;
            this.createCategoryConteiner.Visible = false;

            var context = new LibrarySystemEntities();

            var book = context.Books.Find(id);

            this.NameOfDeleteBook.Text = "Delete " + book.Title + " book";
            this.DeleteBookButton.CommandArgument = book.Id.ToString();
        }
Esempio n. 11
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<WebFormsExam.Models.Book> AllBooks_GetData()
        {
            var context = new LibrarySystemEntities();

            return context.Books.Include("Category");
        }
Esempio n. 12
0
        protected void CreateABookButton_Command(object sender, CommandEventArgs e)
        {
            var context = new LibrarySystemEntities();

            this.createCategoryConteiner.Visible = true;
            this.deleteBookConteiner.Visible = false;
            this.editBookConteiner.Visible = false;

            this.CreateSelectForBookCategory.DataSource = context.Categories.ToList();
            this.CreateSelectForBookCategory.DataBind();
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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();
        }
Esempio n. 15
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<Category> AllCategories_GetData()
        {
            var context = new LibrarySystemEntities();

            return context.Categories;
        }
Esempio n. 16
0
        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();

        }