示例#1
0
 public void CreateSchool(School s)
 {
     using (var db = new HstDBContainer(_connectionString))
     {
         db.Schools.AddObject(s);
         db.SaveChanges();
     }
 }
示例#2
0
文件: UserAccessor.cs 项目: anbro/hst
        public bool AuthorizeTeacher(User u, Child c)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var result = (from child in db.Children
                              where child.Id == c.Id
                              select child).First();

                return result.Users.Contains(u) && u.IsTeacher;
            }
        }
示例#3
0
        public List<Subject> GetAllSubjects()
        {
            var results = new List<Subject>();

            using (var db = new HstDBContainer(_connectionString))
            {
                var subjects = from s in db.Subjects
                               select s;

                foreach (var subject in subjects)
                {
                    results.Add(subject);
                }
            }

            return results;
        }
示例#4
0
        public List<Child> GetChildrenByUser(User user)
        {
            var result = new List<Child>();

            using (var db = new HstDBContainer(_connectionString))
            {
                var children = (from c in db.Children
                               where c.Users.Any(a => a.Login == user.Login)
                               select c).AsEnumerable();

                foreach (var child in children)
                {
                    result.Add(child);
                }
            }

            return result;
        }
示例#5
0
        public List<Child> GetChildrenByIds(List<int> ids)
        {
            var result = new List<Child>();

            using (var db = new HstDBContainer(_connectionString))
            {
                var children = (from c in db.Children
                                where ids.Contains(c.Id)
                                select c).AsEnumerable();

                foreach (var child in children)
                {
                    result.Add(child);
                }
            }

            return result;
        }
示例#6
0
        public List<Subject> GetSubjectsByIds(List<int> ids)
        {
            var results = new List<Subject>();

            using (var db = new HstDBContainer(_connectionString))
            {
                var subjects = (from s in db.Subjects
                                where ids.Contains(s.Id)
                                select s).AsEnumerable();

                foreach (var subject in subjects)
                {
                    results.Add(subject);
                }
            }

            return results;
        }
示例#7
0
        public string GetSchoolName(User u)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var result = from s in db.Schools
                             where s.Users.Contains(u)
                             select s;

                if (result.Count() > 0)
                {
                    return result.First().SchoolName;
                }
                else
                {
                    return string.Empty;
                }
            }
        }
示例#8
0
文件: UserAccessor.cs 项目: anbro/hst
        public User GetUserByLogin(string login)
        {
            var user = new User();
            using (var db = new HstDBContainer(_connectionString))
            {

                var result = (from u in db.Users
                             where u.Login == login
                             select u).AsEnumerable();

                if (result != null)
                {
                    user = result.First();
                    db.LoadProperty(user, "School");
                    //db.Users.Detach(user);
                }
            }

            return user;
        }
示例#9
0
        public void PersistChild(Child child)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var children = from c in db.Children
                            where c.Id == child.Id
                            select c;

                if (children.Count() > 0)
                {
                    db.Children.Attach(child);
                    db.Children.ApplyCurrentValues(child);
                    db.SaveChanges();
                }
                else
                {
                    db.Children.AddObject(child);
                    db.SaveChanges();
                }
            }
        }
示例#10
0
        public void PersistSubject(Subject subject)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var subjects = from s in db.Subjects
                               where s.Id == subject.Id
                               select s;

                if (subjects.Count() > 0)
                {
                    db.Subjects.Attach(subject);
                    db.Subjects.ApplyCurrentValues(subject);
                    db.SaveChanges();
                }
                else
                {
                    db.Subjects.AddObject(subject);
                    db.SaveChanges();
                }
            }
        }
示例#11
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();
                }
            }
        }
示例#12
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();
                }
            }
        }
示例#13
0
文件: UserAccessor.cs 项目: anbro/hst
        public void PersistUser(User u)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var user = from users in db.Users
                            where users.Id == u.Id
                            select users;

                if (user.Count() > 0)
                {
                    db.Users.Attach(u);
                    db.Users.ApplyCurrentValues(u);
                    db.SaveChanges();
                }
                else
                {
                    db.Users.AddObject(u);
                    foreach (var lesson in u.Lessons)
                    {
                        db.ObjectStateManager.ChangeObjectState(lesson, EntityState.Unchanged);
                    }
                    foreach (var activity in u.Activities)
                    {
                        db.ObjectStateManager.ChangeObjectState(activity, EntityState.Unchanged);
                    }
                    foreach (var child in u.Children)
                    {
                        db.ObjectStateManager.ChangeObjectState(child, EntityState.Unchanged);
                    }
                    foreach (var test in u.Tests)
                    {
                        db.ObjectStateManager.ChangeObjectState(test, EntityState.Unchanged);
                    }
                    db.ObjectStateManager.ChangeObjectState(u.School, EntityState.Unchanged);
                    db.SaveChanges();
                }
            }
        }
示例#14
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();
                }
            }
        }
示例#15
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();
                }
            }
        }
示例#16
0
        public void PersistTest(Test test)
        {
            using (var db = new HstDBContainer(_connectionString))
            {
                var tl = from t in db.Tests
                        where t.Id == test.Id
                        select t;

                if (tl.Count() > 0)
                {
                    db.Tests.Attach(test);
                    db.Tests.ApplyCurrentValues(test);
                    db.SaveChanges();
                }
                else
                {
                    db.Tests.AddObject(test);
                    db.ObjectStateManager.ChangeObjectState(test, EntityState.Added);
                    foreach (var result in test.TestResults)
                    {
                        //db.TestResults.Detach(result);
                        db.ObjectStateManager.ChangeObjectState(result, EntityState.Unchanged);

                    }

                    foreach (var subject in test.Subjects)
                    {
                        //db.Subjects.Detach(subject);
                        db.ObjectStateManager.ChangeObjectState(subject, EntityState.Unchanged);

                    }

                    foreach (var user in test.Users)
                    {
                        //db.Users.Detach(user);
                        db.ObjectStateManager.ChangeObjectState(user, EntityState.Unchanged);

                    }

                    //db.DetectChanges();
                    db.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
                }

            }
        }