Пример #1
0
        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() }
            });
        }
Пример #2
0
        public IActionResult Add(NewChapterViewModel model)
        {
            var success = service.Add(
                model.CourseId,
                model.ParentId,
                model.Title,
                model.Content,
                model.Video);

            return(Ok(success));
        }