Пример #1
0
 public static List <Book> ListBooksBy()
 {
     using (MyBooks entities = new MyBooks())
     {
         return(entities.Books.ToList <Book>());
     }
 }
Пример #2
0
 public static Book getBookByID(int bookID)
 {
     using (MyBooks entities = new MyBooks())
     {
         return(entities.Books.Where
                    (x => x.BookID == bookID).ToList <Book>()[0]);
     }
 }
Пример #3
0
 public static void DeleteBooks(string title)
 {
     using (MyBooks entities = new MyBooks())
     {
         Book book = entities.Books.Where(z => z.Title == title).First <Book>();
         entities.Books.Remove(book);
         entities.SaveChanges();
     }
 }
Пример #4
0
 protected void AllBooksBtn_Click(object sender, EventArgs e)
 {
     using (MyBooks mb = new MyBooks())
     {
         var q = from x in mb.Books select x;
         DataList1.DataSource = q.ToList();
         DataList1.DataBind();
     }
 }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int bookID = (int)GridView1.SelectedDataKey.Value;

            using (MyBooks entities = new MyBooks())
            {
                Book book = entities.Books.Where(x => x.BookID == bookID).First <Book>();
                DetailsView1.DataSource = new Book[] { book };
                DetailsView1.DataBind();
            }
        }
Пример #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (MyBooks mb = new MyBooks())
         {
             DataList1.DataSource = mb.Books.ToList <Book>();
             DataList1.DataBind();
         }
     }
 }
Пример #7
0
 public static void EditInventory(int bookID, string title, int categoryID, string isbn, string author, int stock, decimal price)
 {
     using (MyBooks entities = new MyBooks())
     {
         Book book = entities.Books.Where(x => x.BookID == bookID).First <Book>();
         book.Title      = title;
         book.CategoryID = categoryID;
         book.ISBN       = isbn;
         book.Author     = author;
         book.Stock      = stock;
         book.Price      = price;
         entities.SaveChanges();
     }
 }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            selectedID = (int)Session["id"];

            if (!IsPostBack)
            {
                ViewState["qty"] = 1;
            }
            //txQty.Controls[0].Dispose();

            qty          = (int)ViewState["qty"];
            context      = new MyBooks();
            selectedBook = context.Books.Where(b => b.BookID.Equals(selectedID)).First();

            cat = new Category();
            cat = context.Categories.Where(c => c.CategoryID.Equals(selectedBook.CategoryID)).First();

            display(selectedBook);

            bookList = (List <Book>)Session["cart"];
        }
Пример #9
0
        protected void SearchBtn_Click(object sender, EventArgs e)
        {
            using (MyBooks mb = new MyBooks())
            {
                if (DetailsDL.Text != null && SearchTxt.Text != null && CategoryDL.SelectedValue != null)
                {
                    switch (DetailsDL.SelectedItem.ToString())
                    {
                    case "Author":

                        catid = mb.Categories.Where(x => x.Name == CategoryDL.SelectedValue).Select(x => x.CategoryID).First();
                        var q = from x in mb.Books where x.Author.Contains(SearchTxt.Text) && x.CategoryID == catid select x;
                        if (q.Count() != 0)
                        {
                            DataList1.DataSource = q.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    case "Title":
                        catid = mb.Categories.Where(x => x.Name == CategoryDL.SelectedValue).Select(x => x.CategoryID).First();
                        var q1 = from x in mb.Books where x.Title.Contains(SearchTxt.Text) && x.CategoryID == catid select x;
                        if (q1.Count() != 0)
                        {
                            DataList1.DataSource = q1.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    case "ISBN":
                        catid = mb.Categories.Where(x => x.Name == CategoryDL.SelectedValue).Select(x => x.CategoryID).First();
                        var q2 = from x in mb.Books where x.ISBN == (SearchTxt.Text) && x.CategoryID == catid select x;
                        if (q2.Count() != 0)
                        {
                            DataList1.DataSource = q2.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    default:
                        Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        break;
                    }
                }
                else if (DetailsDL.SelectedValue != null && SearchTxt.Text == null && CategoryDL.SelectedValue != null)
                {
                    switch (CategoryDL.SelectedItem.ToString())
                    {
                    case "children":
                        catid = mb.Categories.Select(x => x.CategoryID).First();
                        var q1 = from x in mb.Books where x.CategoryID == catid select x;
                        if (q1.Count() != 0)
                        {
                            DataList1.DataSource = q1.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    case "technical":
                        catid = mb.Categories.Select(x => x.CategoryID).First();
                        var q = from x in mb.Books where x.CategoryID == catid select x;
                        if (q.Count() != 0)
                        {
                            DataList1.DataSource = q.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    case "finance":
                        catid = mb.Categories.Select(x => x.CategoryID).First();
                        var q2 = from x in mb.Books where x.CategoryID == catid select x;
                        if (q2.Count() != 0)
                        {
                            DataList1.DataSource = q2.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;

                    case "non-fiction":
                        catid = mb.Categories.Select(x => x.CategoryID).First();
                        var q3 = from x in mb.Books where x.CategoryID == catid select x;
                        if (q3.Count() != 0)
                        {
                            DataList1.DataSource = q3.ToList();
                            DataList1.DataBind();
                        }
                        else
                        {
                            Response.Write("<script>confirm('Record Does Not Exist !!')</script>");
                        }
                        break;
                    }
                }
            }
        }