Beispiel #1
0
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static HtmlContent ToModel(this HtmlContentDto value)
        {
            HtmlContent result = new HtmlContent();

            value.CopyToModel(result);
            return(result);
        }
 /// <summary>
 /// Clones this HtmlContent object to a new HtmlContent object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static HtmlContent Clone(this HtmlContent source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as HtmlContent);
     }
     else
     {
         var target = new HtmlContent();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
        protected void lbEdit_Click(object sender, EventArgs e)
        {
            HtmlContentService service = new HtmlContentService();

            Rock.Model.HtmlContent content = service.GetActiveContent(CurrentBlock.Id, EntityValue());
            if (content == null)
            {
                content = new Rock.Model.HtmlContent();
            }

            if (_supportVersioning)
            {
                phCurrentVersion.Visible    = true;
                pnlVersioningHeader.Visible = true;
                cbOverwriteVersion.Visible  = true;

                hfVersion.Value   = content.Version.ToString();
                lVersion.Text     = content.Version.ToString();
                tbStartDate.Text  = content.StartDateTime.HasValue ? content.StartDateTime.Value.ToShortDateString() : string.Empty;
                tbExpireDate.Text = content.ExpireDateTime.HasValue ? content.ExpireDateTime.Value.ToShortDateString() : string.Empty;

                if (_requireApproval)
                {
                    cbApprove.Checked = content.IsApproved;
                    cbApprove.Enabled = IsUserAuthorized("Approve");
                    cbApprove.Visible = true;
                }
                else
                {
                    cbApprove.Visible = false;
                }
            }
            else
            {
                phCurrentVersion.Visible    = false;
                pnlVersioningHeader.Visible = false;
                cbOverwriteVersion.Visible  = false;
            }

            edtHtmlContent.Toolbar = "RockCustomConfigFull";
            edtHtmlContent.Text    = content.Content;
            mpeContent.Show();
            edtHtmlContent.Visible      = true;
            HtmlContentModified         = false;
            edtHtmlContent.TextChanged += edtHtmlContent_TextChanged;

            BindGrid();

            hfAction.Value = "Edit";
        }
Beispiel #4
0
 /// <summary>
 /// Copies the properties from another HtmlContent object to this HtmlContent object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this HtmlContent target, HtmlContent source)
 {
     target.BlockId              = source.BlockId;
     target.EntityValue          = source.EntityValue;
     target.Version              = source.Version;
     target.Content              = source.Content;
     target.IsApproved           = source.IsApproved;
     target.ApprovedByPersonId   = source.ApprovedByPersonId;
     target.ApprovedDateTime     = source.ApprovedDateTime;
     target.StartDateTime        = source.StartDateTime;
     target.ExpireDateTime       = source.ExpireDateTime;
     target.LastModifiedDateTime = source.LastModifiedDateTime;
     target.LastModifiedPersonId = source.LastModifiedPersonId;
     target.Id   = source.Id;
     target.Guid = source.Guid;
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (IsUserAuthorized("Edit") || IsUserAuthorized("Administrate"))
            {
                Rock.Model.HtmlContent content = null;
                HtmlContentService     service = new HtmlContentService();

                // get settings
                string entityValue = EntityValue();

                // get current  content
                int version = 0;
                if (!Int32.TryParse(hfVersion.Value, out version))
                {
                    version = 0;
                }
                content = service.GetByBlockIdAndEntityValueAndVersion(CurrentBlock.Id, entityValue, version);

                // if the existing content changed, and the overwrite option was not checked, create a new version
                if (content != null &&
                    _supportVersioning &&
                    content.Content != edtHtmlContent.Text &&
                    !cbOverwriteVersion.Checked)
                {
                    content = null;
                }

                // if a record doesn't exist then  create one
                if (content == null)
                {
                    content             = new Rock.Model.HtmlContent();
                    content.BlockId     = CurrentBlock.Id;
                    content.EntityValue = entityValue;

                    if (_supportVersioning)
                    {
                        int?maxVersion = service.Queryable().
                                         Where(c => c.BlockId == CurrentBlock.Id &&
                                               c.EntityValue == entityValue).
                                         Select(c => (int?)c.Version).Max();

                        content.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1;
                    }
                    else
                    {
                        content.Version = 0;
                    }

                    service.Add(content, CurrentPersonId);
                }

                if (_supportVersioning)
                {
                    DateTime startDate;
                    if (DateTime.TryParse(tbStartDate.Text, out startDate))
                    {
                        content.StartDateTime = startDate;
                    }
                    else
                    {
                        content.StartDateTime = null;
                    }

                    DateTime expireDate;
                    if (DateTime.TryParse(tbExpireDate.Text, out expireDate))
                    {
                        content.ExpireDateTime = expireDate;
                    }
                    else
                    {
                        content.ExpireDateTime = null;
                    }
                }
                else
                {
                    content.StartDateTime  = null;
                    content.ExpireDateTime = null;
                }

                if (!_requireApproval || IsUserAuthorized("Approve"))
                {
                    content.IsApproved = !_requireApproval || cbApprove.Checked;
                    if (content.IsApproved)
                    {
                        content.ApprovedByPersonId = CurrentPersonId;
                        content.ApprovedDateTime   = DateTime.Now;
                    }
                }

                content.Content = edtHtmlContent.Text;

                if (service.Save(content, CurrentPersonId))
                {
                    // flush cache content
                    this.FlushCacheItem(entityValue);
                    ShowView();
                }
                else
                {
                    // TODO: service.ErrorMessages;
                }
            }

            else
            {
                ShowView();
            }
        }
Beispiel #6
0
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="htmlContent"></param>
 public HtmlContentDto(HtmlContent htmlContent)
 {
     CopyFromModel(htmlContent);
 }
Beispiel #7
0
 /// <summary>
 /// To the dto.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static HtmlContentDto ToDto(this HtmlContent value)
 {
     return(new HtmlContentDto(value));
 }