/// <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 )
        {
            PersonBadge PersonBadge = null;
            var rockContext = new RockContext();
            PersonBadgeService PersonBadgeService = new PersonBadgeService( rockContext );

            if ( PersonBadgeId != 0 )
            {
                PersonBadge = PersonBadgeService.Get( PersonBadgeId );
            }

            if (PersonBadge == null)
            {
                PersonBadge = new PersonBadge();
                PersonBadgeService.Add( PersonBadge );
            }

            PersonBadge.Name = tbName.Text;
            PersonBadge.Description = tbDescription.Text;

            if ( !string.IsNullOrWhiteSpace( compBadgeType.SelectedValue ) )
            {
                var badgeType = EntityTypeCache.Read( compBadgeType.SelectedValue.AsGuid() );
                if ( badgeType != null )
                {
                    PersonBadge.EntityTypeId = badgeType.Id;
                }
            }

            PersonBadge.LoadAttributes( rockContext );
            Rock.Attribute.Helper.GetEditValues( phAttributes, PersonBadge );

            if ( !Page.IsValid )
            {
                return;
            }

            if ( !PersonBadge.IsValid )
            {
                return;
            }

            RockTransactionScope.WrapTransaction( () =>
            {
                rockContext.SaveChanges();
                PersonBadge.SaveAttributeValues( rockContext );
            } );

            PersonBadgeCache.Flush( PersonBadge.Id );

            NavigateToParentPage();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            if ( !Page.IsPostBack )
            {
                lActionTitle.Text = ActionTitle.Add( PersonBadge.FriendlyTypeName ).FormatAsHtmlTitle();

                PersonBadgeId = PageParameter( "PersonBadgeId" ).AsInteger();
                if ( PersonBadgeId != 0 )
                {
                    var personBadge = new PersonBadgeService( new RockContext() ).Get( PersonBadgeId );
                    if ( personBadge != null )
                    {
                        lActionTitle.Text = ActionTitle.Edit( personBadge.Name ).FormatAsHtmlTitle();

                        tbName.Text = personBadge.Name;
                        tbDescription.Text = personBadge.Description;
                        if ( personBadge.EntityTypeId.HasValue )
                        {
                            var badgeType = EntityTypeCache.Read( personBadge.EntityTypeId.Value );
                            compBadgeType.SelectedValue = badgeType.Guid.ToString().ToUpper();
                        }

                        BuildEditControls( personBadge, true );
                    }
                }
            }
            else
            {
                if ( !string.IsNullOrWhiteSpace( compBadgeType.SelectedValue ) )
                {
                    var badgeType = EntityTypeCache.Read( compBadgeType.SelectedValue.AsGuid() );
                    if ( badgeType != null )
                    {
                        var personBadge = new PersonBadge { EntityTypeId = badgeType.Id };
                        BuildEditControls( personBadge, false );
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Delete event of the gPersonBadge control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gPersonBadge_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            PersonBadgeService PersonBadgeService = new PersonBadgeService( rockContext );
            PersonBadge PersonBadge = PersonBadgeService.Get( e.RowKeyId );

            if ( PersonBadge != null )
            {
                string errorMessage;
                if ( !PersonBadgeService.CanDelete( PersonBadge, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                PersonBadgeCache.Flush( PersonBadge.Id );

                PersonBadgeService.Delete( PersonBadge );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        void gPersonBadge_GridReorder( object sender, GridReorderEventArgs e )
        {
            var rockContext = new RockContext();
            var service = new PersonBadgeService( rockContext );
            var badges = service.Queryable().OrderBy( b => b.Order );
            service.Reorder( badges.ToList(), e.OldIndex, e.NewIndex );
            rockContext.SaveChanges();

            BindGrid();
        }
Ejemplo n.º 5
0
        void gPersonBadge_GridReorder( object sender, GridReorderEventArgs e )
        {
            var rockContext = new RockContext();
            var service = new PersonBadgeService( rockContext );
            var personBadges = service.Queryable().OrderBy( b => b.Order );
            service.Reorder( personBadges.ToList(), e.OldIndex, e.NewIndex );
            rockContext.SaveChanges();

            foreach ( var personBadge in personBadges )
            {
                PersonBadgeCache.Flush( personBadge.Id );
            }

            BindGrid();
        }