Ejemplo n.º 1
0
        public void PersistStudent(Child student)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var students = from c in db.Children
                                 where c.Id == student.Id
                                 select c;

                if (students.Count() > 0)
                {
                    db.Children.Attach(student);
                    db.Children.ApplyCurrentValues(student);
                    db.DetectChanges();
                    db.SaveChanges();
                }
                else
                {
                    db.Children.AddObject(student);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        public void PersistActivity(Activity activity)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var activities = from a in db.Activities
                               where a.Id == activity.Id
                               select a;

                if (activities.Count() > 0)
                {
                    db.Activities.Attach(activity);
                    db.Activities.ApplyCurrentValues(activity);
                    db.SaveChanges();
                }
                else
                {

                    db.Activities.AddObject(activity);
                    foreach (var child in activity.Children)
                    {
                        db.ObjectStateManager.ChangeObjectState(child, EntityState.Unchanged);
                    }

                    foreach (var subject in activity.Subjects)
                    {
                        db.ObjectStateManager.ChangeObjectState(subject, EntityState.Unchanged);
                    }

                    foreach (var user in activity.Users)
                    {
                        db.ObjectStateManager.ChangeObjectState(user, EntityState.Unchanged);
                    }

                    db.DetectChanges();
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
        public void PersistLesson(Lesson lesson)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var lessons = from l in db.Lessons
                              where l.Id == lesson.Id
                              select l;

                if (lessons.Count() > 0)
                {
                    db.Lessons.Attach(lesson);
                    db.Lessons.ApplyCurrentValues(lesson);
                    db.SaveChanges();
                }
                else
                {
                    db.Lessons.AddObject(lesson);
                    foreach (var child in lesson.Children)
                    {
                        db.ObjectStateManager.ChangeObjectState(child, EntityState.Unchanged);
                    }

                    foreach (var subject in lesson.Subjects)
                    {
                        db.ObjectStateManager.ChangeObjectState(subject, EntityState.Unchanged);
                    }

                    foreach (var user in lesson.Users)
                    {
                        db.ObjectStateManager.ChangeObjectState(user, EntityState.Unchanged);
                    }

                    db.DetectChanges();
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 4
0
        public void PersistTestScore(TestResult result)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var testscores = from ts in db.TestResults
                                 where ts.Id == result.Id
                                 select ts;

                if (testscores.Count() > 0)
                {
                    db.TestResults.Attach(result);
                    db.TestResults.ApplyCurrentValues(result);
                    db.SaveChanges();
                }
                else
                {
                    db.TestResults.AddObject(result);
                    foreach (var child in result.Children)
                    {
                        db.ObjectStateManager.ChangeObjectState(child, EntityState.Unchanged);
                    }

                    foreach (var test in result.Tests)
                    {
                        db.ObjectStateManager.ChangeObjectState(test, EntityState.Unchanged);
                    }

                    db.DetectChanges();
                    db.SaveChanges();
                }
            }
        }