public void AddBook(Book newBook)
 {
     try
     {
         BookDataContext bookData = new BookDataContext();
         bookData.Books.InsertOnSubmit(newBook);
         bookData.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Error:" + ex.Message);
     }
 }
 public void DeleteBook(Book deletebook)
 {
     try
     {
         BookDataContext bookData = new BookDataContext();
         Book            book     = bookData.Books.SingleOrDefault(b => b.BookID.Equals(deletebook.BookID));
         bookData.Books.DeleteOnSubmit(book);
         bookData.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Error: " + ex.Message);
     }
 }
 public void Update(Book updateBook)
 {
     try
     {
         BookDataContext bookData = new BookDataContext();
         Book            book     = bookData.Books.SingleOrDefault(b => b.BookID.Equals(updateBook.BookID));
         book.BookPrice = updateBook.BookPrice;
         book.BookTitle = updateBook.BookTitle;
         bookData.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Error " + ex.Message);
     }
 }
 public List <Book> SearchBook(Book bookInfo)
 {
     try
     {
         BookDataContext bookData = new BookDataContext();
         var             result   = from b in bookData.Books
                                    where b.BookID.Equals(bookInfo.BookID)
                                    orderby b.BookPrice descending
                                    select b;
         return(result.ToList());
     }
     catch (Exception ex)
     {
         throw new Exception("Error: " + ex.Message);
     }
 }
        public List <Book> GetBookList()
        {
            BookDataContext bookData = new BookDataContext();

            return(bookData.Books.ToList());
        }