protected void btnSave_Click(object sender, EventArgs e) { var saved = new Academic.DbEntities.ActivityAndResource.BookItems.BookChapter(); using (var helper = new DbHelper.ActAndRes()) { var chapter = new Academic.DbEntities.ActivityAndResource.BookItems.BookChapter() { Id = ChapterId, BookId = BookId , Content = CKEditor1.Text , Title = txtName.Text , }; if (chkSubChapter.Checked) { if (ParentChapterId > 0) { chapter.ParentChapterId = ParentChapterId; } } else { // here we need to assign th parent id of the parentchapterId var parent = helper.GetChapter(ParentChapterId); if (parent != null) { chapter.ParentChapterId = parent.ParentChapterId; chapter.Position = parent.Position; } } saved = helper.AddOrUpdateBookChapter(chapter); } using (var helper = new DbHelper.ActAndRes()) { if (saved != null) { helper.UpdateBelowChapters(saved.BookId, saved.Id, saved.ParentChapterId ?? 0, saved.Position); Response.Redirect("~/Views/ActivityResource/Book/BookView.aspx?arId=" + BookId + "&SubId=" + hidSubjectId.Value + "&secId=" + hidSectionId.Value); } } }