/// <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(); }
/// <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(); }