/// <summary> /// Adds the remove chapter nodes to the preference xml saved in document library. /// </summary> /// <param name="wellBookDetails">The well book details.</param> /// <param name="chapterPreference">The chapter preference.</param> /// <returns>XmlDocument</returns> private XmlDocument AddRemoveChapterNodes(XmlDocument wellBookDetails, XmlDocument chapterPreference) { if (wellBookDetails != null && wellBookDetails.ChildNodes.Count > 0 && chapterPreference != null && chapterPreference.ChildNodes.Count > 0) { /// add/remove chapters present in wellbookdetails but not in chapterpreference. XmlNodeList chapterNodesInTree = wellBookDetails.SelectNodes("/BookInfo/Chapter"); XmlNode chapterNodeInPreference = null; int intIndex = 1; foreach (XmlNode chapterNodeInTree in chapterNodesInTree) { chapterNodeInPreference = chapterPreference.SelectSingleNode("/BookInfo/Chapter[@ChapterID = '" + chapterNodeInTree.Attributes["ChapterID"].Value + "']"); if (chapterNodeInPreference == null) { /// Insert at the beginning XmlNode refChapterNode = chapterPreference.SelectSingleNode("/BookInfo/Chapter"); XmlElement newChapterElement = chapterPreference.CreateElement("Chapter"); XmlAttribute chapterIDAttribute = chapterPreference.CreateAttribute("ChapterID"); chapterIDAttribute.Value = chapterNodeInTree.Attributes["ChapterID"].Value; XmlAttribute chapterTitle = chapterPreference.CreateAttribute("ChapterTitle"); chapterTitle.Value = chapterNodeInTree.Attributes["ChapterTitle"].Value; XmlAttribute display = chapterPreference.CreateAttribute("Display"); display.Value = "True"; XmlAttribute chapterOrder = chapterPreference.CreateAttribute("ChapterOrder"); chapterOrder.Value = intIndex.ToString(); intIndex++; newChapterElement.Attributes.Append(chapterIDAttribute); newChapterElement.Attributes.Append(chapterTitle); newChapterElement.Attributes.Append(display); newChapterElement.Attributes.Append(chapterOrder); chapterPreference.SelectSingleNode("/BookInfo").InsertBefore(newChapterElement, refChapterNode); } } /// remove chapters in chapterpreference but not in wellbookdetails. XmlNodeList chapterNodesInPreference = chapterPreference.SelectNodes("/BookInfo/Chapter"); XmlNode newChapterNodeInTree = null; foreach (XmlNode chapterNode in chapterNodesInPreference) { newChapterNodeInTree = wellBookDetails.SelectSingleNode("/BookInfo/Chapter[@ChapterID = '" + chapterNode.Attributes["ChapterID"].Value + "']"); if (newChapterNodeInTree == null) { /// Remove the node from preferencexml. chapterPreference.SelectSingleNode("/BookInfo").RemoveChild(chapterNode); } } } ChapterBLL objChapterBLL = new ChapterBLL(); objChapterBLL.SaveReorderXml(chapterPreference.OuterXml, HttpContext.Current.Request.QueryString[QUERYSTRING_BOOKID]); return chapterPreference; }
/// <summary> /// Saves the reorder XML to document library. /// </summary> /// <param name="chapterPreference">The chapter preference.</param> /// <param name="bookId">The book id.</param> /// <returns></returns> protected XmlDocument SaveReorderXml(string chapterPreference, string bookId) { XmlDocument userReorderXml = null; ChapterBLL objChapterBLL = new ChapterBLL(); userReorderXml = objChapterBLL.SaveReorderXml(chapterPreference, bookId); return userReorderXml; }