本文整理汇总了C#中Rock.Model.GroupMemberService.GetInverseRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService.GetInverseRelationship方法的具体用法?C# GroupMemberService.GetInverseRelationship怎么用?C# GroupMemberService.GetInverseRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupMemberService
的用法示例。
在下文中一共展示了GroupMemberService.GetInverseRelationship方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowEditDetails
/// <summary>
/// Shows the edit details.
/// </summary>
/// <param name="business">The business.</param>
private void ShowEditDetails( Person business )
{
if ( business.Id > 0 )
{
lTitle.Text = ActionTitle.Edit( business.FullName ).FormatAsHtmlTitle();
tbBusinessName.Text = business.FirstName;
tbStreet1.Text = business.GivingGroup.GroupLocations.FirstOrDefault().Location.Street1;
tbStreet2.Text = business.GivingGroup.GroupLocations.FirstOrDefault().Location.Street2;
tbCity.Text = business.GivingGroup.GroupLocations.FirstOrDefault().Location.City;
ddlState.SelectedValue = business.GivingGroup.GroupLocations.FirstOrDefault().Location.State;
tbZipCode.Text = business.GivingGroup.GroupLocations.FirstOrDefault().Location.Zip;
pnbPhone.Text = business.PhoneNumbers.FirstOrDefault().ToString();
cbSms.Checked = business.PhoneNumbers.FirstOrDefault().IsMessagingEnabled;
cbUnlisted.Checked = business.PhoneNumbers.FirstOrDefault().IsUnlisted;
tbEmail.Text = business.Email;
rblEmailPreference.SelectedValue = business.EmailPreference.ToString();
ddlCampus.SelectedValue = business.GivingGroup.CampusId.ToString();
var rockContext = new RockContext();
var groupMemberService = new GroupMemberService( rockContext );
var knownRelationshipBusinessGroupMember = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS ) ) &&
g.PersonId == business.Id )
.FirstOrDefault();
if ( knownRelationshipBusinessGroupMember != null )
{
var inverseGroupMember = groupMemberService.GetInverseRelationship( knownRelationshipBusinessGroupMember, false, CurrentPersonAlias );
if ( inverseGroupMember != null )
{
ppOwner.PersonId = inverseGroupMember.Person.Id;
ppOwner.PersonName = inverseGroupMember.Person.FullName;
}
}
ddlGivingGroup.SelectedValue = business.Id.ToString();
ddlRecordStatus.SelectedValue = business.RecordStatusValueId.HasValue ? business.RecordStatusValueId.Value.ToString() : string.Empty;
ddlReason.SelectedValue = business.RecordStatusReasonValueId.HasValue ? business.RecordStatusReasonValueId.Value.ToString() : string.Empty;
ddlReason.Visible = business.RecordStatusReasonValueId.HasValue &&
business.RecordStatusValueId.Value == DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ) ).Id;
}
else
{
lTitle.Text = ActionTitle.Add( "Business" ).FormatAsHtmlTitle();
}
SetEditMode( true );
}
示例2: AddRelationships
//.........这里部分代码省略.........
break;
case "invited-by":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "previous-spouse":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_PREVIOUS_SPOUSE.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "sibling":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_SIBLING.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "parent":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_PARENT.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "child":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CHILD.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "related":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_IMPLIED_RELATIONSHIPS_RELATED.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
default:
//// throw new NotSupportedException( string.Format( "unknown relationship type {0}", elemRelationship.Attribute( "has" ).Value ) );
// just skip unknown relationship types
continue;
}
// find the person's KnownRelationship "owner" group
var knownRelationshipGroup = memberService.Queryable()
.Where( m =>
m.PersonId == ownerPersonId &&
m.GroupRole.Guid == ownerRoleGuid )
.Select( m => m.Group )
.FirstOrDefault();
// create it if it does not yet exist
if ( knownRelationshipGroup == null )
{
var ownerRole = new GroupTypeRoleService( rockContext ).Get( ownerRoleGuid );
if ( ownerRole != null && ownerRole.GroupTypeId.HasValue )
{
var ownerGroupMember = new GroupMember();
ownerGroupMember.PersonId = ownerPersonId;
ownerGroupMember.GroupRoleId = ownerRole.Id;
knownRelationshipGroup = new Group();
knownRelationshipGroup.Name = ownerRole.GroupType.Name;
knownRelationshipGroup.GroupTypeId = ownerRole.GroupTypeId.Value;
knownRelationshipGroup.Members.Add( ownerGroupMember );
var groupService = new GroupService( rockContext );
groupService.Add( knownRelationshipGroup );
//rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
knownRelationshipGroup = groupService.Get( knownRelationshipGroup.Id );
}
}
// Now find (and add if not found) the forPerson as a member with the "has" role-type
var groupMember = memberService.Queryable()
.Where( m =>
m.GroupId == knownRelationshipGroup.Id &&
m.PersonId == forPersonId &&
m.GroupRoleId == roleId )
.FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember()
{
GroupId = knownRelationshipGroup.Id,
PersonId = forPersonId,
GroupRoleId = roleId,
};
rockContext.GroupMembers.Add( groupMember );
}
// Now create thee inverse relationship.
//
// (NOTE: Don't panic if your VS tooling complains that there is
// an unused variable here. There is no need to do anything with the
// inverseGroupMember relationship because it was already added to the
// context. All we have to do below is save the changes to the context
// when we're ready.)
var inverseGroupMember = memberService.GetInverseRelationship( groupMember, createGroup: true );
}
}
示例3: 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();
}
}
}
}
示例4: SetOwner
/// <summary>
/// Sets the owner.
/// </summary>
/// <param name="business">The business.</param>
private void SetOwner( Person business )
{
var rockContext = new RockContext();
var groupMemberService = new GroupMemberService( rockContext );
// Find the original owner/business relationships and remove them if they've changed
var ownersKnownRelationshipGroupMember = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS ) ) &&
g.PersonId == business.Id )
.FirstOrDefault();
if ( ownersKnownRelationshipGroupMember != null )
{
var businessesKnownRelationshipGroupMember = groupMemberService.GetInverseRelationship( ownersKnownRelationshipGroupMember, false, CurrentPersonAlias );
if ( ppOwner.PersonId != businessesKnownRelationshipGroupMember.PersonId )
{
// the id of the person in the owner person picker doesn't match the id of the person in the businesses known relationship group with the principle role.
var ownersKnownRelationshipGroup = ownersKnownRelationshipGroupMember.Group;
ownersKnownRelationshipGroup.Members.Remove( ownersKnownRelationshipGroupMember );
groupMemberService.Delete( ownersKnownRelationshipGroupMember );
var businessesKnownRelationshipGroup = businessesKnownRelationshipGroupMember.Group;
businessesKnownRelationshipGroup.Members.Remove( businessesKnownRelationshipGroupMember );
groupMemberService.Delete( businessesKnownRelationshipGroupMember );
rockContext.SaveChanges();
SetRelationships( business );
}
}
else
{
SetRelationships( business );
}
}
示例5: modalAddPerson_SaveClick
void modalAddPerson_SaveClick( object sender, EventArgs e )
{
if ( ppPerson.PersonId.HasValue )
{
int? roleId = grpRole.GroupRoleId;
if ( roleId.HasValue )
{
var rockContext = new RockContext();
var memberService = new GroupMemberService( rockContext );
var group = memberService.Queryable()
.Where( m =>
m.PersonId == Person.Id &&
m.GroupRole.Guid == ownerRoleGuid
)
.Select( m => m.Group )
.FirstOrDefault();
if ( group != null )
{
GroupMember groupMember = null;
int? groupMemberId = hfRoleId.Value.AsIntegerOrNull();
if ( groupMemberId.HasValue )
{
groupMember = memberService.Queryable()
.Where( m => m.Id == groupMemberId.Value )
.FirstOrDefault();
}
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.GroupId = group.Id;
memberService.Add( groupMember );
}
GroupMember formerInverseGroupMember = null;
if ( IsKnownRelationships )
{
formerInverseGroupMember = memberService.GetInverseRelationship( groupMember, false, CurrentPersonAlias );
}
groupMember.PersonId = ppPerson.PersonId.Value;
groupMember.GroupRoleId = roleId.Value;
rockContext.SaveChanges();
if ( IsKnownRelationships )
{
var inverseGroupMember = memberService.GetInverseRelationship(
groupMember, bool.Parse( GetAttributeValue( "CreateGroup" ) ), CurrentPersonAlias );
if ( inverseGroupMember != null )
{
rockContext.SaveChanges();
if ( formerInverseGroupMember != null && formerInverseGroupMember.Id != inverseGroupMember.Id )
{
memberService.Delete( formerInverseGroupMember );
rockContext.SaveChanges();
}
}
}
}
}
}
HideDialog();
BindData();
}
示例6: gBusinessList_RowDataBound
/// <summary>
/// Handles the RowDataBound event of the gBusinessList control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
protected void gBusinessList_RowDataBound( object sender, GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
var rockContext = new RockContext();
var business = e.Row.DataItem as Person;
int? ownerRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) ) )
.Select( r => r.Id )
.FirstOrDefault();
var groupMemberService = new GroupMemberService( rockContext );
var knownRelationshipBusinessGroupMember = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS ) ) &&
g.PersonId == business.Id )
.FirstOrDefault();
if ( knownRelationshipBusinessGroupMember != null )
{
var inverseGroupMember = groupMemberService.GetInverseRelationship( knownRelationshipBusinessGroupMember, false, CurrentPersonAlias );
if ( inverseGroupMember != null )
{
Label lblOwner = e.Row.FindControl( "lblOwner" ) as Label;
lblOwner.Text = inverseGroupMember.Person.FullName;
}
}
var phoneNumber = business.PhoneNumbers.FirstOrDefault().NumberFormatted;
if ( !string.IsNullOrWhiteSpace( phoneNumber ) )
{
Label lblPhoneNumber = e.Row.FindControl( "lblPhoneNumber" ) as Label;
if ( lblPhoneNumber != null )
{
lblPhoneNumber.Text = string.Format( "{0}</br>", phoneNumber );
}
}
if ( !string.IsNullOrWhiteSpace( business.Email ) )
{
Label lblEmail = e.Row.FindControl( "lblEmail" ) as Label;
if ( lblEmail != null )
{
lblEmail.Text = string.Format( "{0}", business.Email );
}
}
var location = business.GivingGroup.GroupLocations.FirstOrDefault().Location;
if ( !string.IsNullOrWhiteSpace( location.Street1 ) )
{
Label lblStreet1 = e.Row.FindControl( "lblStreet1" ) as Label;
if ( lblStreet1 != null )
{
lblStreet1.Text = string.Format( "{0}</br>", location.Street1 );
}
}
if ( !string.IsNullOrWhiteSpace( location.Street2 ) )
{
Label lblStreet2 = e.Row.FindControl( "lblStreet2" ) as Label;
if ( lblStreet2 != null )
{
lblStreet2.Text = string.Format( "{0}</br>", location.Street2 );
}
}
if ( !string.IsNullOrWhiteSpace( location.City ) || !string.IsNullOrWhiteSpace( location.State ) || !string.IsNullOrWhiteSpace( location.Zip ) )
{
Label lblCityStateZip = e.Row.FindControl( "lblCityStateZip" ) as Label;
if ( lblCityStateZip != null )
{
lblCityStateZip.Text = string.Format( "{0}, {1} {2}", location.City, location.State, location.Zip );
}
}
}
}
示例7: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
private void BindGrid()
{
var rockContext = new RockContext();
var recordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid() ).Id;
var activeRecordStatusValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid() ).Id;
int? businessRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS ) ) )
.Select( r => r.Id )
.FirstOrDefault();
var queryable = new PersonService( rockContext ).Queryable()
.Where( q => q.RecordTypeValueId == recordTypeValueId && q.RecordStatusValueId == activeRecordStatusValueId );
// Business Name Filter
var businessName = gfBusinessFilter.GetUserPreference( "Business Name" );
if ( !string.IsNullOrWhiteSpace( businessName ) )
{
queryable = queryable.Where( a => a.FirstName.Contains( businessName ) );
}
// Owner Filter
int ownerId = 0;
if ( int.TryParse( gfBusinessFilter.GetUserPreference( "Owner" ), out ownerId ) && ownerId != 0 )
{
var members = queryable.SelectMany( a => a.Members ).ToList();
foreach ( var member in members )
{
if ( member.GroupRoleId == businessRoleId )
{
var groupMemberService = new GroupMemberService( rockContext );
var owner = groupMemberService.GetInverseRelationship( member, false, CurrentPersonAlias );
if ( owner.PersonId != ownerId )
{
queryable = queryable.Where( a => a.Id != member.PersonId );
}
}
}
}
SortProperty sortProperty = gBusinessList.SortProperty;
if ( sortProperty != null )
{
gBusinessList.DataSource = queryable.Sort( sortProperty ).ToList();
}
else
{
gBusinessList.DataSource = queryable.OrderBy( q => q.FirstName ).ToList();
}
gBusinessList.DataBind();
}
示例8: 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();
}
}
}
}
}
示例9: modalAddPerson_SaveClick
void modalAddPerson_SaveClick( object sender, EventArgs e )
{
if (!string.IsNullOrWhiteSpace(acPerson.Value))
{
int personId = int.MinValue;
if ( int.TryParse( acPerson.Value, out personId ) )
{
int? roleId = grpRole.GroupRoleId;
if ( roleId.HasValue )
{
using ( new UnitOfWorkScope() )
{
var memberService = new GroupMemberService();
var group = memberService.Queryable()
.Where( m =>
m.PersonId == Person.Id &&
m.GroupRole.Guid == ownerRoleGuid
)
.Select( m => m.Group )
.FirstOrDefault();
if ( group != null )
{
var groupMember = memberService.Queryable()
.Where( m =>
m.GroupId == group.Id &&
m.PersonId == personId &&
m.GroupRoleId == roleId.Value )
.FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.GroupId = group.Id;
groupMember.PersonId = personId;
groupMember.GroupRoleId = roleId.Value;
memberService.Add( groupMember, CurrentPersonId );
}
memberService.Save( groupMember, CurrentPersonId );
if ( IsKnownRelationships )
{
var inverseGroupMember = memberService.GetInverseRelationship(
groupMember, bool.Parse( GetAttributeValue( "CreateGroup" ) ), CurrentPersonId );
if ( inverseGroupMember != null )
{
memberService.Save( inverseGroupMember, CurrentPersonId );
}
}
}
}
}
}
}
BindData();
}