Пример #1
0
        public void UpdateCourseUsers(int courseId, IEnumerable <Guid> userIds)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldUsers = db.CourseUsers.Where(i => i.CourseRef == courseId);

                foreach (var oldUser in oldUsers)
                {
                    db.CourseUsers.Remove(oldUser);
                }

                if (userIds != null)
                {
                    var newUsers = userIds.Select(i => new CourseUser {
                        CourseRef = courseId, UserRef = i
                    });
                    foreach (var newUser in newUsers)
                    {
                        db.CourseUsers.Add(newUser);
                    }
                }

                db.SaveChanges();
            }
        }
Пример #2
0
 public Course GetCourse(int id)
 {
     using (var db = new CourseManagementDbConext())
     {
         return db.Courses.Single(c => c.Id == id);
     }
 }
Пример #3
0
        public int?AddNode(Node node)
        {
            using (var db = new CourseManagementDbConext())
            {
                if (node.Sequencing == null)
                {
                    var sw = new StringWriter();
                    var xs = new XmlSerializer(typeof(Sequencing));
                    xs.Serialize(sw, new Sequencing());
                    node.Sequencing = sw.ToString();
                }

                db.Nodes.Add(node);
                db.SaveChanges();

                if (!node.IsFolder)
                {
                    var template = Path.Combine(GetTemplatesPath(), "iudico.html");

                    File.Copy(template, GetNodePath(node.Id) + ".html", true);
                }

                return(node.Id);
            }
        }
Пример #4
0
 public Course GetCourse(int id)
 {
     using (var db = new CourseManagementDbConext())
     {
         return(db.Courses.Single(c => c.Id == id));
     }
 }
Пример #5
0
 public IEnumerable<Course> GetCourses()
 {
     using (var db = new CourseManagementDbConext())
     {
         return db.Courses.Where(c => c.Deleted == false).AsEnumerable();
     }
 }
Пример #6
0
 public IEnumerable <Course> GetCourses()
 {
     using (var db = new CourseManagementDbConext())
     {
         return(db.Courses.Where(c => c.Deleted == false).AsEnumerable());
     }
 }
Пример #7
0
 public Node GetNode(int id)
 {
     using (var db = new CourseManagementDbConext())
     {
         return(db.Nodes.SingleOrDefault(n => n.Id == id));
     }
 }
Пример #8
0
        public void Parse(int courseId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.Single(c => c.Id == courseId);

                if (!course.Locked.Value)
                {
                    return;
                }

                var coursePath     = GetCoursePath(course.Id);
                var courseTempPath = GetCourseTempPath(course.Id);
                var manifestPath   = Path.Combine(courseTempPath, SCORM.ImsManifset);

                Zipper.ExtractZipFile(coursePath + ".zip", courseTempPath);

                var reader   = new XmlTextReader(new FileStream(manifestPath, FileMode.Open));
                var manifest = Manifest.Deserialize(reader);

                var importer = new Importer(manifest, course, this);

                importer.Import();

                course.Locked = false;

                db.SaveChanges();
            }
        }
Пример #9
0
 public IEnumerable<Course> GetCourses(User owner)
 {
     using (var db = new CourseManagementDbConext())
     {
         return db.Courses.Where(i => i.Owner == owner.Username && i.Deleted == false);
     }
 }
Пример #10
0
 public IEnumerable <Course> GetCourses(User owner)
 {
     using (var db = new CourseManagementDbConext())
     {
         return(db.Courses.Where(i => i.Owner == owner.Username && i.Deleted == false));
     }
 }
Пример #11
0
        public int AddCourse(Course course)
        {
            course.Created = DateTime.Now;
            course.Updated = DateTime.Now;

            using (var db = new CourseManagementDbConext())
            {
                db.Courses.Add(course);
                db.SaveChanges();

                var path = GetCoursePath(course.Id);
                @Directory.CreateDirectory(path);

                var templatePath = GetTemplatesPath();

                foreach (var templateFile in _TemplateFiles)
                {
                    File.Copy(Path.Combine(templatePath, templateFile), Path.Combine(path, templateFile), true);
                }

                _LmsService.Inform(CourseNotifications.CourseCreate, course);

                return(course.Id);
            }
        }
Пример #12
0
        public string GetNodePath(int nodeId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var node = db.Nodes.SingleOrDefault(n => n.Id == nodeId);
                var path = Path.Combine(GetCoursePath(node.CourseId), node.Id.ToString());

                return(path);
            }
        }
Пример #13
0
        public IEnumerable <User> GetCourseUsers(int courseId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var userIds = db.CourseUsers.Where(i => i.CourseRef == courseId);
                var users   = _LmsService.FindService <IUserService>().GetUsersByExpression(i => userIds.Any(j => j.UserRef == i.Id));

                return(users);
            }
        }
Пример #14
0
        public IEnumerable<User> GetCourseUsers(int courseId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var userIds = db.CourseUsers.Where(i => i.CourseRef == courseId);
                var users = _LmsService.FindService<IUserService>().GetUsersByExpression(i => userIds.Any(j => j.UserRef == i.Id));

                return users;
            }
        }
Пример #15
0
 public IEnumerable <Course> GetCourses(Guid userId)
 {
     using (var db = new CourseManagementDbConext())
     {
         return(from c in db.Courses
                join u in db.CourseUsers on c.Id equals u.CourseRef
                where u.UserRef == userId && c.Deleted == false
                select c);
     }
 }
Пример #16
0
 public IEnumerable<Course> GetCourses(Guid userId)
 {
     using (var db = new CourseManagementDbConext())
     {
         return (from c in db.Courses
                     join u in db.CourseUsers on c.Id equals u.CourseRef
                     where u.UserRef == userId && c.Deleted == false
                     select c);
     }
 }
Пример #17
0
        public void DeleteCourseUsers(Guid userId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var courseUsers = db.CourseUsers.Where(i => i.UserRef == userId);

                foreach (var courseUser in courseUsers)
                {
                    db.CourseUsers.Remove(courseUser);
                }
                db.SaveChanges();
            }
        }
Пример #18
0
        public void UpdateNode(int id, Node node)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldNode = db.Nodes.SingleOrDefault(n => n.Id == id);

                oldNode.Name       = node.Name;
                oldNode.ParentId   = node.ParentId;
                oldNode.Position   = node.Position;
                oldNode.Sequencing = node.Sequencing;

                db.SaveChanges();
            }
        }
Пример #19
0
        public void DeleteNode(int id)
        {
            using (var db = new CourseManagementDbConext())
            {
                var node = db.Nodes.SingleOrDefault(n => n.Id == id);

                if (!node.IsFolder)
                {
                    @File.Delete(GetNodePath(id));
                }

                db.Nodes.Remove(node);
                db.SaveChanges();
            }
        }
Пример #20
0
        public void UpdateCourse(int id, Course course)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldCourse = db.Courses.Single(c => c.Id == id);

                oldCourse.Name       = course.Name;
                oldCourse.Updated    = DateTime.Now;
                oldCourse.Sequencing = course.Sequencing;

                db.SaveChanges();

                _LmsService.Inform(CourseNotifications.CourseEdit, course);
            }
        }
Пример #21
0
        public void DeleteCourse(int id)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.Single(c => c.Id == id);

                if (course.Owner != _LmsService.FindService <IUserService>().GetCurrentUser().Username)
                {
                    return;
                }

                course.Deleted = true;

                db.SaveChanges();

                _LmsService.Inform(CourseNotifications.CourseDelete, course);
            }
        }
Пример #22
0
        public IEnumerable <Node> GetNodes(int courseId, int?parentId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.SingleOrDefault(c => c.Id == courseId);
                var nodes  = course.Nodes.OrderBy(n => n.Position).ToList();

                if (parentId == null)
                {
                    nodes = nodes.Where(n => n.ParentId == null).ToList();
                }
                else
                {
                    nodes = nodes.Where(n => n.ParentId == parentId).ToList();
                }

                return(nodes);
            }
        }
Пример #23
0
        public int CreateCopy(Node node, int?parentId, int position)
        {
            using (var db = new CourseManagementDbConext())
            {
                var newnode = new Node
                {
                    CourseId = node.CourseId,
                    Name     = node.Name,
                    ParentId = parentId,
                    IsFolder = node.IsFolder,
                    Position = position
                };

                CopyNodes(node, newnode);

                db.Nodes.Add(newnode);
                db.SaveChanges();

                return(newnode.Id);
            }
        }
Пример #24
0
        public void DeleteCourses(List <int> ids)
        {
            using (var db = new CourseManagementDbConext())
            {
                var courses = (from n in db.Courses where ids.Contains(n.Id) select n);

                foreach (var course in courses)
                {
                    if (course.Owner != _LmsService.FindService <IUserService>().GetCurrentUser().Username)
                    {
                        continue;
                    }

                    course.Deleted = true;

                    _LmsService.Inform(CourseNotifications.CourseDelete, course);
                }

                db.SaveChanges();
            }
        }
Пример #25
0
        public void DeleteNodes(List <int> ids)
        {
            using (var db = new CourseManagementDbConext())
            {
                var nodes = (from n in db.Nodes where ids.Contains(n.Id) select n);

                foreach (var node in nodes)
                {
                    if (!node.IsFolder)
                    {
                        @File.Delete(GetNodePath(node.Id));
                    }
                }

                foreach (var node in nodes)
                {
                    db.Nodes.Remove(node);
                }

                db.SaveChanges();
            }
        }
Пример #26
0
        public IEnumerable<Node> GetNodes(int courseId, int? parentId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.SingleOrDefault(c => c.Id == courseId);
                var nodes = course.Nodes.OrderBy(n => n.Position).ToList();

                if (parentId == null)
                {
                    nodes = nodes.Where(n => n.ParentId == null).ToList();
                }
                else
                {
                    nodes = nodes.Where(n => n.ParentId == parentId).ToList();
                }

                return nodes;
            }
        }
Пример #27
0
        public string GetNodePath(int nodeId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var node = db.Nodes.SingleOrDefault(n => n.Id == nodeId);
                var path = Path.Combine(GetCoursePath(node.CourseId), node.Id.ToString());

                return path;
            }
        }
Пример #28
0
        public int CreateCopy(Node node, int? parentId, int position)
        {
            using (var db = new CourseManagementDbConext())
            {
                var newnode = new Node
                                  {
                                      CourseId = node.CourseId,
                                      Name = node.Name,
                                      ParentId = parentId,
                                      IsFolder = node.IsFolder,
                                      Position = position
                                  };

                CopyNodes(node, newnode);

                db.Nodes.Add(newnode);
                db.SaveChanges();

                return newnode.Id;
            }
        }
Пример #29
0
        public void DeleteNodes(List<int> ids)
        {
            using (var db = new CourseManagementDbConext())
            {
                var nodes = (from n in db.Nodes where ids.Contains(n.Id) select n);

                foreach (var node in nodes)
                {
                    if (!node.IsFolder)
                    {
                        @File.Delete(GetNodePath(node.Id));
                    }
                }

                foreach (var node in nodes)
                {
                    db.Nodes.Remove(node);
                }
                
                db.SaveChanges();
            }
        }
Пример #30
0
        public void DeleteNode(int id)
        {
            using (var db = new CourseManagementDbConext())
            {
                var node = db.Nodes.SingleOrDefault(n => n.Id == id);

                if (!node.IsFolder)
                {
                    @File.Delete(GetNodePath(id));
                }

                db.Nodes.Remove(node);
                db.SaveChanges();
            }
        }
Пример #31
0
        public int AddCourse(Course course)
        {
            course.Created = DateTime.Now;
            course.Updated = DateTime.Now;

            using (var db = new CourseManagementDbConext())
            {

                db.Courses.Add(course);
                db.SaveChanges();

                var path = GetCoursePath(course.Id);
                @Directory.CreateDirectory(path);

                var templatePath = GetTemplatesPath();

                foreach (var templateFile in _TemplateFiles)
                {
                    File.Copy(Path.Combine(templatePath, templateFile), Path.Combine(path, templateFile), true);
                }

                _LmsService.Inform(CourseNotifications.CourseCreate, course);

                return course.Id;
            }
        }
Пример #32
0
        public void UpdateNode(int id, Node node)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldNode = db.Nodes.SingleOrDefault(n => n.Id == id);

                oldNode.Name = node.Name;
                oldNode.ParentId = node.ParentId;
                oldNode.Position = node.Position;
                oldNode.Sequencing = node.Sequencing;

                db.SaveChanges();
            }
        }
Пример #33
0
        public int? AddNode(Node node)
        {
            using (var db = new CourseManagementDbConext())
            {
                if (node.Sequencing == null)
                {
                    var sw = new StringWriter();
                    var xs = new XmlSerializer(typeof(Sequencing));
                    xs.Serialize(sw, new Sequencing());
                    node.Sequencing = sw.ToString();
                }

                db.Nodes.Add(node);
                db.SaveChanges();

                if (!node.IsFolder)
                {
                    var template = Path.Combine(GetTemplatesPath(), "iudico.html");

                    File.Copy(template, GetNodePath(node.Id) + ".html", true);
                }

                return node.Id;
            }
        }
Пример #34
0
 public Node GetNode(int id)
 {
     using (var db = new CourseManagementDbConext())
     {
         return db.Nodes.SingleOrDefault(n => n.Id == id);
     }
 }
Пример #35
0
        public void UpdateCourse(int id, Course course)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldCourse = db.Courses.Single(c => c.Id == id);

                oldCourse.Name = course.Name;
                oldCourse.Updated = DateTime.Now;
                oldCourse.Sequencing = course.Sequencing;

                db.SaveChanges();

                _LmsService.Inform(CourseNotifications.CourseEdit, course);
            }
        }
Пример #36
0
        public void Parse(int courseId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.Single(c => c.Id == courseId);

                if (!course.Locked.Value)
                {
                    return;
                }

                var coursePath = GetCoursePath(course.Id);
                var courseTempPath = GetCourseTempPath(course.Id);
                var manifestPath = Path.Combine(courseTempPath, SCORM.ImsManifset);

                Zipper.ExtractZipFile(coursePath + ".zip", courseTempPath);

                var reader = new XmlTextReader(new FileStream(manifestPath, FileMode.Open));
                var manifest = Manifest.Deserialize(reader);

                var importer = new Importer(manifest, course, this);

                importer.Import();

                course.Locked = false;

                db.SaveChanges();
            }
        }
Пример #37
0
        public void DeleteCourses(List<int> ids)
        {
            using (var db = new CourseManagementDbConext())
            {
                var courses = (from n in db.Courses where ids.Contains(n.Id) select n);

                foreach (var course in courses)
                {
                    if (course.Owner != _LmsService.FindService<IUserService>().GetCurrentUser().Username)
                    {
                        continue;
                    }

                    course.Deleted = true;

                    _LmsService.Inform(CourseNotifications.CourseDelete, course);
                }

                db.SaveChanges();
            }
        }
Пример #38
0
        public void DeleteCourse(int id)
        {
            using (var db = new CourseManagementDbConext())
            {
                var course = db.Courses.Single(c => c.Id == id);

                if (course.Owner != _LmsService.FindService<IUserService>().GetCurrentUser().Username)
                {
                    return;
                }

                course.Deleted = true;

                db.SaveChanges();

                _LmsService.Inform(CourseNotifications.CourseDelete, course);
            }
        }
Пример #39
0
        public void UpdateCourseUsers(int courseId, IEnumerable<Guid> userIds)
        {
            using (var db = new CourseManagementDbConext())
            {
                var oldUsers = db.CourseUsers.Where(i => i.CourseRef == courseId);

                foreach (var oldUser in oldUsers)
                {
                    db.CourseUsers.Remove(oldUser);
                }

                if (userIds != null)
                {
                    var newUsers = userIds.Select(i => new CourseUser { CourseRef = courseId, UserRef = i });
                    foreach (var newUser in newUsers)
                    {
                        db.CourseUsers.Add(newUser);
                    }
                }

                db.SaveChanges();
            }
        }
Пример #40
0
        public void DeleteCourseUsers(Guid userId)
        {
            using (var db = new CourseManagementDbConext())
            {
                var courseUsers = db.CourseUsers.Where(i => i.UserRef == userId);

                foreach (var courseUser in courseUsers)
                {
                    db.CourseUsers.Remove(courseUser);
                }
                db.SaveChanges();
            }
        }