private void BuildEditControls(PersonBadge personBadge, bool setValues) { personBadge.LoadAttributes(); phAttributes.Controls.Clear(); Rock.Attribute.Helper.AddEditControls(personBadge, phAttributes, setValues, "", new List <string> { "Active", "Order" }); }
/// <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; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); PersonBadge.SaveAttributeValues(rockContext); }); PersonBadgeCache.Flush(PersonBadge.Id); NavigateToParentPage(); }
/// <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 SelectedIndexChanged event of the compBadgeType 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 compBadgeType_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(compBadgeType.SelectedValue)) { var badgeType = EntityTypeCache.Read(compBadgeType.SelectedValue.AsGuid()); if (badgeType != null) { var personBadge = new PersonBadge { EntityTypeId = badgeType.Id }; BuildEditControls(personBadge, true); } } }
/// <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); pdAuditDetails.SetEntity(personBadge, ResolveRockUrl("~")); } } else { // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } } 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> /// 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() ?? 0; 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; } personBadgeService.Delete(personBadge); rockContext.SaveChanges(); } BindGrid(); }
private void BuildEditControls(PersonBadge personBadge, bool setValues) { personBadge.LoadAttributes(); phAttributes.Controls.Clear(); Rock.Attribute.Helper.AddEditControls( personBadge, phAttributes, setValues, "", new List<string> { "Active", "Order" } ); }
/// <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() ?? 0; 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 SelectedIndexChanged event of the compBadgeType 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 compBadgeType_SelectedIndexChanged( object sender, EventArgs e ) { if ( !string.IsNullOrWhiteSpace( compBadgeType.SelectedValue ) ) { var badgeType = EntityTypeCache.Read( compBadgeType.SelectedValue.AsGuid() ); if ( badgeType != null ) { var personBadge = new PersonBadge { EntityTypeId = badgeType.Id }; BuildEditControls( personBadge, true ); } } }
/// <summary> /// Loads the attributes for the badge. The attributes are loaded by the framework prior to executing the badge, /// so typically Person Badges do not need to load the attributes /// </summary> /// <param name="badge">The badge.</param> public void LoadAttributes( PersonBadge badge ) { badge.LoadAttributes(); }
/// <summary> /// Loads the attributes for the badge. The attributes are loaded by the framework prior to executing the badge, /// so typically Person Badges do not need to load the attributes /// </summary> /// <param name="badge">The badge.</param> public void LoadAttributes(PersonBadge badge) { badge.LoadAttributes(); }
/// <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 ); pdAuditDetails.SetEntity( personBadge, ResolveRockUrl( "~" ) ); } } else { // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } } 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 ); } } } }