/// <summary> /// Create a new course and add it to the current user's course list /// </summary> /// <returns></returns> public Course CreateCourse(ref ObservableCollection<CourseMeta> crsMeta) { try { //Create the new Course Course newCourse = new Course(); newCourse.Name = "New Course"; newCourse.ID = Guid.NewGuid(); //Add the new course to the current user's course list CoursePermission newCoursePermissions = new CoursePermission(); newCoursePermissions.Course = newCourse; newCoursePermissions.CourseID = newCourse.ID; newCoursePermissions.LbcUser = Session.CurUser; newCoursePermissions.UserID = Session.CurUser.ID; newCoursePermissions.Permission = "Lead Writer"; newCourse.CoursePermissions.Add(newCoursePermissions); //Create the course meta data CourseMeta newCourseMeta = new CourseMeta(); newCourseMeta.CourseID = newCourse.ID; newCourseMeta.Permission = "Lead Writer"; crsMeta.Add(newCourseMeta); //Add the course to the database context and the user's course list that's loaded into the program Session.DbContext.Add(newCourse); return newCourse; } catch { return null; } }
/// <summary> /// Load the user's curriculum /// </summary> /// <param name="user">The user to load curriculum for</param> /// <returns></returns> public ObservableCollection<Course> LoadUserCurriculum(LbcUser user, ref ObservableCollection<CoursePermission> coursePermissions, ref ObservableCollection<CourseMeta> metaData) { ObservableCollection<Course> userCourses = new ObservableCollection<Course>(); List<CoursePermission> userPermissions; metaData = new ObservableCollection<CourseMeta>(); coursePermissions = new ObservableCollection<CoursePermission>(); CourseMeta tmpMeta = new CourseMeta(); try { userPermissions = Session.DbContext.CoursePermissions.Where(cp => cp.LbcUser == user).ToList(); foreach (CoursePermission cp in userPermissions) { tmpMeta = new CourseMeta(); userCourses.Add(cp.Course); coursePermissions.Add(cp); tmpMeta.CourseID = cp.CourseID; tmpMeta.Permission = cp.Permission; metaData.Add(tmpMeta); } return userCourses; } catch { //An error occured while loading the curriculum return null; } finally { //Clean up local variables userCourses = null; userPermissions = null; } }
/// <summary> /// Set CurCourseMeta for the object that matches CurCourse /// </summary> /// <param name="curCourse"></param> public void UpdateCourseMeta(ObservableCollection<CourseMeta> metaData) { CurCourseMeta = metaData.Where(c => c.CourseID == _CurCourse.ID).First(); }