Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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();
                }
            }
        }