/// <summary>
 /// Adds a new ExpandableTextHtmlInfo object into the database
 /// </summary>
 /// <param name="info"></param>
 public void AddExpandableTextHtml(ExpandableTextHtmlInfo info)
 {
     DataProvider.Instance().AddExpandableTextHtml(info.ModuleId, info.Title, info.Body, info.LastUpdated,
                                                   info.IsExpanded, info.SortOrder, info.PublishDate,
                                                   info.RequiredRole);
 }
        /// <summary>
        /// This method handles an insert or update!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                var controller = new ExpandableTextHtmlController();
                var item = new ExpandableTextHtmlInfo();

                txtTitle.HtmlEncode = false;
                item.Title = txtTitle.Text;
                txtBody.HtmlEncode = false;
                item.Body = txtBody.Text;

                item.LastUpdated = DateTime.Now;
                item.ModuleId = ModuleId;
                item.ItemId = itemId;
                item.IsExpanded = chkIsExpanded.Checked;
                item.SortOrder = int.Parse(txtSortOrder.Text);
                item.RequiredRole = ddlRequiredRole.SelectedValue;

                //Do we need to default the publish date
                item.PublishDate = string.IsNullOrEmpty(txtPublishDate.Text) ? DateTime.Now.Date : DateTime.Parse(txtPublishDate.Text);

                //Determine if we need to clean the title text
                if (item.Title.StartsWith("<p>") && item.Title.EndsWith("</p>"))
                {
                    item.Title = item.Title.Substring(3, item.Title.Length - 7);
                }

                //determine if we are adding or updating
                if (Null.IsNull(item.ItemId))
                    controller.AddExpandableTextHtml(item);
                else
                    controller.UpdateExpandableTextHtml(item);

                //Purge the cache
                ModuleController.SynchronizeModule(ModuleId);

                //Call cancel to return
                cmdCancel_Click(sender, e);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        ///// <summary>
        ///// imports a module from an xml file
        ///// </summary>
        ///// <param name="ModuleID">The id of the module</param>
        ///// <param name="Content">The XML content</param>
        ///// <param name="Version"></param>
        ///// <param name="UserID"></param>
        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
            var infos = Globals.GetContent(Content, "ExpandableTextHtmls");

            //If no items found, short circuit
            if (infos == null)
                return;

            //Load each
            foreach (XmlNode info in infos.SelectNodes("ExpandableTextHtml"))
            {
                var oInfo = new ExpandableTextHtmlInfo
                                {
                                    ModuleId = ModuleID,
                                    Title = info.SelectSingleNode("title").InnerText,
                                    Body = info.SelectSingleNode("body").InnerText,
                                    IsExpanded =
                                        bool.Parse(info.SelectSingleNode("isExpanded").InnerText),
                                    SortOrder =
                                        int.Parse(info.SelectSingleNode("sortOrder").InnerText),
                                    PublishDate =
                                        DateTime.Parse(
                                            info.SelectSingleNode("publishDate").InnerText),
                                    LastUpdated = DateTime.Now,
                                    RequiredRole = info.SelectSingleNode("requiredRole").InnerText
                                };

                AddExpandableTextHtml(oInfo);
            }
        }
        /// <summary>
        /// This method will create an item using the jQuery methods for expanding/collapsing
        /// </summary>
        /// <param name="litContent">The literal control that the content item should be added to</param>
        /// <param name="oInfo">The <see cref="ExpandableTextHtmlInfo"/> object with information</param>
        private void CreateItemJQuery(Literal litContent, ExpandableTextHtmlInfo oInfo)
        {
            //Declare a string builder for the template
            var oItemBuilder = new StringBuilder();

            //Start with the template
            oItemBuilder.Append(_itemTemplate);

            //Setup Edit
            oItemBuilder.Replace("[EDIT]", BuildEditLink(oInfo.ItemId));

            //Create the content element's id for later use
            var contentId = "ICG_ETH_" + oInfo.ItemId.ToString();

            //Sub in the title to our template
            oItemBuilder.Replace("[TITLE]", BuildTitleLink(contentId, oInfo.ItemId.ToString(), oInfo.Title));

            //Put in expand collapse token
            oItemBuilder.Replace("[EXPANDCOLLAPSEICON]",
                                 BuildExpandCollapseIconJquery(contentId, oInfo.ItemId, oInfo.IsExpanded));

            //Sub in the content
            oItemBuilder.Replace("[CONTENT]", BuildContent(contentId, oInfo.Body, oInfo.IsExpanded));

            //Add in last modified
            oItemBuilder.Replace("[LASTMODIFIED]", oInfo.LastUpdated.ToShortDateString());

            //Put the content into the literal
            litContent.Text = oItemBuilder.ToString();

            //Add to the list
            _displayed.Add(new DisplayedEntries(oInfo.ItemId, contentId));
        }