/// <summary> /// Shows the edit detail. /// </summary> /// <param name="htmlContent">Content of the HTML.</param> private void ShowEditDetail(HtmlContent htmlContent) { if (htmlContent == null) { htmlContent = new HtmlContent(); } int?maxVersion = GetMaxVersionOfHtmlContent(); hfVersion.Value = htmlContent.Version.ToString(); if (maxVersion.HasValue && maxVersion.Value != htmlContent.Version) { lVersion.Text = string.Format("Version {0} <small>of {1}</small> | ", htmlContent.Version, maxVersion.Value); } else { lVersion.Text = string.Format("Version {0} | ", htmlContent.Version); } SetApprovalValues(htmlContent.IsApproved, htmlContent.ApprovedByPerson); drpDateRange.LowerValue = htmlContent.StartDateTime; drpDateRange.UpperValue = htmlContent.ExpireDateTime; htmlEditor.Text = htmlContent.Content; ceHtml.Text = htmlContent.Content; }
/// <summary> /// Shows the edit detail. /// </summary> /// <param name="htmlContent">Content of the HTML.</param> private void ShowEditDetail( HtmlContent htmlContent ) { if ( htmlContent == null ) { htmlContent = new HtmlContent(); } int? maxVersion = GetMaxVersionOfHtmlContent(); hfVersion.Value = htmlContent.Version.ToString(); if ( maxVersion.HasValue && maxVersion.Value != htmlContent.Version ) { lVersion.Text = string.Format( "Version {0} <small>of {1}</small> | ", htmlContent.Version, maxVersion.Value ); } else { lVersion.Text = string.Format( "Version {0} | ", htmlContent.Version ); } SetApprovalValues( htmlContent.IsApproved, htmlContent.ApprovedByPerson ); drpDateRange.LowerValue = htmlContent.StartDateTime; drpDateRange.UpperValue = htmlContent.ExpireDateTime; htmlEditor.Text = htmlContent.Content; ceHtml.Text = htmlContent.Content; }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click( object sender, EventArgs e ) { bool supportVersioning = GetAttributeValue( "SupportVersions" ).AsBoolean(); bool requireApproval = GetAttributeValue( "RequireApproval" ).AsBoolean(); HtmlContentService htmlContentService = new HtmlContentService(); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion( this.BlockId, entityValue, version ); // if the existing content changed, and the overwrite option was not checked, create a new version string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text; if ( htmlContent != null && supportVersioning && htmlContent.Content != newContent && !cbOverwriteVersion.Checked ) { htmlContent = null; } // if a record doesn't exist then create one if ( htmlContent == null ) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if ( supportVersioning ) { int? maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add( htmlContent, CurrentPersonId ); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; if ( !requireApproval || IsUserAuthorized( "Approve" ) ) { htmlContent.IsApproved = !requireApproval || hfApprovalStatus.Value.AsBoolean(); if ( htmlContent.IsApproved ) { int personId = hfApprovalStatusPersonId.ValueAsInt(); if ( personId > 0 ) { htmlContent.ApprovedByPersonId = personId; htmlContent.ApprovedDateTime = DateTime.Now; } } } htmlContent.LastModifiedPersonId = this.CurrentPersonId; htmlContent.LastModifiedDateTime = DateTime.Now; htmlContent.Content = newContent; if ( htmlContentService.Save( htmlContent, CurrentPersonId ) ) { // flush cache content this.FlushCacheItem( entityValue ); // force the updatepanel for the view to update since we have two update panels and we only want the View to update when it is edited and Saved upnlHtmlContent.Update(); ShowView(); } else { // TODO: service.ErrorMessages; } }
/// <summary> /// Shows the view. /// </summary> protected void ShowView() { mdEdit.Hide(); pnlEditModel.Visible = false; upnlHtmlContent.Update(); // prevent htmlEditor from using viewstate when not needed pnlEdit.EnableViewState = false; pnlEdit.Visible = false; pnlVersionGrid.Visible = false; string entityValue = EntityValue(); string html = string.Empty; string cachedContent = HtmlContentService.GetCachedContent(this.BlockId, entityValue); // if content not cached load it from DB if (cachedContent == null) { using (var rockContext = new RockContext()) { var htmlContentService = new HtmlContentService(rockContext); HtmlContent content = htmlContentService.GetActiveContent(this.BlockId, entityValue); if (content != null) { bool enableDebug = GetAttributeValue("EnableDebug").AsBoolean(); if (content.Content.HasMergeFields() || enableDebug) { var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields(CurrentPerson); if (CurrentPerson != null) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Add("Person", CurrentPerson); mergeFields.Add("CurrentPerson", CurrentPerson); } mergeFields.Add("Campuses", CampusCache.All()); mergeFields.Add("PageParameter", PageParameters()); mergeFields.Add("CurrentPage", GetPageProperties()); var contextObjects = new Dictionary <string, object>(); foreach (var contextEntityType in RockPage.GetContextEntityTypes()) { var contextEntity = RockPage.GetCurrentContext(contextEntityType); if (contextEntity != null && contextEntity is DotLiquid.ILiquidizable) { var type = Type.GetType(contextEntityType.AssemblyName ?? contextEntityType.Name); if (type != null) { contextObjects.Add(type.Name, contextEntity); } } } if (contextObjects.Any()) { mergeFields.Add("Context", contextObjects); } mergeFields.Add("RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber()); mergeFields.Add("CurrentPersonCanEdit", IsUserAuthorized(Authorization.EDIT)); mergeFields.Add("CurrentPersonCanAdministrate", IsUserAuthorized(Authorization.ADMINISTRATE)); html = content.Content.ResolveMergeFields(mergeFields); // show merge fields if enable debug true if (enableDebug && IsUserAuthorized(Authorization.EDIT)) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Remove("Person"); html += mergeFields.lavaDebugInfo(); } } else { html = content.Content; } } else { html = string.Empty; } } // Resolve any dynamic url references string appRoot = ResolveRockUrl("~/"); string themeRoot = ResolveRockUrl("~~/"); html = html.Replace("~~/", themeRoot).Replace("~/", appRoot); // cache content int cacheDuration = GetAttributeValue("CacheDuration").AsInteger(); if (cacheDuration > 0) { HtmlContentService.AddCachedContent(this.BlockId, entityValue, html, cacheDuration); } } else { html = cachedContent; } // add content to the content window lHtmlContent.Text = html; }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click(object sender, EventArgs e) { bool supportVersioning = GetAttributeValue("SupportVersions").AsBoolean(); bool requireApproval = GetAttributeValue("RequireApproval").AsBoolean(); var rockContext = new RockContext(); HtmlContentService htmlContentService = new HtmlContentService(rockContext); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion(this.BlockId, entityValue, version); // get the content depending on which mode we are in (codeeditor or ckeditor) string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text; //// create a new record only in the following situations: //// - this is the first time this htmlcontent block got content (new block and edited for the first time) //// - the content was changed, versioning is enabled, and OverwriteVersion is not checked // if the existing content changed, and the overwrite option was not checked, create a new version if (htmlContent != null) { // Editing existing content. Check if content has changed if (htmlContent.Content != newContent) { // The content has changed (different than database). Check if versioning is enabled if (supportVersioning && !cbOverwriteVersion.Checked) { //// versioning is enabled, and they didn't choose to overwrite //// set to null so that we'll create a new record htmlContent = null; } } } // if a record doesn't exist then create one if (htmlContent == null) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if (supportVersioning) { int?maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add(htmlContent); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; bool currentUserCanApprove = IsUserAuthorized("Approve"); if (!requireApproval) { // if this block doesn't require Approval, mark it as approved htmlContent.IsApproved = true; htmlContent.ApprovedByPersonId = this.CurrentPersonId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // if this block requires Approval, mark it as approved if the ApprovalStatus is still approved, or if the current user can approve htmlContent.IsApproved = (hfApprovalStatus.Value.AsBoolean()) || currentUserCanApprove; if (htmlContent.IsApproved) { int?personId = hfApprovalStatusPersonId.Value.AsInteger(false); if (!personId.HasValue) { // if it wasn't approved, but the current user can approve, make the current user the approver if (currentUserCanApprove) { personId = this.CurrentPersonId; } } if (personId.HasValue) { htmlContent.ApprovedByPersonId = personId; htmlContent.ApprovedDateTime = RockDateTime.Now; } } } htmlContent.Content = newContent; if (rockContext.SaveChanges() > 0) { // flush cache content this.FlushCacheItem(entityValue); ShowView(); } else { // TODO: service.ErrorMessages; } }
/// <summary> /// Shows the view. /// </summary> protected void ShowView() { mdEdit.Hide(); pnlEditModel.Visible = false; upnlHtmlContent.Update(); // prevent htmlEditor from using viewstate when not needed pnlEdit.EnableViewState = false; pnlEdit.Visible = false; pnlVersionGrid.Visible = false; string entityValue = EntityValue(); string html = string.Empty; int cacheDuration = GetAttributeValue("CacheDuration").AsInteger(); string cachedContent = null; // only load from the cache if a cacheDuration was specified if (cacheDuration > 0) { cachedContent = HtmlContentService.GetCachedContent(this.BlockId, entityValue); } // if content not cached load it from DB if (cachedContent == null) { using (var rockContext = new RockContext()) { var htmlContentService = new HtmlContentService(rockContext); HtmlContent content = htmlContentService.GetActiveContent(this.BlockId, entityValue); if (content != null) { if (content.Content.HasMergeFields()) { var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson); mergeFields.Add("CurrentPage", this.PageCache); if (CurrentPerson != null) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.AddOrIgnore("Person", CurrentPerson); } mergeFields.Add("RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber()); mergeFields.Add("CurrentPersonCanEdit", IsUserAuthorized(Authorization.EDIT)); mergeFields.Add("CurrentPersonCanAdministrate", IsUserAuthorized(Authorization.ADMINISTRATE)); html = content.Content.ResolveMergeFields(mergeFields, GetAttributeValue("EnabledLavaCommands")); } else { html = content.Content; } } else { html = string.Empty; } } // Resolve any dynamic url references string appRoot = ResolveRockUrl("~/"); string themeRoot = ResolveRockUrl("~~/"); html = html.Replace("~~/", themeRoot).Replace("~/", appRoot); // cache content if (cacheDuration > 0) { HtmlContentService.AddCachedContent(this.BlockId, entityValue, html, cacheDuration); } } else { html = cachedContent; } // add content to the content window lHtmlContent.Text = html; }
/// <summary> /// Handles the Click event of the lbQuickEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> // Disable QuickEdit for v7 //protected void lbQuickEdit_Click( object sender, EventArgs e ) //{ // ShowSettings(); //} /// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click(object sender, EventArgs e) { bool supportVersioning = GetAttributeValue("SupportVersions").AsBoolean(); bool requireApproval = GetAttributeValue("RequireApproval").AsBoolean(); var rockContext = new RockContext(); HtmlContentService htmlContentService = new HtmlContentService(rockContext); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion(this.BlockId, entityValue, version); string newContent = htmlEditor.Text; // check if the new content is valid // NOTE: This is a limited check that will only warn of invalid HTML the first // time a user clicks the save button. Any errors encountered on the second runthrough // are assumed to be intentional. HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(newContent); if (doc.ParseErrors.Count() > 0 && !nbInvalidHtml.Visible) { var reasons = doc.ParseErrors.Select(r => r.Reason).ToList(); StringBuilder sb = new StringBuilder(); sb.AppendLine("Warning: The HTML has the following errors:<ul>"); foreach (var reason in reasons) { sb.AppendLine(String.Format("<li>{0}</li>", reason.EncodeHtml())); } sb.AppendLine("</ul> <br/> If you wish to save anyway, click the save button again."); nbInvalidHtml.Text = sb.ToString(); nbInvalidHtml.Visible = true; return; } //// create a new record only in the following situations: //// - this is the first time this htmlcontent block got content (new block and edited for the first time) //// - the content was changed, versioning is enabled, and OverwriteVersion is not checked // if the existing content changed, and the overwrite option was not checked, create a new version if (htmlContent != null) { // Editing existing content. Check if content has changed if (htmlContent.Content != newContent) { // The content has changed (different than database). Check if versioning is enabled if (supportVersioning && !cbOverwriteVersion.Checked) { //// versioning is enabled, and they didn't choose to overwrite //// set to null so that we'll create a new record htmlContent = null; } } } // if a record doesn't exist then create one if (htmlContent == null) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if (supportVersioning) { int?maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add(htmlContent); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; bool currentUserCanApprove = IsUserAuthorized("Approve"); if (!requireApproval) { // if this block doesn't require Approval, mark it as approved htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // since this content requires Approval, mark it as approved ONLY if the current user can approve // and they set the hfApprovalStatus flag to true. if (currentUserCanApprove && hfApprovalStatus.Value.AsBoolean()) { htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // if the content has changed if (htmlContent.Content != newContent) { nbApprovalRequired.Visible = true; htmlContent.IsApproved = false; } } } htmlContent.Content = newContent; rockContext.SaveChanges(); // flush cache content HtmlContentService.FlushCachedContent(htmlContent.BlockId, htmlContent.EntityValue); ShowView(); }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click( object sender, EventArgs e ) { bool supportVersioning = GetAttributeValue( "SupportVersions" ).AsBoolean(); bool requireApproval = GetAttributeValue( "RequireApproval" ).AsBoolean(); var rockContext = new RockContext(); HtmlContentService htmlContentService = new HtmlContentService( rockContext ); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion( this.BlockId, entityValue, version ); // get the content depending on which mode we are in (codeeditor or ckeditor) string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text; //// create a new record only in the following situations: //// - this is the first time this htmlcontent block got content (new block and edited for the first time) //// - the content was changed, versioning is enabled, and OverwriteVersion is not checked // if the existing content changed, and the overwrite option was not checked, create a new version if (htmlContent != null) { // Editing existing content. Check if content has changed if (htmlContent.Content != newContent) { // The content has changed (different than database). Check if versioning is enabled if (supportVersioning && !cbOverwriteVersion.Checked) { //// versioning is enabled, and they didn't choose to overwrite //// set to null so that we'll create a new record htmlContent = null; } } } // if a record doesn't exist then create one if ( htmlContent == null ) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if ( supportVersioning ) { int? maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add( htmlContent ); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; bool currentUserCanApprove = IsUserAuthorized( "Approve" ); if ( !requireApproval ) { // if this block doesn't require Approval, mark it as approved htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // since this content requires Approval, mark it as approved ONLY if the current user can approve // and they set the hfApprovalStatus flag to true. if ( currentUserCanApprove && hfApprovalStatus.Value.AsBoolean() ) { htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // if the content has changed if ( htmlContent.Content != newContent ) { nbApprovalRequired.Visible = true; htmlContent.IsApproved = false; } } } htmlContent.Content = newContent; rockContext.SaveChanges(); // flush cache content HtmlContentService.FlushCachedContent( htmlContent.BlockId, htmlContent.EntityValue ); ShowView(); }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click( object sender, EventArgs e ) { bool supportVersioning = GetAttributeValue( "SupportVersions" ).AsBoolean(); bool requireApproval = GetAttributeValue( "RequireApproval" ).AsBoolean(); var rockContext = new RockContext(); HtmlContentService htmlContentService = new HtmlContentService( rockContext ); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion( this.BlockId, entityValue, version ); // get the content depending on which mode we are in (codeeditor or ckeditor) string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text; // check if the new content is valid // NOTE: This is a limited check that will only warn of invalid HTML the first // time a user clicks the save button. Any errors encountered on the second runthrough // are assumed to be intentional. HtmlDocument doc = new HtmlDocument(); doc.LoadHtml( newContent ); if ( doc.ParseErrors.Count() > 0 && !nbInvalidHtml.Visible ) { var reasons = doc.ParseErrors.Select( r => r.Reason ).ToList(); StringBuilder sb = new StringBuilder(); sb.AppendLine( "Warning: The HTML has the following errors:<ul>" ); foreach ( var reason in reasons ) { sb.AppendLine( String.Format( "<li>{0}</li>", reason.EncodeHtml() ) ); } sb.AppendLine( "</ul> <br/> If you wish to save anyway, click the save button again." ); nbInvalidHtml.Text = sb.ToString(); nbInvalidHtml.Visible = true; return; } //// create a new record only in the following situations: //// - this is the first time this htmlcontent block got content (new block and edited for the first time) //// - the content was changed, versioning is enabled, and OverwriteVersion is not checked // if the existing content changed, and the overwrite option was not checked, create a new version if (htmlContent != null) { // Editing existing content. Check if content has changed if (htmlContent.Content != newContent) { // The content has changed (different than database). Check if versioning is enabled if (supportVersioning && !cbOverwriteVersion.Checked) { //// versioning is enabled, and they didn't choose to overwrite //// set to null so that we'll create a new record htmlContent = null; } } } // if a record doesn't exist then create one if ( htmlContent == null ) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if ( supportVersioning ) { int? maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add( htmlContent ); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; bool currentUserCanApprove = IsUserAuthorized( "Approve" ); if ( !requireApproval ) { // if this block doesn't require Approval, mark it as approved htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // since this content requires Approval, mark it as approved ONLY if the current user can approve // and they set the hfApprovalStatus flag to true. if ( currentUserCanApprove && hfApprovalStatus.Value.AsBoolean() ) { htmlContent.IsApproved = true; htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId; htmlContent.ApprovedDateTime = RockDateTime.Now; } else { // if the content has changed if ( htmlContent.Content != newContent ) { nbApprovalRequired.Visible = true; htmlContent.IsApproved = false; } } } htmlContent.Content = newContent; rockContext.SaveChanges(); // flush cache content HtmlContentService.FlushCachedContent( htmlContent.BlockId, htmlContent.EntityValue ); ShowView(); }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click(object sender, EventArgs e) { bool supportVersioning = GetAttributeValue("SupportVersions").AsBoolean(); bool requireApproval = GetAttributeValue("RequireApproval").AsBoolean(); HtmlContentService htmlContentService = new HtmlContentService(); // get settings string entityValue = EntityValue(); // get current content int version = hfVersion.ValueAsInt(); HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion(this.BlockId, entityValue, version); // if the existing content changed, and the overwrite option was not checked, create a new version string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text; if (htmlContent != null && supportVersioning && htmlContent.Content != newContent && !cbOverwriteVersion.Checked) { htmlContent = null; } // if a record doesn't exist then create one if (htmlContent == null) { htmlContent = new HtmlContent(); htmlContent.BlockId = this.BlockId; htmlContent.EntityValue = entityValue; if (supportVersioning) { int?maxVersion = GetMaxVersionOfHtmlContent(); htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1; } else { htmlContent.Version = 1; } htmlContentService.Add(htmlContent, CurrentPersonId); } htmlContent.StartDateTime = drpDateRange.LowerValue; htmlContent.ExpireDateTime = drpDateRange.UpperValue; if (!requireApproval || IsUserAuthorized("Approve")) { htmlContent.IsApproved = !requireApproval || hfApprovalStatus.Value.AsBoolean(); if (htmlContent.IsApproved) { int personId = hfApprovalStatusPersonId.ValueAsInt(); if (personId > 0) { htmlContent.ApprovedByPersonId = personId; htmlContent.ApprovedDateTime = DateTime.Now; } } } htmlContent.LastModifiedPersonId = this.CurrentPersonId; htmlContent.LastModifiedDateTime = DateTime.Now; htmlContent.Content = newContent; if (htmlContentService.Save(htmlContent, CurrentPersonId)) { // flush cache content this.FlushCacheItem(entityValue); // force the updatepanel for the view to update since we have two update panels and we only want the View to update when it is edited and Saved upnlHtmlContent.Update(); ShowView(); } else { // TODO: service.ErrorMessages; } }