Exemple #1
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);
            }
        }
Exemple #2
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();
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
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();
            }
        }
Exemple #5
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();
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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();
            }
        }
Exemple #9
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);
            }
        }
Exemple #10
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);
            }
        }
Exemple #11
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();
            }
        }
Exemple #12
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();
            }
        }
Exemple #13
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();
            }
        }
Exemple #14
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;
            }
        }
Exemple #15
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();
            }
        }
Exemple #16
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();
            }
        }
Exemple #17
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);
            }
        }
Exemple #18
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);
            }
        }
Exemple #19
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;
            }
        }
Exemple #20
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();
            }
        }
Exemple #21
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();
            }
        }
Exemple #22
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;
            }
        }
Exemple #23
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();
            }
        }
Exemple #24
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();
            }
        }