本文整理汇总了C#中GroupMember.LoadAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMember.LoadAttributes方法的具体用法?C# GroupMember.LoadAttributes怎么用?C# GroupMember.LoadAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GroupMember
的用法示例。
在下文中一共展示了GroupMember.LoadAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnLoad
/// <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 )
{
string groupId = PageParameter( "GroupId" );
string groupMemberId = PageParameter( "GroupMemberId" );
if ( !string.IsNullOrWhiteSpace( groupMemberId ) )
{
if ( string.IsNullOrWhiteSpace( groupId ) )
{
ShowDetail( "GroupMemberId", int.Parse( groupMemberId ) );
}
else
{
ShowDetail( "GroupMemberId", int.Parse( groupMemberId ), int.Parse( groupId ) );
}
}
else
{
upDetail.Visible = false;
}
}
else
{
var groupMember = new GroupMember { GroupId = hfGroupId.ValueAsInt() };
if ( groupMember != null )
{
groupMember.LoadAttributes();
phAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( groupMember, phAttributes, false );
}
}
}
示例2: GroupMemberPlacedElsewhereTransaction
/// <summary>
/// Initializes a new instance of the <see cref="GroupMemberPlacedElsewhereTransaction" /> class.
/// </summary>
/// <param name="groupMember">The group member of the current group they are in (before being deleted and processed) </param>
/// <param name="note">The note.</param>
/// <param name="trigger">The GroupMemberWorkflowTrigger.</param>
public GroupMemberPlacedElsewhereTransaction( GroupMember groupMember, string note, GroupMemberWorkflowTrigger trigger )
{
this.Trigger = trigger;
this.GroupId = groupMember.GroupId;
this.PersonId = groupMember.PersonId;
this.GroupMemberStatusName = groupMember.GroupMemberStatus.ConvertToString();
this.GroupMemberRoleName = groupMember.GroupRole.ToString();
groupMember.LoadAttributes();
this.GroupMemberAttributeValues = groupMember.AttributeValues.ToDictionary( k => k.Key, v => v.Value.Value );
this.Note = note;
}
示例3: btnSave_Click
//.........这里部分代码省略.........
RegistrationTemplate.DiscountCodeTerm = string.IsNullOrWhiteSpace( tbDiscountCodeTerm.Text ) ? "Discount Code" : tbDiscountCodeTerm.Text;
RegistrationTemplate.SuccessTitle = tbSuccessTitle.Text;
RegistrationTemplate.SuccessText = ceSuccessText.Text;
if ( !Page.IsValid || !RegistrationTemplate.IsValid )
{
return;
}
foreach ( var form in FormState )
{
if ( !form.IsValid )
{
return;
}
if ( FormFieldsState.ContainsKey( form.Guid ) )
{
foreach( var formField in FormFieldsState[ form.Guid ])
{
if ( !formField.IsValid )
{
return;
}
}
}
}
// Get the valid group member attributes
var group = new Group();
group.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0;
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.LoadAttributes();
var validGroupMemberAttributeIds = groupMember.Attributes.Select( a => a.Value.Id ).ToList();
// Remove any group member attributes that are not valid based on selected group type
foreach( var fieldList in FormFieldsState.Select( s => s.Value ) )
{
foreach( var formField in fieldList
.Where( a =>
a.FieldSource == RegistrationFieldSource.GroupMemberAttribute &&
a.AttributeId.HasValue &&
!validGroupMemberAttributeIds.Contains( a.AttributeId.Value ) )
.ToList() )
{
fieldList.Remove( formField );
}
}
// Perform Validation
var validationErrors = new List<string>();
if ( ( ( RegistrationTemplate.SetCostOnInstance ?? false ) || RegistrationTemplate.Cost > 0 || FeeState.Any() ) && !RegistrationTemplate.FinancialGatewayId.HasValue )
{
validationErrors.Add( "A Financial Gateway is required when the registration has a cost or additional fees or is configured to allow instances to set a cost." );
}
if ( validationErrors.Any() )
{
nbValidationError.Visible = true;
nbValidationError.Text = "<ul class='list-unstyled'><li>" + validationErrors.AsDelimited( "</li><li>" ) + "</li></ul>";
}
else
{
// Save the entity field changes to registration template
if ( RegistrationTemplate.Id.Equals( 0 ) )
示例4: ShowFormFieldEdit
/// <summary>
/// Shows the form field edit.
/// </summary>
/// <param name="formGuid">The form unique identifier.</param>
/// <param name="formFieldGuid">The form field unique identifier.</param>
private void ShowFormFieldEdit( Guid formGuid, Guid formFieldGuid )
{
if ( FormFieldsState.ContainsKey( formGuid ) )
{
ShowDialog( "Attributes" );
var fieldList = FormFieldsState[formGuid];
RegistrationTemplateFormField formField = fieldList.FirstOrDefault( a => a.Guid.Equals( formFieldGuid ) );
if ( formField == null )
{
formField = new RegistrationTemplateFormField();
formField.Guid = formFieldGuid;
formField.FieldSource = RegistrationFieldSource.PersonAttribute;
}
ceAttributePreText.Text = formField.PreText;
ceAttributePostText.Text = formField.PostText;
ddlFieldSource.SetValue( formField.FieldSource.ConvertToInt() );
ddlPersonField.SetValue( formField.PersonFieldType.ConvertToInt() );
lPersonField.Text = formField.PersonFieldType.ConvertToString();
ddlPersonAttributes.Items.Clear();
var person = new Person();
person.LoadAttributes();
foreach ( var attr in person.Attributes
.OrderBy( a => a.Value.Name )
.Select( a => a.Value ) )
{
if ( attr.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
ddlPersonAttributes.Items.Add( new ListItem( attr.Name, attr.Id.ToString() ) );
}
}
ddlGroupTypeAttributes.Items.Clear();
var group = new Group();
group.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0;
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.LoadAttributes();
foreach ( var attr in groupMember.Attributes
.OrderBy( a => a.Value.Name )
.Select( a => a.Value ) )
{
if ( attr.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
ddlGroupTypeAttributes.Items.Add( new ListItem( attr.Name, attr.Id.ToString() ) );
}
}
var attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
if ( formField.FieldSource == RegistrationFieldSource.PersonAttribute )
{
ddlPersonAttributes.SetValue( formField.AttributeId );
}
else if ( formField.FieldSource == RegistrationFieldSource.GroupMemberAttribute )
{
ddlGroupTypeAttributes.SetValue( formField.AttributeId );
}
else if ( formField.FieldSource == RegistrationFieldSource.RegistrationAttribute )
{
if ( formField.Attribute != null )
{
attribute = formField.Attribute;
}
}
edtRegistrationAttribute.SetAttributeProperties( attribute, typeof( RegistrationTemplate ) );
cbInternalField.Checked = formField.IsInternal;
cbShowOnGrid.Checked = formField.IsGridField;
cbRequireInInitialEntry.Checked = formField.IsRequired;
cbUsePersonCurrentValue.Checked = formField.ShowCurrentValue;
cbCommonValue.Checked = formField.IsSharedValue;
hfFormGuid.Value = formGuid.ToString();
hfAttributeGuid.Value = formFieldGuid.ToString();
lPersonField.Visible = formField.FieldSource == RegistrationFieldSource.PersonField && (
formField.PersonFieldType == RegistrationPersonFieldType.FirstName ||
formField.PersonFieldType == RegistrationPersonFieldType.LastName );
SetFieldDisplay();
}
BuildControls( true );
}
示例5: lbConnect_Click
/// <summary>
/// Handles the Click event of the lbConnect 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 lbConnect_Click( object sender, EventArgs e )
{
using ( var rockContext = new RockContext() )
{
var connectionRequestService = new ConnectionRequestService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var connectionActivityTypeService = new ConnectionActivityTypeService( rockContext );
var connectionRequestActivityService = new ConnectionRequestActivityService( rockContext );
var connectionRequest = connectionRequestService.Get( hfConnectionRequestId.ValueAsInt() );
if ( connectionRequest != null &&
connectionRequest.PersonAlias != null &&
connectionRequest.ConnectionOpportunity != null )
{
bool okToConnect = true;
GroupMember groupMember = null;
// Only do group member placement if the request has an assigned placement group, role, and status
if ( connectionRequest.AssignedGroupId.HasValue &&
connectionRequest.AssignedGroupMemberRoleId.HasValue &&
connectionRequest.AssignedGroupMemberStatus.HasValue )
{
var group = new GroupService( rockContext ).Get( connectionRequest.AssignedGroupId.Value );
if ( group != null )
{
// Only attempt the add if person does not already exist in group with same role
groupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId( connectionRequest.AssignedGroupId.Value,
connectionRequest.PersonAlias.PersonId, connectionRequest.AssignedGroupMemberRoleId.Value );
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.PersonId = connectionRequest.PersonAlias.PersonId;
groupMember.GroupId = connectionRequest.AssignedGroupId.Value;
groupMember.GroupRoleId = connectionRequest.AssignedGroupMemberRoleId.Value;
groupMember.GroupMemberStatus = connectionRequest.AssignedGroupMemberStatus.Value;
foreach ( ListItem item in cblManualRequirements.Items )
{
if ( !item.Selected && group.MustMeetRequirementsToAddMember.HasValue && group.MustMeetRequirementsToAddMember.Value )
{
okToConnect = false;
nbRequirementsErrors.Text = "Group Requirements have not been met. Please verify all of the requirements.";
nbRequirementsErrors.Visible = true;
break;
}
else
{
groupMember.GroupMemberRequirements.Add( new GroupMemberRequirement
{
GroupRequirementId = item.Value.AsInteger(),
RequirementMetDateTime = RockDateTime.Now,
LastRequirementCheckDateTime = RockDateTime.Now
} );
}
}
if ( okToConnect )
{
groupMemberService.Add( groupMember );
if ( !string.IsNullOrWhiteSpace( connectionRequest.AssignedGroupMemberAttributeValues ) )
{
var savedValues = JsonConvert.DeserializeObject<Dictionary<string, string>>( connectionRequest.AssignedGroupMemberAttributeValues );
if ( savedValues != null )
{
groupMember.LoadAttributes();
foreach ( var item in savedValues )
{
groupMember.SetAttributeValue( item.Key, item.Value );
}
}
}
}
}
}
}
if ( okToConnect )
{
// ... but always record the connection activity and change the state to connected.
var guid = Rock.SystemGuid.ConnectionActivityType.CONNECTED.AsGuid();
var connectedActivityId = connectionActivityTypeService.Queryable()
.Where( t => t.Guid == guid )
.Select( t => t.Id )
.FirstOrDefault();
if ( connectedActivityId > 0 )
{
var connectionRequestActivity = new ConnectionRequestActivity();
connectionRequestActivity.ConnectionRequestId = connectionRequest.Id;
connectionRequestActivity.ConnectionOpportunityId = connectionRequest.ConnectionOpportunityId;
connectionRequestActivity.ConnectionActivityTypeId = connectedActivityId;
connectionRequestActivity.ConnectorPersonAliasId = CurrentPersonAliasId;
connectionRequestActivityService.Add( connectionRequestActivity );
}
//.........这里部分代码省略.........
示例6: GetGroupMemberAttributeValues
private string GetGroupMemberAttributeValues()
{
var groupId = ddlPlacementGroup.SelectedValueAsInt();
var groupMemberRoleId = ddlPlacementGroupRole.SelectedValueAsInt();
var groupMemberStatus = ddlPlacementGroupStatus.SelectedValueAsEnumOrNull<GroupMemberStatus>();
var values = new Dictionary<string, string>();
if ( groupId.HasValue && groupMemberRoleId.HasValue && groupMemberStatus != null )
{
using ( var rockContext = new RockContext() )
{
var group = new GroupService( rockContext ).Get( groupId.Value );
var role = new GroupTypeRoleService( rockContext ).Get( groupMemberRoleId.Value );
if ( group != null && role != null )
{
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupId = group.Id;
groupMember.GroupRole = role;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = groupMemberStatus.Value;
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phGroupMemberAttributes, groupMember );
foreach( var attrValue in groupMember.AttributeValues )
{
values.Add( attrValue.Key, attrValue.Value.Value );
}
return JsonConvert.SerializeObject( values, Formatting.None );
}
}
}
return string.Empty;
}
示例7: BuildGroupMemberAttributes
private void BuildGroupMemberAttributes( int? groupId, int? groupMemberRoleId, GroupMemberStatus? groupMemberStatus, bool setValues )
{
phGroupMemberAttributes.Controls.Clear();
phGroupMemberAttributesView.Controls.Clear();
if ( groupId.HasValue && groupMemberRoleId.HasValue && groupMemberStatus != null )
{
using ( var rockContext = new RockContext() )
{
var group = new GroupService( rockContext ).Get( groupId.Value );
var role = new GroupTypeRoleService( rockContext ).Get( groupMemberRoleId.Value );
if ( group != null && role != null )
{
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupId = group.Id;
groupMember.GroupRole = role;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = groupMemberStatus.Value;
groupMember.LoadAttributes();
if ( setValues && !string.IsNullOrWhiteSpace( hfGroupMemberAttributeValues.Value ) )
{
var savedValues = JsonConvert.DeserializeObject<Dictionary<string, string>>( hfGroupMemberAttributeValues.Value );
if ( savedValues != null )
{
foreach( var item in savedValues )
{
groupMember.SetAttributeValue( item.Key, item.Value );
}
}
}
Rock.Attribute.Helper.AddEditControls( groupMember, phGroupMemberAttributes, setValues, BlockValidationGroup, 2 );
Rock.Attribute.Helper.AddDisplayControls( groupMember, phGroupMemberAttributesView, null, false, false );
}
}
}
}
示例8: OnLoad
/// <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 );
ClearErrorMessage();
if ( !Page.IsPostBack )
{
ShowDetail( PageParameter( "GroupMemberId" ).AsInteger(), PageParameter( "GroupId" ).AsIntegerOrNull() );
}
else
{
var groupMember = new GroupMember { GroupId = hfGroupId.ValueAsInt() };
if ( groupMember != null )
{
groupMember.LoadAttributes();
phAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( groupMember, phAttributes, false );
}
}
}
示例9: btnConfirm_Click
//.........这里部分代码省略.........
else
{
pw = phAttributesCol2.FindControl( controlId ) as PanelWidget;
}
categoryIndex++;
if ( pw != null )
{
var orderedAttributeList = new AttributeService( rockContext ).GetByCategoryId( category.Id )
.OrderBy( a => a.Order ).ThenBy( a => a.Name );
foreach ( var attribute in orderedAttributeList )
{
if ( attribute.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
var attributeCache = AttributeCache.Read( attribute.Id );
Control attributeControl = pw.FindControl( string.Format( "attribute_field_{0}", attribute.Id ) );
if ( attributeControl != null && SelectedFields.Contains( attributeControl.ClientID ) )
{
string newValue = attributeCache.FieldType.Field.GetEditValue( attributeControl, attributeCache.QualifierValues );
attributes.Add( attributeCache );
attributeValues.Add( attributeCache.Id, newValue );
}
}
}
}
}
if ( attributes.Any() )
{
foreach ( var person in people )
{
person.LoadAttributes();
foreach ( var attribute in attributes )
{
string originalValue = person.GetAttributeValue( attribute.Key );
string newValue = attributeValues[attribute.Id];
if ( ( originalValue ?? string.Empty ).Trim() != ( newValue ?? string.Empty ).Trim() )
{
Rock.Attribute.Helper.SaveAttributeValue( person, attribute, newValue, rockContext );
string formattedOriginalValue = string.Empty;
if ( !string.IsNullOrWhiteSpace( originalValue ) )
{
formattedOriginalValue = attribute.FieldType.Field.FormatValue( null, originalValue, attribute.QualifierValues, false );
}
string formattedNewValue = string.Empty;
if ( !string.IsNullOrWhiteSpace( newValue ) )
{
formattedNewValue = attribute.FieldType.Field.FormatValue( null, newValue, attribute.QualifierValues, false );
}
History.EvaluateChange( allChanges[person.Id], attribute.Name, formattedOriginalValue, formattedNewValue );
}
}
}
}
// Create the history records
foreach ( var changes in allChanges )
{
if ( changes.Value.Any() )
{
HistoryService.AddChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
示例10: BuildGroupAttributes
private void BuildGroupAttributes( Group group, RockContext rockContext, bool setValues )
{
if (group != null)
{
string action = ddlGroupAction.SelectedValue;
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupId = group.Id;
groupMember.LoadAttributes( rockContext );
foreach ( var attributeCache in groupMember.Attributes.Select( a => a.Value ) )
{
string labelText = attributeCache.Name;
bool controlEnabled = true;
if ( action == "Update" )
{
string clientId = string.Format( "{0}_attribute_field_{1}", phAttributes.NamingContainer.ClientID, attributeCache.Id );
controlEnabled = SelectedFields.Contains( clientId, StringComparer.OrdinalIgnoreCase );
string iconCss = controlEnabled ? "fa-check-circle-o" : "fa-circle-o";
labelText = string.Format( "<span class='js-select-item'><i class='fa {0}'></i></span> {1}", iconCss, attributeCache.Name );
}
Control control = attributeCache.AddControl( phAttributes.Controls, attributeCache.DefaultValue, string.Empty, setValues, true, attributeCache.IsRequired, labelText );
if ( action == "Update" && !( control is RockCheckBox ) )
{
var webControl = control as WebControl;
if ( webControl != null )
{
webControl.Enabled = controlEnabled;
}
}
}
}
}
示例11: btnComplete_Click
//.........这里部分代码省略.........
if ( attributeControl != null && SelectedFields.Contains( attributeControl.ClientID ) )
{
string newValue = attributeCache.FieldType.Field.GetEditValue( attributeControl, attributeCache.QualifierValues );
EvaluateChange( changes, attributeCache.Name, attributeCache.FieldType.Field.FormatValue( null, newValue, attributeCache.QualifierValues, false ) );
}
}
}
}
}
#endregion
#region Note
if ( !string.IsNullOrWhiteSpace( tbNote.Text ) && CurrentPerson != null )
{
changes.Add( string.Format( "Add a <span class='field-name'>{0}Note{1}</span> of <p><span class='field-value'>{2}</span></p>.",
( cbIsPrivate.Checked ? "Private " : "" ), ( cbIsAlert.Checked ? " (Alert)" : "" ), tbNote.Text.ConvertCrLfToHtmlBr() ) );
}
#endregion
#region Group
int? groupId = gpGroup.SelectedValue.AsIntegerOrNull();
if ( groupId.HasValue && groupId > 0 )
{
var group = new GroupService( rockContext ).Get( groupId.Value );
if ( group != null )
{
string action = ddlGroupAction.SelectedValue;
if ( action == "Remove" )
{
changes.Add( string.Format( "Remove from <span class='field-name'>{0}</span> group.", group.Name ) );
}
else if ( action == "Add")
{
changes.Add( string.Format( "Add to <span class='field-name'>{0}</span> group.", group.Name ) );
}
else // Update
{
if ( SelectedFields.Contains( ddlGroupRole.ClientID ) )
{
var roleId = ddlGroupRole.SelectedValueAsInt();
if ( roleId.HasValue )
{
var groupType = GroupTypeCache.Read( group.GroupTypeId );
var role = groupType.Roles.Where( r => r.Id == roleId.Value ).FirstOrDefault();
if ( role != null )
{
string field = string.Format( "{0} Role", group.Name );
EvaluateChange( changes, field, role.Name );
}
}
}
if ( SelectedFields.Contains( ddlGroupMemberStatus.ClientID ) )
{
string field = string.Format( "{0} Member Status", group.Name );
EvaluateChange( changes, field, ddlGroupMemberStatus.SelectedValueAsEnum<GroupMemberStatus>().ToString() );
}
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupId = group.Id;
groupMember.LoadAttributes( rockContext );
foreach ( var attributeCache in groupMember.Attributes.Select( a => a.Value ) )
{
Control attributeControl = phAttributes.FindControl( string.Format( "attribute_field_{0}", attributeCache.Id ) );
if ( attributeControl != null && SelectedFields.Contains( attributeControl.ClientID ) )
{
string field = string.Format( "{0}: {1}", group.Name, attributeCache.Name );
string newValue = attributeCache.FieldType.Field.GetEditValue( attributeControl, attributeCache.QualifierValues );
EvaluateChange( changes, field, attributeCache.FieldType.Field.FormatValue( null, newValue, attributeCache.QualifierValues, false ) );
}
}
}
}
}
#endregion
StringBuilder sb = new StringBuilder();
sb.AppendFormat( "<p>You are about to make the following updates to {0} individuals:</p>", Individuals.Count().ToString( "N0" ) );
sb.AppendLine();
sb.AppendLine( "<ul>" );
changes.ForEach( c => sb.AppendFormat("<li>{0}</li>\n", c));
sb.AppendLine( "</ul>" );
sb.AppendLine( "<p>Please confirm that you want to make these updates.</p>");
phConfirmation.Controls.Add( new LiteralControl( sb.ToString() ) );
pnlEntry.Visible = false;
pnlConfirm.Visible = true;
}
}
示例12: btnMoveRegistration_Click
protected void btnMoveRegistration_Click( object sender, EventArgs e )
{
// set the new registration id
using ( var rockContext = new RockContext() )
{
var registrationService = new RegistrationService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var registration = registrationService.Get( Registration.Id );
registration.RegistrationInstanceId = ddlNewRegistrationInstance.SelectedValue.AsInteger();
// Move registrants to new group
int? groupId = ddlMoveGroup.SelectedValueAsInt();
if ( groupId.HasValue )
{
registration.GroupId = groupId;
rockContext.SaveChanges();
var group = new GroupService( rockContext ).Get( groupId.Value );
if ( group != null )
{
int? groupRoleId = null;
var template = registration.RegistrationInstance.RegistrationTemplate;
if ( group.GroupTypeId == template.GroupTypeId && template.GroupMemberRoleId.HasValue )
{
groupRoleId = template.GroupMemberRoleId.Value;
}
if ( !groupRoleId.HasValue )
{
groupRoleId = group.GroupType.DefaultGroupRoleId;
}
if ( !groupRoleId.HasValue )
{
groupRoleId = group.GroupType.Roles.OrderBy( r => r.Order ).Select( r => r.Id ).FirstOrDefault();
}
if ( groupRoleId.HasValue )
{
foreach ( var registrant in registration.Registrants.Where( r => r.PersonAlias != null ) )
{
var newGroupMembers = groupMemberService.GetByGroupIdAndPersonId( groupId.Value, registrant.PersonAlias.PersonId );
if ( !newGroupMembers.Any() )
{
// Get any existing group member attribute values
var existingAttributeValues = new Dictionary<string, string>();
if ( registrant.GroupMemberId.HasValue )
{
var existingGroupMember = groupMemberService.Get( registrant.GroupMemberId.Value );
if ( existingGroupMember != null )
{
existingGroupMember.LoadAttributes( rockContext );
foreach ( var attributeValue in existingGroupMember.AttributeValues )
{
existingAttributeValues.Add( attributeValue.Key, attributeValue.Value.Value );
}
}
registrant.GroupMember = null;
groupMemberService.Delete( existingGroupMember );
}
var newGroupMember = new GroupMember();
groupMemberService.Add( newGroupMember );
newGroupMember.Group = group;
newGroupMember.PersonId = registrant.PersonAlias.PersonId;
newGroupMember.GroupRoleId = groupRoleId.Value;
rockContext.SaveChanges();
newGroupMember = groupMemberService.Get( newGroupMember.Id );
newGroupMember.LoadAttributes();
foreach( var attr in newGroupMember.Attributes )
{
if ( existingAttributeValues.ContainsKey( attr.Key ) )
{
newGroupMember.SetAttributeValue( attr.Key, existingAttributeValues[attr.Key] );
}
}
newGroupMember.SaveAttributeValues( rockContext );
registrant.GroupMember = newGroupMember;
rockContext.SaveChanges();
}
}
}
}
}
// Reload registration
Registration = GetRegistration( Registration.Id );
lWizardInstanceName.Text = Registration.RegistrationInstance.Name;
ShowReadonlyDetails( Registration );
}
mdMoveRegistration.Hide();
}
示例13: gpMoveGroupMember_SelectItem
/// <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;
}
}
示例14: btnMoveGroupMember_Click
/// <summary>
/// Handles the Click event of the btnMoveGroupMember 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 btnMoveGroupMember_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( hfGroupMemberId.Value.AsInteger() );
groupMember.LoadAttributes();
int destGroupId = gpMoveGroupMember.SelectedValue.AsInteger();
var destGroup = new GroupService( rockContext ).Get( destGroupId );
var destGroupMember = groupMemberService.Queryable().Where( a =>
a.GroupId == destGroupId
&& a.PersonId == groupMember.PersonId
&& a.GroupRoleId == grpMoveGroupMember.GroupRoleId ).FirstOrDefault();
if ( destGroupMember != null )
{
nbMoveGroupMemberWarning.Visible = true;
nbMoveGroupMemberWarning.Text = string.Format( "{0} is already in {1}", groupMember.Person, destGroupMember.Group );
return;
}
if ( !grpMoveGroupMember.GroupRoleId.HasValue )
{
nbMoveGroupMemberWarning.Visible = true;
nbMoveGroupMemberWarning.Text = string.Format( "Please select a Group Role" );
return;
}
string canDeleteWarning;
if ( !groupMemberService.CanDelete( groupMember, out canDeleteWarning ) )
{
nbMoveGroupMemberWarning.Visible = true;
nbMoveGroupMemberWarning.Text = string.Format( "Unable to remove {0} from {1}: {2}", groupMember.Person, groupMember.Group, canDeleteWarning );
return;
}
destGroupMember = new GroupMember();
destGroupMember.GroupId = destGroupId;
destGroupMember.GroupRoleId = grpMoveGroupMember.GroupRoleId.Value;
destGroupMember.PersonId = groupMember.PersonId;
destGroupMember.LoadAttributes();
foreach ( var attribute in groupMember.Attributes )
{
if ( destGroupMember.Attributes.Any( a => a.Key == attribute.Key && a.Value.FieldTypeId == attribute.Value.FieldTypeId ) )
{
destGroupMember.SetAttributeValue( attribute.Key, groupMember.GetAttributeValue( attribute.Key ) );
}
}
rockContext.WrapTransaction( () =>
{
groupMemberService.Add( destGroupMember );
rockContext.SaveChanges();
destGroupMember.SaveAttributeValues( rockContext );
// move any Note records that were associated with the old groupMember to the new groupMember record
if ( cbMoveGroupMemberMoveNotes.Checked )
{
destGroupMember.Note = groupMember.Note;
int groupMemberEntityTypeId = EntityTypeCache.GetId<Rock.Model.GroupMember>().Value;
var noteService = new NoteService( rockContext );
var groupMemberNotes = noteService.Queryable().Where( a => a.NoteType.EntityTypeId == groupMemberEntityTypeId && a.EntityId == groupMember.Id );
foreach ( var note in groupMemberNotes )
{
note.EntityId = destGroupMember.Id;
}
rockContext.SaveChanges();
}
groupMemberService.Delete( groupMember );
rockContext.SaveChanges();
destGroupMember.CalculateRequirements( rockContext, true );
} );
var queryString = new Dictionary<string, string>();
queryString.Add( "GroupMemberId", destGroupMember.Id.ToString() );
this.NavigateToPage( this.RockPage.Guid, queryString );
}
示例15: BuildGroupControls
private void BuildGroupControls( bool setValues )
{
ddlGroupRole.Items.Clear();
ddlGroupMemberStatus.Items.Clear();
phAttributes.Controls.Clear();
if ( bddlGroupAction.SelectedValue == "Remove" )
{
ddlGroupMemberStatus.Visible = false;
ddlGroupRole.Visible = false;
}
else
{
ddlGroupRole.Visible = true;
ddlGroupMemberStatus.Visible = true;
var rockContext = new RockContext();
Group group = null;
int? groupId = gpGroup.SelectedValueAsId();
if ( groupId.HasValue )
{
group = new GroupService( rockContext ).Get( groupId.Value );
}
if ( group != null )
{
var groupType = GroupTypeCache.Read( group.GroupTypeId );
ddlGroupRole.DataSource = groupType.Roles.OrderBy( r => r.Order ).ToList();
ddlGroupRole.DataBind();
ddlGroupMemberStatus.Items.Add( new ListItem( "Active", "1" ) );
ddlGroupMemberStatus.Items.Add( new ListItem( "Pending", "2" ) );
ddlGroupMemberStatus.Items.Add( new ListItem( "Inactive", "0" ) );
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupId = group.Id;
groupMember.LoadAttributes( rockContext );
Rock.Attribute.Helper.AddEditControls( groupMember, phAttributes, setValues, "", true );
}
else
{
ddlGroupRole.Items.Add( new ListItem( string.Empty, string.Empty ) );
ddlGroupMemberStatus.Items.Add( new ListItem( string.Empty, string.Empty ) );
}
}
}