private void BookMarkList_ItemTap(object sender, ListBoxItemTapEventArgs e)
        {
            BookMark bookMark = ((sender as RadDataBoundListBox).SelectedItem as BookMark);

            if (bookMark != null)
            {
                App.ViewModel.LoadChapterRec(bookMark.chapter_id);
                NavigationService.Navigate(new Uri("/Views/Verses.xaml?chapterId=" + bookMark.chapter_id.ToString() + "&verseId=" + bookMark.verse_id.ToString() + "&chapterName=" + App.ViewModel.ChapterRec.tr_name.ToString() + "&type=" + App.ViewModel.ChapterRec.type + "&enName=" + App.ViewModel.ChapterRec.en_name, UriKind.Relative));
            }
        }
        private void MenuItemBookmark_Click(object sender, RoutedEventArgs e)
        {
            string header = (sender as MenuItem).Header.ToString();

            ListBoxItem selectedListBoxItem = this.BookMarkList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }

            BookMark data = selectedListBoxItem.DataContext as BookMark;

            if (header == "Refresh")
            {
                //App.ViewModel.LoadBookMarks();
                //BookMarkList.ItemsSource = App.ViewModel.BookMarks;
                //BookMarkList.DataContext = App.ViewModel;
            }
            else if (header == "Delete")
            {
                int result = (Application.Current as App).db.DeleteBookMark(data.id);

                if (result == 0)
                {
                    //MessageBox.Show("Delete BookMark Failed.");
                }
                else if (result == 2)
                {
                    //MessageBox.Show("Cannot Delete ReadPoint.");
                }
                else
                {
                    //MessageBox.Show("Delete BookMark Success.");
                }
            }
            else if (header == "Delete all")
            {
                /*
                 * if ((Application.Current as App).db.clearBookmarks() > 0)
                 * {
                 *  vm.GetBookmarks();
                 *  BookmarkListBox.DataContext = vm.Bookmarks;
                 *  MessageBox.Show("All Bookmarks deleted");
                 * }
                 */
            }

            App.ViewModel.LoadBookMarks();
            BookMarkList.ItemsSource = App.ViewModel.BookMarks;
            BookMarkList.DataContext = App.ViewModel;

            BookMarkList.SelectedIndex = -1;
            //To highlight the tapped item just use something like selectedListBoxItem.Background = new SolidColorBrush(Colors.Green);
        }
        public int SetLastRead(int chapterNo, int verseNo)
        {
            int status     = 0;
            int positionId = -2;

            try
            {
                //checkPoint

                IQueryable <BookMark> bookMarkQuery = from bookMark in (Application.Current as App).db.BookMarks
                                                      where bookMark.position_id == positionId
                                                      select bookMark;

                //if exist update else create
                if (bookMarkQuery.Any())
                {
                    BookMark bookMarkUpdate = bookMarkQuery.Single();

                    bookMarkUpdate.name          = "Last Read";
                    bookMarkUpdate.chapter_id    = chapterNo;
                    bookMarkUpdate.verse_id      = verseNo;
                    bookMarkUpdate.position_id   = positionId;
                    bookMarkUpdate.date_modified = DateTime.Now;

                    (Application.Current as App).db.SubmitChanges();
                }
                else
                {
                    BookMark bookMarkNew = new BookMark
                    {
                        name          = "Last Read",
                        chapter_id    = chapterNo,
                        verse_id      = verseNo,
                        position_id   = positionId,
                        is_deleted    = 0,
                        date_created  = DateTime.Now,
                        date_modified = DateTime.Now,
                    };

                    (Application.Current as App).db.BookMarks.InsertOnSubmit(bookMarkNew);

                    (Application.Current as App).db.SubmitChanges();
                }

                status = 1;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
            return(status);
        }
        private void BookmarkList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BookMarkList.SelectedIndex == -1)
            {
                return;
            }

            BookMark bookMark = ((BookMark)BookMarkList.SelectedItem);

            if (bookMark != null)
            {
                App.ViewModel.LoadChapterRec(bookMark.chapter_id);
                NavigationService.Navigate(new Uri("/Views/Verses.xaml?chapterId=" + bookMark.chapter_id.ToString() + "&verseId=" + bookMark.verse_id.ToString() + "&chapterName=" + App.ViewModel.ChapterRec.tr_name.ToString() + "&type=" + App.ViewModel.ChapterRec.type + "&enName=" + App.ViewModel.ChapterRec.en_name, UriKind.Relative));
            }
        }
        public int DeleteBookMark(int bookMarkId)
        {
            int status = 0;

            try
            {
                IQueryable <BookMark> bookMarkQuery = from bookMark in (Application.Current as App).db.BookMarks
                                                      where bookMark.id == bookMarkId
                                                      select bookMark;

                //if checkpoint else as a bookmark
                if (bookMarkQuery.Any())
                {
                    BookMark bookMarkUpdate = bookMarkQuery.Single();

                    if (bookMarkUpdate.position_id == -1)
                    {
                        //checkpoint
                        status = 2;
                    }
                    else
                    {
                        bookMarkUpdate.is_deleted    = 1;
                        bookMarkUpdate.date_modified = DateTime.Now;

                        (Application.Current as App).db.SubmitChanges();

                        status = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
            return(status);
        }
        public void Execute(object parameter)
        {
            RadDataBoundListBox listBox = ElementTreeHelper.FindVisualAncestor <RadDataBoundListBox>(parameter as DependencyObject);
            RadContextMenu      menu    = RadContextMenu.GetContextMenu(listBox);

            RadDataBoundListBoxItem item = ElementTreeHelper.FindVisualAncestor <RadDataBoundListBoxItem>(parameter as DependencyObject);

            int    chapterNo = 0;
            int    verseNo   = 0;
            string quranText = "";
            string verseText = "";

            if (item.Content is Verse)
            {
                Verse verse = (item.Content as Verse);

                int result = (Application.Current as App).db.SetLastRead(verse.chapter_id, verse.verse_id);

                if (result == 0)
                {
                    MessageBox.Show("Last Read upadate Failed.");
                }
                else
                {
                    //MessageBox.Show("Last Read Saved.");
                }
            }

            if (menu.Name == "menuVerse")
            {
                Verse verse = (item.Content as Verse);

                chapterNo = verse.chapter_id;
                verseNo   = verse.verse_id;
                quranText = verse.AyahText;
                verseText = verse.verse_text;
            }
            else if (menu.Name == "menuVerseCompare")
            {
                VerseCompare verse = (item.Content as VerseCompare);

                chapterNo = verse.SuraID;
                verseNo   = verse.VerseID;
                //quranText = verse.AyahText;
                verseText = verse.AyahText;
            }
            else if (menu.Name == "menuIndexItem")
            {
                IndexItem verse = (item.Content as IndexItem);

                chapterNo = verse.chapter_id;
                verseNo   = verse.verse_id;
                quranText = verse.AyahText;
                verseText = verse.VerseText;
            }
            else if (menu.Name == "menuTopicItem")
            {
                TopicItem verse = (item.Content as TopicItem);

                chapterNo = verse.chapter_id;
                verseNo   = verse.verse_id;
                quranText = verse.AyahText;
                verseText = verse.VerseText;
            }
            else if (menu.Name == "menuBookMark")
            {
            }
            else if (menu.Name == "menuSearchTerm")
            {
            }
            else
            {
                Verse verse = (item.Content as Verse);

                chapterNo = verse.chapter_id;
                verseNo   = verse.verse_id;
                quranText = verse.AyahText;
                verseText = verse.verse_text;
            }

            if (this.Name == "CopyCompleteCommand")
            {
                string shareTextArabTrans = quranText + " | '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                //string shareTextTrans = "'"+verseText+"' (" + chapterNo + ":" + verseNo + ")";

                Clipboard.SetText(shareTextArabTrans);
                //MessageBox.Show("Copied to Clipboard: " + shareTextArabTrans);
            }
            else if (this.Name == "CopyCommand")
            {
                //string shareTextArabTrans = quranText + "  '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                string shareTextTrans = "'" + verseText + "' (" + chapterNo + ":" + verseNo + ")";

                Clipboard.SetText(shareTextTrans);
                //MessageBox.Show("Copied to Clipboard: " + shareTextTrans);
            }
            else if (this.Name == "ShareCommand")
            {
                //string shareTextArabTrans = quranText + "  '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                string shareTextTrans = "'" + verseText + "' (" + chapterNo + ":" + verseNo + ")";

                ShareStatusTask shareStatusTask = new ShareStatusTask();
                shareStatusTask.Status = shareTextTrans;
                shareStatusTask.Show();
            }
            else if (this.Name == "TweetCommand")
            {
                //string shareTextArabTrans = quranText + "  '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                string shareTextTrans = "'" + verseText + "' (" + chapterNo + ":" + verseNo + ")";

                //http://web.quran360.com/site/verse/tr/26/ch/1/v/1

                shareTextTrans = shareTextTrans.Substring(0, 90);
                shareTextTrans = shareTextTrans + "... (cont) http://web.quran360.com/site/verse/tr/" + AppSettings.TransSetting + "/ch/" + chapterNo + "/v/" + verseNo;

                ShareStatusTask shareStatusTask = new ShareStatusTask();
                shareStatusTask.Status = shareTextTrans;
                shareStatusTask.Show();
            }
            else if (this.Name == "EmailCommand")
            {
                string shareSubject = "Quran360 Share | Quran (" + chapterNo + ":" + verseNo + ")";

                string shareTextArabTrans = quranText + "  '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                //string shareTextTrans = "'" + verseText + "' (" + chapterNo + ":" + verseNo + ")";

                Microsoft.Phone.Tasks.EmailComposeTask email = new Microsoft.Phone.Tasks.EmailComposeTask();
                email.Subject = shareSubject;
                email.Body    = shareTextArabTrans;
                email.Show();
            }
            else if (this.Name == "SmsCommand")
            {
                string shareSubject = "Read Quran: (" + chapterNo + ":" + verseNo + ")";

                //string shareTextArabTrans = quranText + "  '" + verseText + "' (" + chapterNo + ":" + verseNo + ")";
                string shareTextTrans = "'" + verseText + "' (" + chapterNo + ":" + verseNo + ")";

                Microsoft.Phone.Tasks.SmsComposeTask sms = new Microsoft.Phone.Tasks.SmsComposeTask();
                sms.Body = shareTextTrans;
                sms.Show();
            }
            else if (this.Name == "SetCheckPointCommand")
            {
                try
                {
                    //int chapterNo = (item.Content as Verse).chapter_id;
                    //int verseNo = (item.Content as Verse).verse_id;
                    int result = (Application.Current as App).db.SetBookMark(chapterNo, verseNo, -1);

                    if (result == 0)
                    {
                        MessageBox.Show("ReadPoint Failed.");
                    }
                    else
                    {
                        //MessageBox.Show("ReadPoint Saved.");
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("SetCheckPointCommand failed: " + ex.StackTrace);
                }
            }
            else if (this.Name == "SetBookmarkCommand")
            {
                try
                {
                    //int chapterNo = (item.Content as Verse).chapter_id;
                    //int verseNo = (item.Content as Verse).verse_id;
                    int result = (Application.Current as App).db.SetBookMark(chapterNo, verseNo, (verseNo - 1));

                    if (result == 0)
                    {
                        MessageBox.Show("BookMark Failed.");
                    }
                    else
                    {
                        //MessageBox.Show("BookMark Saved.");
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("SetBookmarkCommand failed: " + ex.StackTrace);
                }
            }
            else if (this.Name == "PlayCommand")
            {
                Verse verse = (item.Content as Verse);

                String url = "http://web.quran360.com/audio/v_saad_al_ghaamidi/00" + verse.chapter_id + "/00" + verse.chapter_id + "00" + verse.verse_id + ".mp3";
            }
            else if (this.Name == "PauseCommand")
            {
            }
            else if (this.Name == "StopCommand")
            {
            }
            else if (this.Name == "DeleteBookMarkCommand")
            {
                BookMark bookMark = (item.Content as BookMark);
                int      result   = (Application.Current as App).db.DeleteBookMark(bookMark.id);

                if (result == 0)
                {
                    MessageBox.Show("Delete BookMark Failed.");
                }
                else if (result == 2)
                {
                    MessageBox.Show("Cannot Delete ReadPoint.");
                }
                else
                {
                    //MessageBox.Show("Delete BookMark Success.");
                }
            }
            else if (this.Name == "DeleteSearchTermCommand")
            {
                SearchTerm searchTerm = (item.Content as SearchTerm);
                int        result     = (Application.Current as App).db.DeleteSearchTerm(searchTerm.id);

                if (result == 0)
                {
                    MessageBox.Show("Delete Search Failed.");
                }
                else
                {
                    //MessageBox.Show("Delete Search Success.");
                }
            }
            //this.ScheduleNotification(menu, item);
        }
        public int SetLastRead(int chapterNo, int verseNo)
        {
            int status = 0;
            int positionId = -2;
            try
            {
                //checkPoint

                IQueryable<BookMark> bookMarkQuery = from bookMark in (Application.Current as App).db.BookMarks
                                                     where bookMark.position_id == positionId
                                                     select bookMark;

                //if exist update else create
                if (bookMarkQuery.Any())
                {
                    BookMark bookMarkUpdate = bookMarkQuery.Single();

                    bookMarkUpdate.name = "Last Read";
                    bookMarkUpdate.chapter_id = chapterNo;
                    bookMarkUpdate.verse_id = verseNo;
                    bookMarkUpdate.position_id = positionId;
                    bookMarkUpdate.date_modified = DateTime.Now;

                    (Application.Current as App).db.SubmitChanges();

                }
                else
                {
                    BookMark bookMarkNew = new BookMark
                    {
                        name = "Last Read",
                        chapter_id = chapterNo,
                        verse_id = verseNo,
                        position_id = positionId,
                        is_deleted = 0,
                        date_created = DateTime.Now,
                        date_modified = DateTime.Now,
                    };

                    (Application.Current as App).db.BookMarks.InsertOnSubmit(bookMarkNew);

                    (Application.Current as App).db.SubmitChanges();
                }

                status = 1;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
            return status;
        }