本文整理汇总了C#中Rock.Model.GroupMemberService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService.Get方法的具体用法?C# GroupMemberService.Get怎么用?C# GroupMemberService.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupMemberService
的用法示例。
在下文中一共展示了GroupMemberService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnCancel_Click
/// <summary>
/// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
{
if ( hfGroupMemberId.Value.Equals( "0" ) )
{
// Cancelling on Add.
Dictionary<string, string> qryString = new Dictionary<string, string>();
qryString["GroupId"] = hfGroupId.Value;
NavigateToParentPage( qryString );
}
else
{
// Cancelling on Edit. Return to Details
GroupMemberService groupMemberService = new GroupMemberService( new RockContext() );
GroupMember groupMember = groupMemberService.Get( int.Parse( hfGroupMemberId.Value ) );
Dictionary<string, string> qryString = new Dictionary<string, string>();
qryString["GroupId"] = groupMember.GroupId.ToString();
NavigateToParentPage( qryString );
}
}
示例2: DisplayEditGroupMember
/// <summary>
/// Displays the edit group member.
/// </summary>
/// <param name="groupMemberId">The group member identifier.</param>
private void DisplayEditGroupMember( int groupMemberId )
{
// persist the group member id for use in partial postbacks
this.CurrentGroupMemberId = groupMemberId;
pnlGroupEdit.Visible = false;
pnlGroupView.Visible = false;
pnlEditGroupMember.Visible = true;
RockContext rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( groupMemberId );
if ( groupMember == null )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = _groupId;
groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId );
groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
// load dropdowns
LoadGroupMemberDropDowns( _groupId );
// set values
ppGroupMemberPerson.SetValue( groupMember.Person );
ddlGroupRole.SetValue( groupMember.GroupRoleId );
rblStatus.SetValue( (int)groupMember.GroupMemberStatus );
bool hideGroupMemberInactiveStatus = this.GetAttributeValue( "HideInactiveGroupMemberStatus" ).AsBooleanOrNull() ?? false;
if ( hideGroupMemberInactiveStatus )
{
var inactiveItem = rblStatus.Items.FindByValue( ( (int)GroupMemberStatus.Inactive ).ToString() );
if ( inactiveItem != null )
{
rblStatus.Items.Remove( inactiveItem );
}
}
// set attributes
groupMember.LoadAttributes();
phGroupMemberAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( groupMember, phGroupMemberAttributes, true, string.Empty, true );
this.IsEditingGroupMember = true;
}
示例3: btnSave_Click
/// <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 )
{
if ( Page.IsValid )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMemberRequirementService groupMemberRequirementService = new GroupMemberRequirementService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
// check to see if the user selected a role
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = hfGroupId.ValueAsInt();
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.Note = tbNote.Text;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
if ( cbIsNotified.Visible )
{
groupMember.IsNotified = cbIsNotified.Checked;
}
if ( pnlRequirements.Visible )
{
foreach ( var checkboxItem in cblManualRequirements.Items.OfType<ListItem>() )
{
int groupRequirementId = checkboxItem.Value.AsInteger();
var groupMemberRequirement = groupMember.GroupMemberRequirements.FirstOrDefault( a => a.GroupRequirementId == groupRequirementId );
bool metRequirement = checkboxItem.Selected;
if ( metRequirement )
{
if ( groupMemberRequirement == null )
{
groupMemberRequirement = new GroupMemberRequirement();
groupMemberRequirement.GroupRequirementId = groupRequirementId;
groupMember.GroupMemberRequirements.Add( groupMemberRequirement );
}
// set the RequirementMetDateTime if it hasn't been set already
groupMemberRequirement.RequirementMetDateTime = groupMemberRequirement.RequirementMetDateTime ?? RockDateTime.Now;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
else
{
if ( groupMemberRequirement != null )
{
// doesn't meets the requirement
groupMemberRequirement.RequirementMetDateTime = null;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
}
}
}
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
// if the groupMember IsValue is false, and the UI controls didn't report any errors, it is probably because the custom rules of GroupMember didn't pass.
// So, make sure a message is displayed in the validation summary
cvGroupMember.IsValid = groupMember.IsValid;
if ( !cvGroupMember.IsValid )
{
cvGroupMember.ErrorMessage = groupMember.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
//.........这里部分代码省略.........
示例4: LoadViewState
/// <summary>
/// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
/// </summary>
/// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
protected override void LoadViewState( object savedState )
{
base.LoadViewState( savedState );
if ( IsEditingGroup == true )
{
Group group = new GroupService( new RockContext() ).Get( _groupId );
group.LoadAttributes();
phAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( group, phAttributes, false, BlockValidationGroup );
}
if ( IsEditingGroupMember == true )
{
RockContext rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( this.CurrentGroupMemberId );
if ( groupMember == null )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = _groupId;
groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId );
groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
// set attributes
groupMember.LoadAttributes();
phGroupMemberAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( groupMember, phGroupMemberAttributes, true, string.Empty, true );
}
}
示例5: DeleteGroupMember
/// <summary>
/// Deletes the group member.
/// </summary>
/// <param name="groupMemberId">The group member identifier.</param>
private void DeleteGroupMember( int groupMemberId )
{
RockContext rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( groupMemberId );
if ( groupMember != null )
{
groupMemberService.Delete( groupMember );
}
rockContext.SaveChanges();
}
示例6: mdPlaceElsewhere_SaveClick
/// <summary>
/// Handles the SaveClick event of the mdPlaceElsewhere 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 mdPlaceElsewhere_SaveClick( object sender, EventArgs e )
{
using ( var rockContext = new RockContext() )
{
var groupService = new GroupService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( hfPlaceElsewhereGroupMemberId.Value.AsInteger() );
if ( groupMember != null )
{
string errorMessage;
if ( !groupMemberService.CanDelete( groupMember, out errorMessage ) )
{
nbPlaceElsewhereWarning.Text = errorMessage;
return;
}
var trigger = _group.GetGroupMemberWorkflowTriggers().FirstOrDefault( a => a.Id == hfPlaceElsewhereTriggerId.Value.AsInteger() );
if ( trigger != null )
{
// create a transaction for the selected trigger
var transaction = new Rock.Transactions.GroupMemberPlacedElsewhereTransaction( groupMember, tbPlaceElsewhereNote.Text, trigger );
// delete the group member from the current group
groupMemberService.Delete( groupMember );
rockContext.SaveChanges();
// queue up the transaction
Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
}
}
mdPlaceElsewhere.Hide();
mdPlaceElsewhere.Visible = false;
BindGroupMembersGrid();
}
}
示例7: btnSaveGroupMember_Click
protected void btnSaveGroupMember_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
var groupMember = groupMemberService.Get( this.CurrentGroupMemberId );
if ( this.CurrentGroupMemberId == 0 )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = _groupId;
// check to see if the person is alread a member of the gorup/role
var existingGroupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId(
_groupId, ppGroupMemberPerson.SelectedValue ?? 0, ddlGroupRole.SelectedValueAsId() ?? 0 );
if ( existingGroupMember != null )
{
// if so, don't add and show error message
var person = new PersonService( rockContext ).Get( (int)ppGroupMemberPerson.PersonId );
nbGroupMemberErrorMessage.Title = "Person Already In Group";
nbGroupMemberErrorMessage.Text = string.Format(
"{0} already belongs to the {1} role for this {2}, and cannot be added again with the same role.",
person.FullName,
ddlGroupRole.SelectedItem.Text,
role.GroupType.GroupTerm,
RockPage.PageId,
existingGroupMember.Id );
return;
}
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
// using WrapTransaction because there are two Saves
rockContext.WrapTransaction( () =>
{
if ( groupMember.Id.Equals( 0 ) )
{
groupMemberService.Add( groupMember );
}
rockContext.SaveChanges();
groupMember.SaveAttributeValues( rockContext );
} );
Group group = new GroupService( rockContext ).Get( groupMember.GroupId );
if ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
pnlEditGroupMember.Visible = false;
pnlGroupView.Visible = true;
DisplayViewGroup();
this.IsEditingGroupMember = false;
}
示例8: btnSave_Click
/// <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 )
{
ClearErrorMessage();
if ( Page.IsValid )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
// check to see if the user selected a role
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = hfGroupId.ValueAsInt();
// check to see if the person is alread a member of the gorup/role
var existingGroupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId(
hfGroupId.ValueAsInt(), ppGroupMemberPerson.SelectedValue ?? 0, ddlGroupRole.SelectedValueAsId() ?? 0 );
if ( existingGroupMember != null )
{
// if so, don't add and show error message
var person = new PersonService( rockContext ).Get( (int)ppGroupMemberPerson.PersonId );
nbErrorMessage.Title = "Person already added";
nbErrorMessage.Text = string.Format(
"{0} already belongs to the {1} role for this {2}, and cannot be added again with the same role. <a href=\"/page/{3}?groupMemberId={4}\">Click here</a> to view existing membership.",
person.FullName,
ddlGroupRole.SelectedItem.Text,
role.GroupType.GroupTerm,
RockPage.PageId,
existingGroupMember.Id );
return;
}
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
int memberCountInRole = new GroupMemberService( rockContext ).Queryable()
.Where( m =>
m.GroupId == groupMember.GroupId &&
m.GroupRoleId == role.Id &&
m.GroupMemberStatus == GroupMemberStatus.Active )
.Count();
bool roleMembershipAboveMax = false;
// if adding new active group member..
if ( groupMemberId.Equals( 0 ) && rblStatus.SelectedValueAsEnum<GroupMemberStatus>() == GroupMemberStatus.Active )
{
// verify that active count has not exceeded the max
if ( role.MaxCount != null && ( memberCountInRole + 1 ) > role.MaxCount )
{
roleMembershipAboveMax = true;
}
}
else if ( groupMemberId > 0 && ( groupMember.GroupRoleId != role.Id || groupMember.GroupMemberStatus != rblStatus.SelectedValueAsEnum<GroupMemberStatus>() )
&& rblStatus.SelectedValueAsEnum<GroupMemberStatus>() == GroupMemberStatus.Active )
{
// if existing group member changing role or status..
// verify that active count has not exceeded the max
if ( role.MaxCount != null && ( memberCountInRole + 1 ) > role.MaxCount )
{
roleMembershipAboveMax = true;
}
}
// show error if above max.. do not proceed
if ( roleMembershipAboveMax )
{
var person = new PersonService( rockContext ).Get( (int)ppGroupMemberPerson.PersonId );
nbErrorMessage.Title = string.Format( "Maximum {0} Exceeded", role.Name.Pluralize() );
nbErrorMessage.Text = string.Format(
"<br />The number of {0} for this {1} is at or above its maximum allowed limit of {2:N0} active {3}.",
role.Name.Pluralize(),
role.GroupType.GroupTerm,
role.MaxCount,
role.MaxCount == 1 ? role.GroupType.GroupMemberTerm : role.GroupType.GroupMemberTerm.Pluralize() );
//.........这里部分代码省略.........
示例9: rGroupMembers_ItemCommand
void rGroupMembers_ItemCommand( object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e )
{
int groupMemberId = int.MinValue;
if ( int.TryParse( e.CommandArgument.ToString(), out groupMemberId ) )
{
var rockContext = new RockContext();
var service = new GroupMemberService( rockContext );
var groupMember = service.Get( groupMemberId );
if ( groupMember != null )
{
if ( e.CommandName == "EditRole" )
{
ShowModal(groupMember.Person, groupMember.GroupRoleId, groupMemberId);
}
else if ( e.CommandName == "RemoveRole" )
{
if ( IsKnownRelationships )
{
var inverseGroupMember = service.GetInverseRelationship( groupMember, false, CurrentPersonAlias );
if ( inverseGroupMember != null )
{
service.Delete( inverseGroupMember );
}
}
service.Delete( groupMember );
rockContext.SaveChanges();
BindData();
}
}
}
}
示例10: SaveGroupMember
private void SaveGroupMember()
{
if ( Page.IsValid )
{
var rockContext = new RockContext();
// Verify valid group
var groupService = new GroupService( rockContext );
var group = groupService.Get( hfGroupId.ValueAsInt() );
if ( group == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// Check to see if a person was selected
int? personId = ppGroupMemberPerson.PersonId;
int? personAliasId = ppGroupMemberPerson.PersonAliasId;
if ( !personId.HasValue || !personAliasId.HasValue )
{
nbErrorMessage.Title = "Please select a Person";
return;
}
// check to see if the user selected a role
var role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
var groupMemberService = new GroupMemberService( rockContext );
var groupMemberRequirementService = new GroupMemberRequirementService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = group.Id;
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = personId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.Note = tbNote.Text;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
if ( cbIsNotified.Visible )
{
groupMember.IsNotified = cbIsNotified.Checked;
}
if ( pnlRequirements.Visible )
{
foreach ( var checkboxItem in cblManualRequirements.Items.OfType<ListItem>() )
{
int groupRequirementId = checkboxItem.Value.AsInteger();
var groupMemberRequirement = groupMember.GroupMemberRequirements.FirstOrDefault( a => a.GroupRequirementId == groupRequirementId );
bool metRequirement = checkboxItem.Selected;
if ( metRequirement )
{
if ( groupMemberRequirement == null )
{
groupMemberRequirement = new GroupMemberRequirement();
groupMemberRequirement.GroupRequirementId = groupRequirementId;
groupMember.GroupMemberRequirements.Add( groupMemberRequirement );
}
// set the RequirementMetDateTime if it hasn't been set already
groupMemberRequirement.RequirementMetDateTime = groupMemberRequirement.RequirementMetDateTime ?? RockDateTime.Now;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
else
{
if ( groupMemberRequirement != null )
{
// doesn't meets the requirement
groupMemberRequirement.RequirementMetDateTime = null;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
}
}
}
if ( group.RequiredSignatureDocumentTemplate != null )
{
var person = new PersonService( rockContext ).Get( personId.Value );
var documentService = new SignatureDocumentService( rockContext );
var binaryFileService = new BinaryFileService( rockContext );
//.........这里部分代码省略.........
示例11: 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();
}
示例12: 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 );
}
示例13: rGroupMembers_ItemCommand
/// <summary>
/// Handles the ItemCommand event of the rGroupMembers control.
/// </summary>
/// <param name="source">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
protected void rGroupMembers_ItemCommand( object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e )
{
if ( CanEdit )
{
int groupMemberId = e.CommandArgument.ToString().AsIntegerOrNull() ?? 0;
if ( groupMemberId != 0 )
{
var rockContext = new RockContext();
var service = new GroupMemberService( rockContext );
var groupMember = service.Get( groupMemberId );
if ( groupMember != null )
{
if ( e.CommandName == "EditRole" )
{
ShowModal( groupMember.Person, groupMember.GroupRoleId, groupMemberId );
}
else if ( e.CommandName == "RemoveRole" )
{
if ( IsKnownRelationships )
{
var inverseGroupMember = service.GetInverseRelationship( groupMember, false );
if ( inverseGroupMember != null )
{
service.Delete( inverseGroupMember );
}
}
service.Delete( groupMember );
rockContext.SaveChanges();
BindData();
}
}
}
}
}
示例14: DisplayEditGroupMember
private void DisplayEditGroupMember( int groupMemberId )
{
// persist the group member id for use in partial postbacks
this.CurrentGroupMemberId = groupMemberId;
pnlGroupEdit.Visible = false;
pnlGroupView.Visible = false;
pnlEditGroupMember.Visible = true;
RockContext rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService.Get( groupMemberId );
if ( groupMember == null )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = _groupId;
groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId );
groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
// load dropdowns
LoadGroupMemberDropDowns( _groupId );
// set values
ppGroupMemberPerson.SetValue( groupMember.Person );
ddlGroupRole.SetValue( groupMember.GroupRoleId );
rblStatus.SetValue( (int)groupMember.GroupMemberStatus );
// set attributes
groupMember.LoadAttributes();
phGroupMemberAttributes.Controls.Clear();
Rock.Attribute.Helper.AddEditControls( groupMember, phGroupMemberAttributes, true, "", true );
this.IsEditingGroupMember = true;
}
示例15: btnSave_Click
/// <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 )
{
if ( Page.IsValid )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
// check to see if the user selected a role
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = hfGroupId.ValueAsInt();
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
cvGroupMember.IsValid = groupMember.IsValid;
if ( !cvGroupMember.IsValid )
{
cvGroupMember.ErrorMessage = groupMember.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
// using WrapTransaction because there are two Saves
rockContext.WrapTransaction( () =>
{
if ( groupMember.Id.Equals( 0 ) )
{
groupMemberService.Add( groupMember );
}
rockContext.SaveChanges();
groupMember.SaveAttributeValues( rockContext );
} );
Group group = new GroupService( rockContext ).Get( groupMember.GroupId );
if ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
}
Dictionary<string, string> qryString = new Dictionary<string, string>();
qryString["GroupId"] = hfGroupId.Value;
NavigateToParentPage( qryString );
}