public Lesson GetLesson(Lesson lesson)
 {
     Lesson rs = new Lesson();
     using (var db = new SQLiteConnection(this.Path, this.State))
     {
         rs = db.Query<Lesson>("SELECT * FROM Lesson WHERE ID=?", lesson.Id).FirstOrDefault();
     }
     return rs;
 }
        public ObservableCollection<Lesson> GetLessonOfBooks(Lesson lesson)
        {
            using (var db = new SQLiteConnection(this.Path, this.State))
            {
                var r = db.Query<Lesson>("SELECT * FROM Lesson WHERE BOOKID=?", lesson.BookID);
                this.Lessons = new ObservableCollection<Lesson>(r);
            }

            return this.Lessons;
        }
        public int InsertLesson(Lesson lesson)
        {
            int rs = -1;
            using (var db = new SQLiteConnection(this.Path, this.State))
            {
                db.RunInTransaction(() =>
                {
                    rs = db.Insert(lesson);
                });

                this.RaisePropertyChanged("Lessons");
            }

            return rs;
        }
        public int UpdateLesson(Lesson lesson)
        {
            int rs = -1;
            using (var db = new SQLiteConnection(this.Path, this.State))
            {
                var existing = db.Query<Lesson>("SELECT * FROM Lesson WHERE ID=?", lesson.Id).FirstOrDefault();
                if (existing != null)
                {
                    existing = lesson.GetCopy();
                    db.RunInTransaction(() =>
                    {
                        rs = db.Update(existing);
                    });

                    this.RaisePropertyChanged("Lessons");
                }
            }
            return rs;
        }
 private void prepareLesson()
 {
     this.lesson = (Lesson)PhoneApplicationService.Current.State["selectedLesson"];
     this.fens = lesson.Png.Split('\n');
 }