Example #1
0
        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
        }
Example #2
0
        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);
        }
Example #3
0
 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();
         }
     }
 }
Example #4
0
        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();
        }
Example #5
0
        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();
            }
        }
Example #6
0
        private void UpdateTableOfContents(CoursePage coursePage)
        {
            phTOC.Controls.Clear();
            phMobileTOC.Controls.Clear();

            var course = coursePage.Chapter.Course;
            var passed = false;
            var first  = true;

            var mostAdvancedCoursePageId = coursePage.Id;

            if (ViewState["coursePageRecordId"] is int)
            {
                RockContext             rockContext             = new RockContext();
                CoursePageRecordService coursePageRecordService = new CoursePageRecordService(rockContext);
                mostAdvancedCoursePageId = coursePageRecordService.Get(( int )ViewState["coursePageRecordId"]).CoursePageId;
            }



            foreach (var chapter in course.Chapters.OrderBy(c => c.Order).ToList())
            {
                var ltChapter = new Literal
                {
                    ID = "ltChapter" + chapter.Id.ToString(),
                };
                if (coursePage.ChapterId == chapter.Id)
                {
                    ltChapter.Text = string.Format("<b>{0}</b></br>", chapter.Name);
                }
                else
                {
                    ltChapter.Text = string.Format("{0}</br>", chapter.Name);
                }
                phTOC.Controls.Add(ltChapter);

                //Mobile
                if (!first)
                {
                    HtmlGenericControl liDivider = new HtmlGenericControl("li");
                    liDivider.AddCssClass("divider");
                    phMobileTOC.Controls.Add(liDivider);
                }
                first = false;

                HtmlGenericControl liChapter = new HtmlGenericControl("li");
                liChapter.AddCssClass("dropdown-header");
                liChapter.InnerText = chapter.Name;
                phMobileTOC.Controls.Add(liChapter);


                //Add the course pages
                foreach (var page in chapter.CoursePages.OrderBy(c => c.Order).ToList())
                {
                    phTOC.Controls.Add(new Literal {
                        Text = "&emsp;"
                    });

                    if (page.Id == coursePage.Id)
                    {
                        Literal ltPage = new Literal
                        {
                            ID   = "ltPage" + page.Id.ToString(),
                            Text = string.Format("<a href='#'><i class='fa fa-caret-right'></i> {0}</a><br>", page.Name)
                        };

                        phTOC.Controls.Add(ltPage);

                        //Mobile
                        phMobileTitle.Controls.Clear();
                        Literal mobileTitle = new Literal
                        {
                            Text = page.Name
                        };
                        phMobileTitle.Controls.Add(mobileTitle);

                        HtmlGenericControl li = new HtmlGenericControl("li")
                        {
                            InnerHtml = string.Format("<a href='#'><i class='fa fa-caret-right'></i> {0}</a>", page.Name)
                        };
                        phMobileTOC.Controls.Add(li);
                    }
                    else
                    {
                        LinkButton lbPage = new LinkButton
                        {
                            ID   = "lbPage" + page.Id.ToString(),
                            Text = string.Format("{0}<br>", page.Name)
                        };

                        HtmlGenericControl li = new HtmlGenericControl("li");
                        phMobileTOC.Controls.Add(li);

                        LinkButton lbMobile = new LinkButton
                        {
                            ID   = "lbMobile" + page.Id.ToString(),
                            Text = page.Name
                        };

                        if (passed)
                        {
                            lbPage.Enabled   = false;
                            lbMobile.Enabled = false;
                        }
                        else
                        {
                            lbPage.Click   += (s, e) => { MoveToPage(page.Id); };
                            lbMobile.Click += (s, e) => { MoveToPage(page.Id); };
                        }

                        phTOC.Controls.Add(lbPage);
                        li.Controls.Add(lbMobile);
                    }


                    if (page.Id == mostAdvancedCoursePageId)
                    {
                        passed = true;
                    }
                }
            }
        }