void confirm_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtName.Text))
     {
         MessageBox.Show("Name of the book is required");
         txtName.Focus();
     }
     else if (String.IsNullOrEmpty(txtAuthor.Text))
     {
         MessageBox.Show("Name of the Author is required");
         txtAuthor.Focus();
     }
     else
     {
         using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
         {
             try
             {
                 //Add the details to the Tables
                 TblBooks st = new TblBooks()
                 {
                     name = txtName.Text, author = txtAuthor.Text, description = txtDesc.Text, version = txtVersion.Text
                 };
                 context.TblBooks.InsertOnSubmit(st);
                 context.SubmitChanges();
                 MessageBox.Show("Book has been Added Successfully");
             }
             catch (Exception)
             {
                 MessageBox.Show("Unable to add book");
             }
         }
     }
 }
Beispiel #2
0
        protected override void OnTap(System.Windows.Input.GestureEventArgs e)
        {
            //enable onTap on the list items
            TblBooks tb = (TblBooks)bookList.SelectedItem;

            if (bookList.SelectedIndex != -1)
            {
                NavigationService.Navigate(new Uri("/ViewBook.xaml?id=" + tb.id, UriKind.RelativeOrAbsolute));
            }
        }
 //delete book by id
 public void DeleteUser(String id)
 {
     using (BooksDatacontext context = new BooksDatacontext(App.booksconnectionString))
     {
         IQueryable <TblBooks> entityQuery = from c in context.TblBooks where c.id.Equals(id) select c;
         TblBooks entityToDelete           = entityQuery.FirstOrDefault();
         context.TblBooks.DeleteOnSubmit(entityToDelete);
         context.SubmitChanges();
     }
 }