public static CourseProgressData Update( this CourseProgressData courseProgressData, int lessonId, int stepId, int questionId, QuestionStateData questionStateData) { if (courseProgressData == null) { throw new ArgumentNullException(nameof(courseProgressData)); } if (questionStateData == null) { throw new ArgumentNullException(nameof(questionStateData)); } var lessonProgress = courseProgressData.LessonProgresses[lessonId]; var stepProgress = lessonProgress.StepProgresses[stepId]; var questionStates = stepProgress.QuestionStates; courseProgressData.StatisticsData.PassedQuestionsCount += GetDelta(questionStates[questionId], questionStateData); questionStates[questionId] = questionStateData; stepProgress.Passed = stepProgress.QuestionStates.TrueForAll(x => x.Passed); lessonProgress.Passed = lessonProgress.StepProgresses.TrueForAll(x => x.Passed); courseProgressData.Passed = courseProgressData.LessonProgresses.TrueForAll(x => x.Passed); return(courseProgressData); }
public static CourseProgressData SetUpLinks(this CourseProgressData courseProgressData) { if (courseProgressData == null) { throw new ArgumentNullException(nameof(courseProgressData)); } foreach (var lessonProgress in courseProgressData.LessonProgresses) { lessonProgress.ProgressId = courseProgressData.Id; lessonProgress.CourseId = courseProgressData.CourceId; foreach (var stepProgress in lessonProgress.StepProgresses) { stepProgress.ProgressId = courseProgressData.Id; stepProgress.CourseId = courseProgressData.CourceId; stepProgress.LessonId = lessonProgress.LessonId; foreach (var questionState in stepProgress.QuestionStates) { questionState.ProgressId = courseProgressData.Id; questionState.CourseId = courseProgressData.CourceId; questionState.LessonId = lessonProgress.LessonId; questionState.StepId = stepProgress.Id; } } } return(courseProgressData); }
public void Init() { courseData = Utilits.CreateCourse(); courseData.SetUpLinks(); userId = "1"; user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, userId) })); courseProgressData = courseData.CreateProgress(userId); courseProgressData.Id = $"{userId}{courseData.Id}"; courseProgressData.SetUpLinks(); controller = CreateProgressController(); }
private static void AddLessonProgress(CourseProgressData courseProgressData, LessonData lessonData) { var lessonProgress = new LessonProgressData { LessonId = lessonData.Id, StepProgresses = new List <StepProgressData>() }; foreach (var step in lessonData.Steps) { AddStepProgress(lessonProgress, step); } courseProgressData.LessonProgresses.Add(lessonProgress); }
public static CourseProgress ToApiModel(this CourseProgressData progressData) { var result = new CourseProgress { CourceId = progressData.CourceId, Id = progressData.Id, LessonProgresses = progressData.LessonProgresses.Select(lessonProgress => lessonProgress.ToApiModel()).ToList(), Passed = progressData.Passed, Statistics = new Statistics { Passed = progressData.StatisticsData.Passed, PassedQuestionsCount = progressData.StatisticsData.PassedQuestionsCount, TotalQuestionsCount = progressData.StatisticsData.TotalQuestionsCount }, UserId = progressData.UserId }; return(result); }
public static CourseProgressData CreateProgress(this CourseData courseData, string userId) { if (courseData == null) { throw new ArgumentNullException(nameof(courseData)); } var result = new CourseProgressData { LessonProgresses = new List <LessonProgressData>(), CourceId = courseData.Id, UserId = userId, StatisticsData = new StatisticsData { TotalQuestionsCount = QuestionsCount(courseData) } }; foreach (var lesson in courseData.Lessons) { AddLessonProgress(result, lesson); } return(result); }
//Optional return of default data public CourseProgressData SetDefaultCourseProgressData(Course _course) { CourseProgressData _pData = new CourseProgressData(_course.ID, _course.GetCourseViewIDByIndex(0)); for (int i = 0; i < _course.courseViews.Count; i++) { _pData.AddStateData(new CourseViewStateData(_course.courseViews[i].ID)); } SetCourseProgressData(_pData); return _pData; }
// Sets entire progress data public void SetCourseProgressData(CourseProgressData _pData) { string _fileName = CourseProgressHelper.GetFileName(_pData.courseID); Serializer.Save<CourseProgressData>(_pData, _fileName); }