コード例 #1
0
        private static void ImportClozes(Lesson importLesson)
        {
            Lesson dbLesson = database.lessons.FirstOrDefault(x => x.id == importLesson.id);

            //lesson exists, so update it
            if (dbLesson != null)
            {
                //update lesson properties
                dbLesson.Fill(importLesson);

                //first find out wich clozes to delete
                List <Cloze> clozesToDelete = new List <Cloze>();

                foreach (Cloze dbCloze in dbLesson.Clozes)
                {
                    //to do so, find all clozes in the database that are no longer in the new imported lesson
                    Cloze cloze = importLesson.Clozes.FirstOrDefault(x => x.id == dbCloze.id);

                    //if the cloze can't be found in the importLesson, than delete it
                    if (cloze == null)
                    {
                        clozesToDelete.Add(dbCloze);
                    }
                    else //if its still in the list, than update the cloze
                    {
                        dbCloze.Fill(cloze);
                    }
                }

                //than go through all clozes from import lesson
                foreach (Cloze cloze in importLesson.Clozes)
                {
                    //and find all clozes that are not in the database
                    Cloze dbCloze = dbLesson.Clozes.FirstOrDefault(x => x.id == cloze.id);

                    //if the cloze isn't in the database than insert it new
                    if (dbCloze == null)
                    {
                        cloze.Lesson = dbLesson;
                        dbLesson.Clozes.Add(cloze);

                        database.clozes.InsertOnSubmit(cloze);
                    }
                }

                database.clozes.DeleteAllOnSubmit(clozesToDelete);
            }
            else //lesson does not exists, so just insert it
            {
                database.clozes.InsertAllOnSubmit(importLesson.Clozes);
                database.lessons.InsertOnSubmit(importLesson);
            }
        }
コード例 #2
0
 public Cloze(Cloze other)
 {
     Fill(other);
 }
コード例 #3
0
 public void Fill(Cloze other)
 {
     text    = other.text;
     inserts = other.inserts;
     hints   = other.hints;
 }