/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="groupId">The group id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? groupId ) { if ( !itemKey.Equals( "GroupMemberId" ) ) { return; } var rockContext = new RockContext(); GroupMember groupMember = null; if ( !itemKeyValue.Equals( 0 ) ) { groupMember = new GroupMemberService( rockContext ).Get( itemKeyValue ); groupMember.LoadAttributes(); } else { // only create a new one if parent was specified if ( groupId.HasValue ) { groupMember = new GroupMember { Id = 0 }; groupMember.GroupId = groupId.Value; groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId ); groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0; groupMember.GroupMemberStatus = GroupMemberStatus.Active; } } if ( groupMember == null ) { return; } hfGroupId.Value = groupMember.GroupId.ToString(); hfGroupMemberId.Value = groupMember.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; var group = groupMember.Group; if ( !string.IsNullOrWhiteSpace( group.GroupType.IconCssClass ) ) { lGroupIconHtml.Text = string.Format( "<i class='{0}' ></i>", group.GroupType.IconCssClass ); } else { lGroupIconHtml.Text = string.Empty; } if ( groupMember.Id.Equals( 0 ) ) { lReadOnlyTitle.Text = ActionTitle.Add( groupMember.Group.GroupType.GroupTerm + " " + groupMember.Group.GroupType.GroupMemberTerm ).FormatAsHtmlTitle(); } else { lReadOnlyTitle.Text = groupMember.Person.FullName.FormatAsHtmlTitle(); } // user has to have EDIT Auth to both the Block and the group nbEditModeMessage.Text = string.Empty; if ( !IsUserAuthorized( Authorization.EDIT ) || !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Group.FriendlyTypeName ); } if ( groupMember.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Group.FriendlyTypeName ); } btnSave.Visible = !readOnly; LoadDropDowns(); ppGroupMemberPerson.SetValue( groupMember.Person ); ppGroupMemberPerson.Enabled = !readOnly; ddlGroupRole.SetValue( groupMember.GroupRoleId ); ddlGroupRole.Enabled = !readOnly; rblStatus.SetValue( (int)groupMember.GroupMemberStatus ); rblStatus.Enabled = !readOnly; rblStatus.Label = string.Format( "{0} Status", group.GroupType.GroupMemberTerm ); groupMember.LoadAttributes(); phAttributes.Controls.Clear(); Rock.Attribute.Helper.AddEditControls( groupMember, phAttributes, true, "", true ); if ( readOnly ) { Rock.Attribute.Helper.AddDisplayControls( groupMember, phAttributesReadOnly ); phAttributesReadOnly.Visible = true; phAttributes.Visible = false; } else { phAttributesReadOnly.Visible = false; phAttributes.Visible = true; } }
/// <summary> /// Handles the SelectItem event of the gpMoveGroupMember 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 gpMoveGroupMember_SelectItem( object sender, EventArgs e ) { var rockContext = new RockContext(); var destGroup = new GroupService( rockContext ).Get( gpMoveGroupMember.SelectedValue.AsInteger() ); if ( destGroup != null ) { var destTempGroupMember = new GroupMember { Group = destGroup, GroupId = destGroup.Id }; destTempGroupMember.LoadAttributes( rockContext ); var destGroupMemberAttributes = destTempGroupMember.Attributes; var groupMember = new GroupMemberService( rockContext ).Get( hfGroupMemberId.Value.AsInteger() ); groupMember.LoadAttributes(); var currentGroupMemberAttributes = groupMember.Attributes; var lostAttributes = currentGroupMemberAttributes.Where( a => !destGroupMemberAttributes.Any( d => d.Key == a.Key && d.Value.FieldTypeId == a.Value.FieldTypeId ) ); nbMoveGroupMemberWarning.Visible = lostAttributes.Any(); nbMoveGroupMemberWarning.Text = "The destination group does not have the same group member attributes as the source. Some loss of data may occur"; if ( destGroup.Id == groupMember.GroupId ) { grpMoveGroupMember.Visible = false; nbMoveGroupMemberWarning.Visible = true; nbMoveGroupMemberWarning.Text = "The destination group is the same as the current group"; } else { grpMoveGroupMember.Visible = true; grpMoveGroupMember.GroupTypeId = destGroup.GroupTypeId; grpMoveGroupMember.GroupRoleId = destGroup.GroupType.DefaultGroupRoleId; } } else { nbMoveGroupMemberWarning.Visible = false; grpMoveGroupMember.Visible = false; } }