Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var context = new LibrarySystemEntities())
            {
                int bookId = Convert.ToInt32(this.Request.Params["id"]);
                var book   = context.Books.Find(bookId);

                if (book != null)
                {
                    this.LabelBookTitle.Text = Server.HtmlEncode(book.Title);
                    this.LabelAuthor.Text    = "by " + Server.HtmlEncode(book.Author);

                    if (book.ISBN != null)
                    {
                        this.LabelIsbn.Text = "ISBN " + Server.HtmlEncode(book.ISBN);
                    }

                    if (book.WebSite != null)
                    {
                        this.LabelWebSite.Text        = Server.HtmlEncode(book.WebSite);
                        this.LabelWebSite.NavigateUrl = Server.HtmlEncode(book.WebSite);
                    }

                    this.LabelDescription.Text = Server.HtmlEncode(book.Description);
                }
                else
                {
                    ErrorSuccessNotifier.AddErrorMessage("This book doest not exist anymore");
                    this.Response.Redirect("~/Default.aspx");
                }
            }
        }
Ejemplo n.º 2
0
 protected List <Book> CategoryBooks(int categoryId)
 {
     using (var context = new LibrarySystemEntities())
     {
         var books = context.Books.Where(b => b.CategoryId == categoryId);
         return(books.ToList());
     }
 }
Ejemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (var context = new LibrarySystemEntities())
     {
         var categories = context.Categories.ToList();
         this.ListViewCategories.DataSource = categories;
         this.ListViewCategories.DataBind();
     }
 }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var context = new LibrarySystemEntities())
            {
                string queryString        = this.Request.Params["q"];
                string queryStringToLower = queryString.ToLower();

                if (queryStringToLower == "")
                {
                    this.ListViewBooks.DataSource = context.Books.Include("Category").ToList();
                }
                else
                {
                    var books = context.Books.Include("Category").Where(
                        b => b.Title.ToLower().Contains(queryStringToLower) || b.Author.Contains(queryStringToLower))
                                .OrderBy(b => b.Title).ThenBy(b => b.Author);

                    this.ListViewBooks.DataSource = books.ToList();
                }

                this.LabelSearchQueryHeader.Text = string.Format("Search Results for Query \"{0}\"", Server.HtmlEncode(queryString));
                this.ListViewBooks.DataBind();
            }
        }