/// <summary> /// Saves content for the ediotr. Creates a new version entry in the DB /// </summary> protected void SaveContent(string ChapID, string sender) { try { ChapterVersion chapterVersion = new ChapterVersion(); IList <ChapterVersion> allChapters = DocoManager.GetAllItemsByArticleId(ArticleId); chapterVersion = allChapters.First(x => x.Id.Equals(ChapID)); string temp = chapterVersion.Content; // chapterVersion.Content = UltimateEditor1.EditorHtml; BusiBlocks.XHTMLText htmlText = new BusiBlocks.XHTMLText(); //chapterVersion.Content = htmlText.FormatXHTML(txtEditor.Content); chapterVersion.Content = txtEditor.Content; //check if the user has changed the Chapter Name. if (txtBoxChapterName.Visible && !string.IsNullOrEmpty(txtBoxChapterName.Text) && txtBoxChapterName.Text != chapterVersion.Name) { chapterVersion.Name = txtBoxChapterName.Text; } //if this is the first chapter and no content has been uploaded then if (string.IsNullOrEmpty(temp)) // if the content is empty or is being added for the first time it will update the only existing single record. { BusiBlocks.DocoBlock.DocoManager.UpdateChapterVersion(chapterVersion); } else //Check if the chapter name has changed at all - if yes then pass in VersionUpdateType.Chapter //Update chapter ID if using the button to save content, if not then do no update since the wmLoadChapter does it. { if (sender == "button") { ChapterId = BusiBlocks.DocoBlock.DocoManager.CreateChapterVersion(ArticleId, chapterVersion, VersionUpdateType.Content).Id; } else { BusiBlocks.DocoBlock.DocoManager.CreateChapterVersion(ArticleId, chapterVersion, VersionUpdateType.Content); } } //perform draft operations. //DeleteDraft(chapterVersion.Id); } catch (Exception ex) { //Log - unable to save current content for the selected chapter. throw ex; } lblLastDraft.Text = "<i>Chapter content saved on: " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToShortTimeString() + "</i>"; }
/// <summary> /// Binds the reorder list on left to the chapters. Also binds the chapters to the list in link selection div. /// </summary> protected void BindSequence() { IList <ChapterVersion> dsChapters = DocoManager.GetAllItemsByArticleId(ArticleId); //bind chapters to the list ReorderList1.DataSource = dsChapters; ReorderList1.DataBind(); ReorderList2.DataSource = dsChapters; ReorderList2.DataBind(); //bind chapters to the select list rptChapsList.DataSource = dsChapters; rptChapsList.DataBind(); }
protected void SaveContent(string ChapID, int sequence) { try { ChapterVersion chapterVersion = new ChapterVersion(); BusiBlocks.XHTMLText xhtml = new BusiBlocks.XHTMLText(); IList <ChapterVersion> allChapters = DocoManager.GetAllItemsByArticleId(ArticleId); chapterVersion = allChapters.First(x => x.Id.Equals(ChapID)); Draft draft = DocoManager.GetDraftByChapterId(chapterVersion.Id); string temp = chapterVersion.Content; if (draft != null) { chapterVersion.Content = draft.Content; } //add anchor tags for subchapters. chapterVersion.Sequence = sequence; chapterVersion.Content = xhtml.AddAnchorTags(chapterVersion.Content); //if this is the first time chapter content is added and no content has been uploaded then if (string.IsNullOrEmpty(temp)) // if the content is empty or is being added for the first time it will update the only existing single record. { BusiBlocks.DocoBlock.DocoManager.UpdateChapterVersion(chapterVersion); } else //Update chapter ID if using the button to save content, if not then do no update since the wmLoadChapter does it. { BusiBlocks.DocoBlock.DocoManager.CreateChapterVersion(ArticleId, chapterVersion, VersionUpdateType.Content); } Article a = DocoManager.GetArticle(ArticleId); a.UpdateDate = DateTime.Now; DocoManager.UpdateArticle(a, false); } catch (Exception ex) { //Log - unable to save current content for the selected chapter. throw ex; } }
protected void rlTemplate_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e) { ChapterVersion chapterVers = new ChapterVersion(); IList <ChapterVersion> allChapters = DocoManager.GetAllItemsByArticleId(ArticleId); HiddenField lblIdSender = (HiddenField)e.Item.FindControl("hdnId"); //item moving down -- all items below it will move up starting from the new index if (e.NewIndex > e.OldIndex) { for (int i = e.NewIndex; i > e.OldIndex; i--) { HiddenField lblId = (HiddenField)ReorderList1.Items[i].FindControl("hdnId"); chapterVers = allChapters.First(x => x.Id.Equals(lblId.Value)); chapterVers.Sequence = i - 1; BusiBlocks.DocoBlock.DocoManager.UpdateChapterVersion(chapterVers); } } else if (e.NewIndex < e.OldIndex) { for (int i = e.NewIndex; i < e.OldIndex; i++) { HiddenField lblId = (HiddenField)ReorderList1.Items[i].FindControl("hdnId"); chapterVers = allChapters.First(x => x.Id.Equals(lblId.Value)); chapterVers.Sequence = i + 1; BusiBlocks.DocoBlock.DocoManager.UpdateChapterVersion(chapterVers); } } //update the item itself chapterVers = allChapters.First(x => x.Id.Equals(lblIdSender.Value)); chapterVers.Sequence = e.NewIndex; BusiBlocks.DocoBlock.DocoManager.UpdateChapterVersion(chapterVers); BindSequence(); }
/// <summary> /// Loads a chapter /// </summary> /// <param name="isDefault">True if called on !Postback which will load the default chapter for the document.</param> protected void LoadChapter(bool isDefault) { IList <ChapterVersion> chapters = DocoManager.GetAllItemsByArticleId(ArticleId); int lowestOrderNumber = DocoManager.GetLowestSequenceNumber(ArticleId); //Load the chapter from the docoID if (chapters.Count > 0) { divEditor.Style.Add("display", "block"); List <ChapterVersion> chapVersions = new List <ChapterVersion>(); if (isDefault) { var chaps = from c in chapters where c.Sequence == lowestOrderNumber select c; chapVersions = chaps.ToList <ChapterVersion>(); } else { var chaps = from c in chapters where c.Id == ChapterId select c; chapVersions = chaps.ToList <ChapterVersion>(); } ChapterVersion chVersion = chapVersions.First(); lblChapterName.Text = chVersion.Name; txtBoxChapterName.Text = chVersion.Name; lblChapterNameEditor.InnerHtml = chVersion.Name; ChapterId = chVersion.Id; ChapterName = chVersion.Name; int chapNumb = (chVersion.Sequence + 1); if (!string.IsNullOrEmpty(contentMode) && contentMode.Equals("pub")) { //set the content in the editor or literal depending on the mode. if (chapVersions.Count <ChapterVersion>() > 0) { DisplayContent(chVersion.Content, chapNumb, IsNumbChaps); } else { DisplayContent("", chapNumb, IsNumbChaps); } //Bind drafts if any found for this chapter. //divDraftsList.InnerHtml = BindDrafts(ChapterId); } else { IList <Draft> drafts = DocoManager.GetDraftsByChapterId(ChapterId); if (drafts.Count > 0) { Draft draft = drafts.FirstOrDefault <Draft>(); if (draft != null) { DisplayContent(draft.Content, chapNumb, IsNumbChaps); } else { DisplayContent("", chapNumb, IsNumbChaps); } } else //load published version by default { if (chapVersions.Count <ChapterVersion>() > 0) { DisplayContent(chVersion.Content, chapNumb, IsNumbChaps); } else { DisplayContent("", chapNumb, IsNumbChaps); } } } } else { previewDiv.Style.Add("display", "none"); divEditor.Style.Add("display", "none"); } }