/// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                var rockContext = new RockContext();
                LayoutService layoutService = new LayoutService( rockContext );
                Layout layout;

                int layoutId = int.Parse( hfLayoutId.Value );

                // if adding a new layout
                if ( layoutId.Equals( 0 ) )
                {
                    layout = new Layout { Id = 0 };
                    layout.SiteId = hfSiteId.ValueAsInt();
                }
                else
                {
                    //load existing group member
                    layout = layoutService.Get( layoutId );
                }

                layout.Name = tbLayoutName.Text;
                layout.Description = tbDescription.Text;
                layout.FileName = ddlLayout.SelectedValue;

                if ( !layout.IsValid )
                {
                    return;
                }

                if ( layout.Id.Equals( 0 ) )
                {
                    layoutService.Add( layout );
                }

                rockContext.SaveChanges();

                LayoutCache.Flush( layout.Id );

                Dictionary<string, string> qryParams = new Dictionary<string, string>();
                qryParams["layoutId"] = layout.Id.ToString();
                NavigateToPage( RockPage.Guid, qryParams );
            }
        }
        /// <summary>
        /// Handles the Click event of the DeleteLayout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteLayout_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            LayoutService layoutService = new LayoutService(rockContext);

            Layout layout = layoutService.Get( e.RowKeyId );
            if ( layout != null )
            {
                string errorMessage;
                canDelete = layoutService.CanDelete( layout, out errorMessage );
                if ( !canDelete )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                int siteId = layout.SiteId;

                layoutService.Delete( layout );
                rockContext.SaveChanges();

                LayoutCache.Flush( e.RowKeyId );
            }

            BindLayoutsGrid();
        }
Beispiel #3
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                LayoutService layoutService = new LayoutService();
                Layout layout;

                int layoutId = int.Parse( hfLayoutId.Value );

                // if adding a new layout 
                if ( layoutId.Equals( 0 ) )
                {
                    layout = new Layout { Id = 0 };
                    layout.SiteId = hfSiteId.ValueAsInt();
                }
                else
                {
                    //load existing group member
                    layout = layoutService.Get( layoutId );
                }

                layout.Name = tbLayoutName.Text;
                layout.Description = tbDescription.Text;
                layout.FileName = ddlLayout.SelectedValue;

                if ( !layout.IsValid )
                {
                    return;
                }

                RockTransactionScope.WrapTransaction( () =>
                {
                    if ( layout.Id.Equals( 0 ) )
                    {
                        layoutService.Add( layout, CurrentPersonId );
                    }

                    layoutService.Save( layout, CurrentPersonId );
                } );

                LayoutCache.Flush( layout.Id );

                Dictionary<string, string> qryString = new Dictionary<string, string>();
                qryString["siteId"] = hfSiteId.Value;
                NavigateToParentPage( qryString );
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
        {
            if ( hfLayoutId.Value.Equals( "0" ) )
            {
                // Cancelling on Add
                Dictionary<string, string> qryString = new Dictionary<string, string>();
                qryString["siteId"] = hfSiteId.Value;
                NavigateToParentPage( qryString );
            }
            else
            {
                // Cancelling on Edit
                LayoutService layoutService = new LayoutService();
                Layout layout = layoutService.Get( int.Parse( hfLayoutId.Value ) );

                Dictionary<string, string> qryString = new Dictionary<string, string>();
                qryString["siteId"] = layout.SiteId.ToString();
                NavigateToParentPage( qryString );
            }
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Click event of the DeleteLayout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteLayout_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                LayoutService layoutService = new LayoutService();
                Layout layout = layoutService.Get( e.RowKeyId );
                if ( layout != null )
                {
                    string errorMessage;
                    if ( !layoutService.CanDelete( layout, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    int siteId = layout.SiteId;

                    layoutService.Delete( layout, CurrentPersonId );
                    layoutService.Save( layout, CurrentPersonId );

                    LayoutCache.Flush( e.RowKeyId );
                }
            } );

            BindLayoutsGrid();
        }