/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); btnNext.Visible = true; if (!Page.IsPostBack) { RockContext rockContext = new RockContext(); coursePageRecord = GetCurrentCoursePageRecord(rockContext); if (coursePageRecord == null) { //This has a value when the user is an editor and the course is external if (externalRedirectDebug.IsNotNullOrWhiteSpace()) { DisplayExternalRedirectDebug(); } else { DisplayCompletion(); } return; } RockPage.PageTitle = coursePageRecord.CoursePage.Chapter.Course.Name; RockPage.BrowserTitle = RockPage.PageTitle; RockPage.Title = RockPage.PageTitle; Page.Title = RockPage.PageTitle; RockPage.BreadCrumbs.Last().Name = RockPage.PageTitle; DisplayCoursePage(); } }
private CoursePageRecord GetNextCoursePageRecord(CoursePageRecordService coursePageRecordService, ChapterRecord chapterRecord) { var pages = chapterRecord.Chapter.CoursePages.OrderBy(p => p.Order); foreach (var page in pages) { var pageRecords = chapterRecord.CoursePageRecords .Where(r => r.CoursePageId == page.Id); //If no page record exists create one if (!pageRecords.Any()) { var pageRecord = new CoursePageRecord { CoursePage = page, ChapterRecord = chapterRecord }; coursePageRecordService.Add(pageRecord); coursePageRecordService.Context.SaveChanges(); return(pageRecord); } //Return incomplete page if (pageRecords.Where(r => r.CompletionDateTime == null).Any()) { return(pageRecords.Where(r => r.CompletionDateTime == null).FirstOrDefault()); } } return(null); //There are no more page records to complete for this chapter }
private void ShowFailedChapter() { ViewState["coursePageRecordId"] = null; RockContext rockContext = new RockContext(); coursePageRecord = GetCurrentCoursePageRecord(rockContext); pnlElements.Visible = false; pnlSuccess.Visible = false; pnlFail.Visible = true; }
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); }
protected override void LoadViewState(object savedState) { base.LoadViewState(savedState); if (ViewState["coursePageRecordId"] is int) { var coursePageRecordId = ( int )ViewState["coursePageRecordId"]; RockContext rockContext = new RockContext(); CoursePageRecordService coursePageRecordService = new CoursePageRecordService(rockContext); coursePageRecord = coursePageRecordService.Get(coursePageRecordId); if (coursePageRecord != null) { DisplayCoursePage(); } } }
private void MoveToPage(int coursePageId) { var currentPersonAliasIds = CurrentPerson.Aliases.Select(a => a.Id).ToList(); RockContext rockContext = new RockContext(); CoursePageRecordService coursePageRecordService = new CoursePageRecordService(rockContext); coursePageRecord = coursePageRecordService.Queryable() .Where(r => r.CoursePageId == coursePageId && currentPersonAliasIds.Contains(r.ChapterRecord.CourseRecord.PersonAliasId)) .OrderByDescending(r => r.CreatedDateTime) .FirstOrDefault(); btnNext.Visible = false; DisplayCoursePage(); }
public override void ScoreCourse(List <Control> controls, CoursePageRecord coursePageRecord) { coursePageRecord.Score = 0; if (controls.Count > 0 && controls[0] is HiddenField) { coursePageRecord.Score = (( HiddenField )controls[0]).Value.AsInteger(); } if (coursePageRecord.Score >= coursePageRecord.CoursePage.PassingScore) { coursePageRecord.Passed = true; } else { coursePageRecord.Passed = false; } }
protected void btnNext_Click(object sender, EventArgs e) { //Need to recreate the coursePageRecord with our own context RockContext rockContext = new RockContext(); CoursePageRecordService coursePageRecordService = new CoursePageRecordService(rockContext); coursePageRecord = coursePageRecordService.Get(coursePageRecord.Id); var component = GetPageComponent(); component.ScoreCourse(controls, coursePageRecord); coursePageRecord.CompletionDateTime = Rock.RockDateTime.Now; rockContext.SaveChanges(); coursePageRecord = GetCurrentCoursePageRecord(rockContext); if (coursePageRecord != null) { DisplayCoursePage(); } }
/// <summary>Scores the course.</summary> /// <param name="controls">The controls.</param> /// <param name="coursePageRecord">The course page record.</param> public virtual void ScoreCourse(List <Control> controls, CoursePageRecord coursePageRecord) { coursePageRecord.Passed = true; coursePageRecord.CompletionDateTime = Rock.RockDateTime.Now; }