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 Course GetCourse(int id) { using (var db = new CourseManagementDbConext()) { return db.Courses.Single(c => c.Id == id); } }
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 Course GetCourse(int id) { using (var db = new CourseManagementDbConext()) { return(db.Courses.Single(c => c.Id == id)); } }
public IEnumerable<Course> GetCourses() { using (var db = new CourseManagementDbConext()) { return db.Courses.Where(c => c.Deleted == false).AsEnumerable(); } }
public IEnumerable <Course> GetCourses() { using (var db = new CourseManagementDbConext()) { return(db.Courses.Where(c => c.Deleted == false).AsEnumerable()); } }
public Node GetNode(int id) { using (var db = new CourseManagementDbConext()) { return(db.Nodes.SingleOrDefault(n => n.Id == 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 IEnumerable<Course> GetCourses(User owner) { using (var db = new CourseManagementDbConext()) { return db.Courses.Where(i => i.Owner == owner.Username && i.Deleted == false); } }
public IEnumerable <Course> GetCourses(User owner) { using (var db = new CourseManagementDbConext()) { return(db.Courses.Where(i => i.Owner == owner.Username && i.Deleted == false)); } }
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 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); } }
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); } }
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; } }
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); } }
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); } }
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 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 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 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 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); } }
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 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; } }
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; } }
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 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 Node GetNode(int id) { using (var db = new CourseManagementDbConext()) { return db.Nodes.SingleOrDefault(n => n.Id == 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 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(); } }