protected void btnSave_Click(object sender, EventArgs e) { RockContext rockContext = new RockContext(); ChapterService chapterService = new ChapterService(rockContext); var chapter = GetChapter(chapterService); chapter.Name = tbName.Text; chapter.Description = tbDescription.Text; if (chapter.Id == 0) { chapterService.Add(chapter); var courseId = PageParameter(PageParameterKey.CourseId).AsIntegerOrNull(); var chapters = chapterService .Queryable() .Where(cc => cc.CourseId == courseId) .OrderBy(cc => cc.Order).ToList(); chapter.Order = 0; if (chapters.Any()) { chapter.Order = chapters.Last().Order + 1; } } rockContext.SaveChanges(); NavigateToCurrentPage(new Dictionary <string, string> { { PageParameterKey.ChapterId, chapter.Id.ToString() } }); }
private void gList_GridReorder(object sender, GridReorderEventArgs e) { var rockContext = new RockContext(); ChapterService chapterService = new ChapterService(rockContext); var courseId = PageParameter(PageParameterKey.CourseId).AsInteger(); var items = chapterService.Queryable().Where(p => p.CourseId == courseId).OrderBy(i => i.Order).ToList(); chapterService.Reorder(items, e.OldIndex, e.NewIndex); rockContext.SaveChanges(); BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var courseId = PageParameter(PageParameterKey.CourseId).AsInteger(); RockContext rockContext = new RockContext(); CourseService courseService = new CourseService(rockContext); var course = courseService.Get(courseId); if (course == null || course.ExternalCourseUrl.IsNotNullOrWhiteSpace()) { this.Visible = false; return; } ChapterService chapterService = new ChapterService(rockContext); var qry = chapterService.Queryable() .Where(cc => cc.CourseId == courseId) .OrderBy(cc => cc.Order); gList.SetLinqDataSource(qry); gList.DataBind(); }