protected void DeleteButton_Click(object sender, EventArgs e)
        {
            this.AddBook.Visible = false;

            this.PanelTitle.Text   = "Confirm Delete Category";
            this.BookPanel.Visible = true;
            Button button = sender as Button;
            int    id     = Convert.ToInt32(button.CommandArgument);

            using (var dbContext = new BooksReviewContext())
            {
                var book = dbContext.Books.Find(id);
                this.TitleTextBox.Text                = book.Title;
                this.TitleTextBox.ReadOnly            = true;
                this.AuthorLabel.Visible              = false;
                this.AuthorTextBox.Visible            = false;
                this.ISBN.Visible                     = false;
                this.ISBNTextBox.Visible              = false;
                this.UrlLabel.Visible                 = false;
                this.UrlTextBox.Visible               = false;
                this.DescrLabel.Visible               = false;
                this.DescrTextBox.Visible             = false;
                this.CategoryLabel.Visible            = false;
                this.CategoryDropDownList.Visible     = false;
                this.EditOrCreateBook.Text            = "Delete";
                this.EditOrCreateBook.CommandArgument = id.ToString();
                this.EditOrCreateBook.CommandName     = "delete";
            }
        }
        protected void EditButton_Click(object sender, EventArgs e)
        {
            this.BookPanel.Visible = true;
            Button button     = sender as Button;
            int    id         = Convert.ToInt32(button.CommandArgument);
            var    dbContext  = new BooksReviewContext();
            var    book       = dbContext.Books.Find(id);
            var    categories = dbContext.Categories.ToList();

            this.AddBook.Visible    = false;
            this.PanelTitle.Text    = "Edit Book";
            this.TitleTextBox.Text  = book.Title;
            this.AuthorTextBox.Text = book.Author;
            this.ISBNTextBox.Text   = book.ISBN;
            this.UrlTextBox.Text    = book.SiteURL;
            this.DescrTextBox.Text  = book.Description;
            this.CategoryDropDownList.DataSource = categories;
            this.CategoryDropDownList.DataBind();
            int indexSel = 0;

            for (int i = 0; i < categories.Count; i++)
            {
                if (categories[i].Id == book.CategoryId)
                {
                    indexSel = i;
                    break;
                }
            }
            this.CategoryDropDownList.SelectedIndex = indexSel;
            this.EditOrCreateBook.Text            = "Edit";
            this.EditOrCreateBook.CommandName     = "edit";
            this.EditOrCreateBook.CommandArgument = id.ToString();
        }
Beispiel #3
0
        public IQueryable <Category> GridViewCategories_GetData()
        {
            IQueryable <Category> cateories = null;
            var dbContext = new BooksReviewContext();

            cateories = dbContext.Categories.AsQueryable <Category>();
            return(cateories);
        }
        public IQueryable <BookReviews.Models.Book> GridViewBooks_GetData()
        {
            IQueryable <Book> books = null;
            var dbContext           = new BooksReviewContext();

            books = dbContext.Books.Include("Category").AsQueryable <Book>();
            return(books);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var    dbContext = new BooksReviewContext();
            string searchStr = Request.QueryString["str"];
            var    books     = dbContext.Books.Where(b => (b.Author.Contains(searchStr) || b.Author.Contains(searchStr))).ToList();

            this.RepeaterSearchResult.DataSource = books;
            this.RepeaterSearchResult.DataBind();
        }
        public IQueryable <Category> BookListGetData()
        {
            var dbContext = new BooksReviewContext();
            IQueryable <Category> categories = null;

            categories = dbContext.Categories.AsQueryable <Category>();

            return(categories);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (var dbContext = new BooksReviewContext())
            {
                var book = dbContext.Books;
                this.DetailsFormView.DataSource = book.Where(x => x.Id == id).ToList();
                this.DetailsFormView.DataBind();
            }
        }
Beispiel #8
0
        protected void EditButton_Click(object sender, EventArgs e)
        {
            this.PanelTitle.Text     = "Edit Category";
            this.AddCategory.Visible = false;
            this.EditOrCreateCategotyPanel.Visible = true;
            Button button = sender as Button;
            int    id     = Convert.ToInt32(button.CommandArgument);

            using (var dbContext = new BooksReviewContext())
            {
                var category = dbContext.Categories.Find(id);
                this.EditOrCreateCategotyTextBox.Text           = category.Name;
                this.EditOrCreateCategotyButton.Text            = "Edit";
                this.EditOrCreateCategotyButton.CommandArgument = id.ToString();
                this.EditOrCreateCategotyButton.CommandName     = "edit";
            }
        }
        protected void AddBook_Click(object sender, EventArgs e)
        {
            this.BookPanel.Visible = true;
            var dbContext  = new BooksReviewContext();
            var categories = dbContext.Categories.ToList();

            this.AddBook.Visible    = false;
            this.PanelTitle.Text    = "Add Book";
            this.TitleTextBox.Text  = string.Empty;
            this.AuthorTextBox.Text = string.Empty;
            this.ISBNTextBox.Text   = string.Empty;
            this.UrlTextBox.Text    = string.Empty;
            this.DescrTextBox.Text  = string.Empty;
            this.CategoryDropDownList.DataSource = categories;
            this.CategoryDropDownList.DataBind();
            this.EditOrCreateBook.Text        = "Add";
            this.EditOrCreateBook.CommandName = "add";
        }
Beispiel #10
0
        protected void EditOrCreateCategotyButton_Click(object sender, EventArgs e)
        {
            var    dbContext    = new BooksReviewContext();
            string categoryName = this.EditOrCreateCategotyTextBox.Text;
            Button button       = sender as Button;

            if (button.CommandName == "edit")
            {
                int id       = Convert.ToInt32(button.CommandArgument);
                var category = dbContext.Categories.Find(id);
                category.Name = categoryName;
            }
            else if (button.CommandName == "delete")
            {
                int id       = Convert.ToInt32(button.CommandArgument);
                var category = dbContext.Categories.Find(id);
                var books    = category.Books.ToList();
                dbContext.Books.RemoveRange(books);
                dbContext.Categories.Remove(category);
            }
            else
            {
                var category = new Category {
                    Name = categoryName
                };
                dbContext.Categories.Add(category);
            }

            try
            {
                dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                this.ErrorLabel.Text = ex.Message;
            }
            this.GridViewCategories.DataBind();
            this.EditOrCreateCategotyPanel.Visible = false;
        }
        protected void EditOrCreateBook_Click(object sender, EventArgs e)
        {
            var dbContext = new BooksReviewContext();

            Button button = sender as Button;

            if (button.CommandName == "edit")
            {
                int id   = Convert.ToInt32(button.CommandArgument);
                var book = dbContext.Books.Find(id);
                book.Title       = this.TitleTextBox.Text = book.Title;
                book.Author      = this.AuthorTextBox.Text;
                book.ISBN        = this.ISBNTextBox.Text;
                book.SiteURL     = this.UrlTextBox.Text;
                book.Description = this.DescrTextBox.Text;
                book.CategoryId  = Convert.ToInt32(this.CategoryDropDownList.SelectedValue);
            }
            else if (button.CommandName == "delete")
            {
                int id   = Convert.ToInt32(button.CommandArgument);
                var book = dbContext.Books.Find(id);
                dbContext.Books.Remove(book);
            }
            else
            {
                var book = new Book();
                book.Title       = this.TitleTextBox.Text;
                book.Author      = this.AuthorTextBox.Text;
                book.ISBN        = this.ISBNTextBox.Text;
                book.SiteURL     = this.UrlTextBox.Text;
                book.Description = this.DescrTextBox.Text;
                book.CategoryId  = Convert.ToInt32(this.CategoryDropDownList.SelectedValue);
                dbContext.Books.Add(book);
            }
            dbContext.SaveChanges();
            this.GridViewBooks.DataBind();
            this.BookPanel.Visible = false;
        }