/// <summary>
        /// Handles the SaveClick event of the dlgChannelAttributes 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 dlgChannelAttributes_SaveClick(object sender, EventArgs e)
        {
            Rock.Model.Attribute attribute = new Rock.Model.Attribute();
            edtChannelAttributes.GetAttributeProperties(attribute);

            // Controls will show warnings
            if (!attribute.IsValid)
            {
                return;
            }

            if (ChannelAttributesState.Any(a => a.Guid.Equals(attribute.Guid)))
            {
                attribute.Order = ChannelAttributesState.Where(a => a.Guid.Equals(attribute.Guid)).FirstOrDefault().Order;
                ChannelAttributesState.RemoveEntity(attribute.Guid);
            }
            else
            {
                attribute.Order = ChannelAttributesState.Any() ? ChannelAttributesState.Max(a => a.Order) + 1 : 0;
            }
            ChannelAttributesState.Add(attribute);

            BindChannelAttributesGrid();

            HideDialog();
        }
        /// <summary>
        /// Handles the GridReorder event of the gChannelAttributes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void gChannelAttributes_GridReorder(object sender, GridReorderEventArgs e)
        {
            var movedChannel = ChannelAttributesState.Where(a => a.Order == e.OldIndex).FirstOrDefault();

            if (movedChannel != null)
            {
                if (e.NewIndex < e.OldIndex)
                {
                    // Moved up
                    foreach (var otherChannel in ChannelAttributesState.Where(a => a.Order < e.OldIndex && a.Order >= e.NewIndex))
                    {
                        otherChannel.Order = otherChannel.Order + 1;
                    }
                }
                else
                {
                    // Moved Down
                    foreach (var otherChannel in ChannelAttributesState.Where(a => a.Order > e.OldIndex && a.Order <= e.NewIndex))
                    {
                        otherChannel.Order = otherChannel.Order - 1;
                    }
                }

                movedChannel.Order = e.NewIndex;
            }

            BindChannelAttributesGrid();
        }
 /// <summary>
 /// Binds the marketing campaign ad attribute type grid.
 /// </summary>
 private void BindChannelAttributesGrid()
 {
     gChannelAttributes.DataSource = ChannelAttributesState
                                     .OrderBy(a => a.Order)
                                     .ThenBy(a => a.Name)
                                     .ToList();
     gChannelAttributes.DataBind();
 }
        /// <summary>
        /// Handles the Delete event of the gChannelAttributes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void gChannelAttributes_Delete(object sender, RowEventArgs e)
        {
            Guid attributeGuid = (Guid)e.RowKeyValue;

            ChannelAttributesState.RemoveEntity(attributeGuid);

            BindChannelAttributesGrid();
        }
        /// <summary>
        /// Gs the marketing campaign ad attribute type_ show edit.
        /// </summary>
        /// <param name="attributeId">The attribute id.</param>
        protected void gChannelAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                        = new Attribute();
                attribute.FieldTypeId            = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
                edtChannelAttributes.ActionTitle = ActionTitle.Add(tbName.Text + " Channel Attribute");
            }
            else
            {
                attribute = ChannelAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtChannelAttributes.ActionTitle = ActionTitle.Edit(tbName.Text + " Channel Attribute");
            }

            edtChannelAttributes.ReservedKeyNames = ChannelAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList();

            edtChannelAttributes.SetAttributeProperties(attribute, typeof(ContentChannel));

            ShowDialog("ChannelAttributes", true);
        }