private CoursePageRecord GetCurrentCoursePageRecord(RockContext rockContext) { CourseRecordService courseRecordService = new CourseRecordService(rockContext); ChapterRecordService chapterRecordService = new ChapterRecordService(rockContext); CoursePageRecordService coursePageRecordService = new CoursePageRecordService(rockContext); CourseRecord courseRecord = GetCourseRecord(courseRecordService); if (externalRedirectDebug.IsNotNullOrWhiteSpace()) { return(null); } if (courseRecord == null) { throw new Exception("This course does not exist or you are not authorized"); } ChapterRecord chapterRecord = GetNextChapterRecord(courseRecord, chapterRecordService); while (chapterRecord != null) { CoursePageRecord coursePageRecord = GetNextCoursePageRecord(coursePageRecordService, chapterRecord); if (coursePageRecord != null) { ViewState["coursePageRecordId"] = coursePageRecord.Id; return(coursePageRecord); } else { chapterRecord.CompletionDateTime = RockDateTime.Now; chapterRecord.Passed = chapterRecord.CoursePageRecords.Where(p => p.Passed).Count() >= chapterRecord.Chapter.CoursePages.Count(); rockContext.SaveChanges(); if (chapterRecord.Passed == false) { ShowFailedChapter(); return(null); } chapterRecord = GetNextChapterRecord(courseRecord, chapterRecordService); } } //if we got to this place the course is complete courseRecord.CompletionDateTime = RockDateTime.Now; courseRecord.Passed = courseRecord.ChapterRecords.Where(c => c.Passed).Count() >= courseRecord.Course.Chapters.Count(); rockContext.SaveChanges(); CourseRequirementHelper.UpdateCourseStatuses(courseRecord.CourseId, courseRecord.PersonAliasId, courseRecord.Passed); DisplayCompletion(); return(null); }
public virtual void Execute(IJobExecutionContext context) { using (RockContext rockContext = new RockContext()) { CourseRequirementService courseRequirementService = new CourseRequirementService(rockContext); var courseRequirements = courseRequirementService.Queryable().AsNoTracking().ToList(); foreach (var courseRequirement in courseRequirements) { CourseRequirementHelper.UpdateCourseRequirementStatuses(courseRequirement); } } }
protected void btnSave_Click(object sender, EventArgs e) { var isNew = false; RockContext rockContext = new RockContext(); CourseRequirementService courseRequirementService = new CourseRequirementService(rockContext); var courseRequirement = GetCourseRequirement(courseRequirementService); if (courseRequirement.Id == 0) { isNew = true; courseRequirementService.Add(courseRequirement); } courseRequirement.CourseId = pCourse.SelectedValueAsId() ?? 0; if (ddlSelect.SelectedValue == "DATAVIEW") { courseRequirement.DataViewId = pDataview.SelectedValueAsId(); courseRequirement.GroupId = null; } else if (ddlSelect.SelectedValue == "GROUP") { courseRequirement.GroupId = pGroup.SelectedValueAsId(); courseRequirement.DataViewId = null; } courseRequirement.DaysValid = tbDaysValid.Text.AsIntegerOrNull(); rockContext.SaveChanges(); ; CourseRequirementHelper.UpdateCourseRequirementStatuses(courseRequirement); if (isNew) { NavigateToCurrentPage(new Dictionary <string, string> { { PageParameterKey.CourseId, PageParameter(PageParameterKey.CourseId) }, { PageParameterKey.CourseRequirementId, courseRequirement.Id.ToString() }, }); } else { ShowDetails(); } }