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); } }
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(); } }
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); } }
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(); } }
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(); } }
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(); } }
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); } }
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(); } }
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); } }
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); } }
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(); } }
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(); } }
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; } }
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(); } }
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); } }
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; } }
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(); } }
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; } }
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(); } }