本文整理汇总了C#中Rock.Model.GroupTypeRoleService类的典型用法代码示例。如果您正苦于以下问题:C# GroupTypeRoleService类的具体用法?C# GroupTypeRoleService怎么用?C# GroupTypeRoleService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GroupTypeRoleService类属于Rock.Model命名空间,在下文中一共展示了GroupTypeRoleService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatSelection
/// <summary>
/// Formats the selection.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override string FormatSelection( Type entityType, string selection )
{
string result = "Group Member";
string[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 2 )
{
var rockContext = new RockContext();
var group = new GroupService( rockContext ).Get( selectionValues[0].AsGuid() );
var groupTypeRoleGuidList = selectionValues[1].Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).Select( a => a.AsGuid() ).ToList();
var groupTypeRoles = new GroupTypeRoleService( rockContext ).Queryable().Where( a => groupTypeRoleGuidList.Contains( a.Guid ) ).ToList();
if ( group != null )
{
result = string.Format( "Not in group: {0}", group.Name );
if ( groupTypeRoles.Count() > 0 )
{
result += string.Format( ", with role(s): {0}", groupTypeRoles.Select( a => a.Name ).ToList().AsDelimited( "," ) );
}
}
}
return result;
}
示例2: FormatValue
/// <summary>
/// Returns the field's current value(s)
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="value">Information about the value</param>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
/// <returns></returns>
public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
{
string formattedValue = string.Empty;
Guid guid = Guid.Empty;
if ( Guid.TryParse( value, out guid ) )
{
var groupRole = new GroupTypeRoleService( new RockContext() ).Get( guid );
if ( groupRole != null )
{
formattedValue = groupRole.Name;
}
}
return base.FormatValue( parentControl, formattedValue, null, condensed );
}
示例3: OnInit
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
var campusi = new CampusService().Queryable().OrderBy( a => a.Name ).ToList();
cpCampus.Campuses = campusi;
cpCampus.Visible = campusi.Any();
var childRole = new GroupTypeRoleService().Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) );
if ( childRole != null )
{
_childRoleId = childRole.Id;
}
bool.TryParse( GetAttributeValue( "Gender" ), out _requireGender );
bool.TryParse( GetAttributeValue( "Grade" ), out _requireGrade );
bool showNickName = false;
nfmMembers.ShowNickName = bool.TryParse( GetAttributeValue( "NickName" ), out showNickName ) && showNickName;
lTitle.Text = ("Add Family").FormatAsHtmlTitle();
}
示例4: 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 )
{
GroupType groupType;
var rockContext = new RockContext();
GroupTypeService groupTypeService = new GroupTypeService( rockContext );
GroupTypeRoleService groupTypeRoleService = new GroupTypeRoleService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService qualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
GroupScheduleExclusionService scheduleExclusionService = new GroupScheduleExclusionService( rockContext );
int groupTypeId = int.Parse( hfGroupTypeId.Value );
if ( groupTypeId == 0 )
{
groupType = new GroupType();
groupTypeService.Add( groupType );
}
else
{
groupType = groupTypeService.Get( groupTypeId );
// selected roles
var selectedRoleGuids = GroupTypeRolesState.Select( r => r.Guid );
foreach ( var role in groupType.Roles.Where( r => !selectedRoleGuids.Contains( r.Guid ) ).ToList() )
{
groupType.Roles.Remove( role );
groupTypeRoleService.Delete( role );
}
}
foreach ( var roleState in GroupTypeRolesState )
{
GroupTypeRole role = groupType.Roles.Where( r => r.Guid == roleState.Guid ).FirstOrDefault();
if ( role == null )
{
role = new GroupTypeRole();
groupType.Roles.Add( role );
}
else
{
roleState.Id = role.Id;
roleState.Guid = role.Guid;
}
role.CopyPropertiesFrom( roleState );
}
ScheduleType allowedScheduleTypes = ScheduleType.None;
foreach( ListItem li in cblScheduleTypes.Items )
{
if ( li.Selected )
{
allowedScheduleTypes = allowedScheduleTypes | (ScheduleType)li.Value.AsInteger();
}
}
GroupLocationPickerMode locationSelectionMode = GroupLocationPickerMode.None;
foreach ( ListItem li in cblLocationSelectionModes.Items )
{
if ( li.Selected )
{
locationSelectionMode = locationSelectionMode | (GroupLocationPickerMode)li.Value.AsInteger();
}
}
groupType.Name = tbName.Text;
groupType.Description = tbDescription.Text;
groupType.GroupTerm = tbGroupTerm.Text;
groupType.GroupMemberTerm = tbGroupMemberTerm.Text;
groupType.ShowInGroupList = cbShowInGroupList.Checked;
groupType.ShowInNavigation = cbShowInNavigation.Checked;
groupType.IconCssClass = tbIconCssClass.Text;
groupType.TakesAttendance = cbTakesAttendance.Checked;
groupType.SendAttendanceReminder = cbSendAttendanceReminder.Checked;
groupType.AttendanceRule = ddlAttendanceRule.SelectedValueAsEnum<AttendanceRule>();
groupType.AttendancePrintTo = ddlPrintTo.SelectedValueAsEnum<PrintTo>();
groupType.AllowedScheduleTypes = allowedScheduleTypes;
groupType.LocationSelectionMode = locationSelectionMode;
groupType.GroupTypePurposeValueId = ddlGroupTypePurpose.SelectedValueAsInt();
groupType.AllowMultipleLocations = cbAllowMultipleLocations.Checked;
groupType.InheritedGroupTypeId = gtpInheritedGroupType.SelectedGroupTypeId;
groupType.EnableLocationSchedules = cbEnableLocationSchedules.Checked;
groupType.ChildGroupTypes = new List<GroupType>();
groupType.ChildGroupTypes.Clear();
foreach ( var item in ChildGroupTypesDictionary )
{
var childGroupType = groupTypeService.Get( item.Key );
if ( childGroupType != null )
{
groupType.ChildGroupTypes.Add( childGroupType );
}
}
//.........这里部分代码省略.........
示例5: ShowReadonlyDetails
/// <summary>
/// Shows the readonly details.
/// </summary>
/// <param name="connectionRequest">The connection request.</param>
private void ShowReadonlyDetails( ConnectionRequest connectionRequest )
{
pdAuditDetails.SetEntity( connectionRequest, ResolveRockUrl( "~" ) );
if ( connectionRequest.AssignedGroupId != null )
{
pnlRequirements.Visible = true;
ShowConnectionOpportunityRequirementsStatuses();
}
else
{
pnlRequirements.Visible = false;
lbConnect.Enabled = !connectionRequest.ConnectionOpportunity.ConnectionType.RequiresPlacementGroupToConnect;
}
if ( connectionRequest.ConnectionState == ConnectionState.Inactive || connectionRequest.ConnectionState == ConnectionState.Connected )
{
lbConnect.Visible = false;
lbTransfer.Visible = false;
}
lContactInfo.Text = string.Empty;
Person person = null;
if ( connectionRequest != null && connectionRequest.PersonAlias != null )
{
person = connectionRequest.PersonAlias.Person;
}
if ( person != null && ( person.PhoneNumbers.Any() || !String.IsNullOrWhiteSpace( person.Email ) ) )
{
List<String> contactList = new List<string>();
foreach ( PhoneNumber phoneNumber in person.PhoneNumbers )
{
contactList.Add( String.Format( "{0} <font color='#808080'>{1}</font>", phoneNumber.NumberFormatted, phoneNumber.NumberTypeValue ) );
}
string emailTag = person.GetEmailTag( ResolveRockUrl( "/" ) );
if ( !string.IsNullOrWhiteSpace( emailTag ) )
{
contactList.Add( emailTag );
}
lContactInfo.Text = contactList.AsDelimited( "</br>" );
}
else
{
lContactInfo.Text = "No contact Info";
}
if ( person != null && !string.IsNullOrWhiteSpace( GetAttributeValue( "PersonProfilePage" ) ) )
{
lbProfilePage.Visible = true;
Dictionary<string, string> queryParms = new Dictionary<string, string>();
queryParms.Add( "PersonId", person.Id.ToString() );
lbProfilePage.PostBackUrl = LinkedPageUrl( "PersonProfilePage", queryParms );
}
else
{
lbProfilePage.Visible = false;
}
if ( person != null )
{
string imgTag = Rock.Model.Person.GetPersonPhotoImageTag( person, 200, 200, className: "img-thumbnail" );
if ( person.PhotoId.HasValue )
{
lPortrait.Text = string.Format( "<a href='{0}'>{1}</a>", person.PhotoUrl, imgTag );
}
else
{
lPortrait.Text = imgTag;
}
}
else
{
lPortrait.Text = string.Empty; ;
}
lComments.Text = connectionRequest != null && connectionRequest.Comments != null ? connectionRequest.Comments.ScrubHtmlAndConvertCrLfToBr() : string.Empty;
lRequestDate.Text = connectionRequest != null && connectionRequest.CreatedDateTime.HasValue ? connectionRequest.CreatedDateTime.Value.ToShortDateString() : string.Empty;
if ( connectionRequest != null && connectionRequest.AssignedGroup != null )
{
var qryParams = new Dictionary<string, string>();
qryParams.Add( "GroupId", connectionRequest.AssignedGroup.Id.ToString() );
string url = LinkedPageUrl( "GroupDetailPage", qryParams );
string roleStatus = string.Empty;
string roleName = string.Empty;
if ( connectionRequest.AssignedGroupMemberRoleId.HasValue )
{
var role = new GroupTypeRoleService( new RockContext() ).Get( connectionRequest.AssignedGroupMemberRoleId.Value );
//.........这里部分代码省略.........
示例6: 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 );
}
}
}
}
示例7: 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 );
}
示例8: bindGrid
protected void bindGrid()
{
if ( String.IsNullOrWhiteSpace( CheckinCode ) )
{
ShowPanel( 0 );
}
else
{
rlCheckinCode.Text = CheckinCode + " <a href='?'><i class='fa fa-times'></i></a>";
if ( !SelectedAttendanceGuid.IsEmpty() )
{
ShowPanel( 2 );
var SelectedAttendance = new AttendanceService( rockContext ).Get( SelectedAttendanceGuid );
SelectedAttendance.LoadAttributes();
var attSearch = SelectedAttendance.GetAttributeValue( "SearchValue" );
var hasSearch = !String.IsNullOrWhiteSpace( attSearch );
if ( hasSearch )
attSearch = attSearch.AsNumeric();
var SelectedPerson = SelectedAttendance.PersonAlias.Person;
rlSelectedPerson.Text = SelectedPerson.FullName + " <a href='?CheckinCode=" + CheckinCode + "'><i class='fa fa-times'></i></a>";
var groupRoleServ = new GroupTypeRoleService( rockContext );
var knownRelationship_GroupMemberships = new GroupMemberService( rockContext ).Queryable()
.Where( gm => gm.Group.GroupTypeId == 11 && gm.PersonId == SelectedPerson.Id );
var shownRelationships = GetAttributeValue( "IncludedRelationships" ).Split( ',' ).Select( g => g.AsGuid() );
gReleventPeople.DataSource = SelectedPerson.GetFamilyMembers( false, rockContext )
.Select( m => new
{
Person = m.Person,
Role = m.GroupRole,
Priority = 100
} )
.ToList()
.Union(
knownRelationship_GroupMemberships
.Where( gm => gm.GroupRole.Guid == GUID_OwnerRole )
.SelectMany( gm => gm.Group.Members.Where( gm2 => gm2.PersonId != SelectedPerson.Id ) )
.ToList()
.Select( gm => new
{
Person = gm.Person,
Role = GetInverseRole( gm.GroupRole, groupRoleServ ),
Priority = 50
} )
)
.Union(
knownRelationship_GroupMemberships
.Where( gm => gm.GroupRole.Guid != GUID_OwnerRole )
.Select( gm => new
{
Person = gm.Group.Members.Where( gm2 => gm2.GroupRole.Guid == GUID_OwnerRole ).FirstOrDefault().Person,
Role = gm.GroupRole,
Priority = 40
} ).ToList()
)
.Where( r => shownRelationships.Contains( r.Role.Guid ) )
.GroupBy( x => x.Person )
.Select( x => new PersonRelationship
{
PersonAliasGuid = x.Key.PrimaryAlias.Guid,
FullName = x.Key.FullName,
Roles = String.Join( " ,", x.Select( y => y.Role.Name ) ),
Priority = x.Select( y => y.Priority ).Max(),
HomePhone = GetFormatedNumber( x.Key, GUID_HomePhone ),
MobilePhone = GetFormatedNumber( x.Key, GUID_MobilePhone ),
Highlight = hasSearch && x.Key.PhoneNumbers.Any( y => y.Number.Contains( attSearch ) )
} )
.OrderByDescending( r => r.Priority + ( r.Highlight ? 100 : 0) );
gReleventPeople.DataKeyNames = new string[] { "PersonAliasGuid" };
gReleventPeople.DataBind();
}
else
{
ShowPanel( 1 );
int daysBacktoSearch = GetAttributeValue( "DaysBacktoSearch" ).AsInteger();
var searchDate = DateTime.Now.Date.AddDays( -daysBacktoSearch );
gSearchResults.SetLinqDataSource( new AttendanceCodeService( rockContext )
.Queryable()
.Where( c => c.Code == CheckinCode && c.IssueDateTime > searchDate )
.SelectMany( c => c.Attendances )
.OrderByDescending( "StartDateTime" ) );
gSearchResults.DataKeyNames = new string[] { "Guid" };
gSearchResults.DataBind();
}
}
}
示例9: SaveIndividuals
/// <summary>
/// Saves the individuals.
/// </summary>
/// <param name="newFamilyList">The family list.</param>
/// <param name="visitorList">The optional visitor list.</param>
private void SaveIndividuals( List<Group> newFamilyList, List<Group> visitorList = null, List<Note> newNoteList = null )
{
if ( newFamilyList.Any() )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( ( ) =>
{
rockContext.Groups.AddRange( newFamilyList );
rockContext.SaveChanges( DisableAuditing );
ImportedFamilies.AddRange( newFamilyList );
foreach ( var familyGroups in newFamilyList.GroupBy<Group, string>( g => g.ForeignKey ) )
{
bool visitorsExist = visitorList.Any() && familyGroups.Any();
foreach ( var newFamilyGroup in familyGroups )
{
foreach ( var person in newFamilyGroup.Members.Select( m => m.Person ) )
{
// Set notes on this person
if ( newNoteList.Any( n => n.ForeignKey == person.ForeignKey ) )
{
newNoteList.Where( n => n.ForeignKey == person.ForeignKey ).ToList()
.ForEach( n => n.EntityId = person.Id );
}
// Set attributes on this person
foreach ( var attributeCache in person.Attributes.Select( a => a.Value ) )
{
var existingValue = rockContext.AttributeValues.FirstOrDefault( v => v.Attribute.Key == attributeCache.Key && v.EntityId == person.Id );
var newAttributeValue = person.AttributeValues[attributeCache.Key];
// set the new value and add it to the database
if ( existingValue == null )
{
existingValue = new AttributeValue();
existingValue.AttributeId = newAttributeValue.AttributeId;
existingValue.EntityId = person.Id;
existingValue.Value = newAttributeValue.Value;
rockContext.AttributeValues.Add( existingValue );
}
else
{
existingValue.Value = newAttributeValue.Value;
rockContext.Entry( existingValue ).State = EntityState.Modified;
}
}
// Set aliases on this person
if ( !person.Aliases.Any( a => a.PersonId == person.Id ) )
{
person.Aliases.Add( new PersonAlias
{
AliasPersonId = person.Id,
AliasPersonGuid = person.Guid,
ForeignKey = person.ForeignKey,
ForeignId = person.ForeignId,
PersonId = person.Id
} );
}
person.GivingGroupId = newFamilyGroup.Id;
if ( visitorsExist )
{
var groupTypeRoleService = new GroupTypeRoleService( rockContext );
var ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int inviteeRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED ) ).Id;
int invitedByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY ) ).Id;
int canCheckInRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN ) ).Id;
int allowCheckInByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_ALLOW_CHECK_IN_BY ) ).Id;
// Retrieve or create the group this person is an owner of
var ownerGroup = new GroupMemberService( rockContext ).Queryable()
.Where( m => m.PersonId == person.Id && m.GroupRoleId == ownerRole.Id )
.Select( m => m.Group ).FirstOrDefault();
if ( ownerGroup == null )
{
var ownerGroupMember = new GroupMember();
ownerGroupMember.PersonId = person.Id;
ownerGroupMember.GroupRoleId = ownerRole.Id;
ownerGroup = new Group();
ownerGroup.Name = ownerRole.GroupType.Name;
ownerGroup.GroupTypeId = ownerRole.GroupTypeId.Value;
ownerGroup.Members.Add( ownerGroupMember );
rockContext.Groups.Add( ownerGroup );
}
// Visitor, add relationships to the family members
if ( visitorList.Where( v => v.ForeignKey == newFamilyGroup.ForeignKey )
.Any( v => v.Members.Any( m => m.Person.ForeignKey.Equals( person.ForeignKey ) ) ) )
{
var familyMembers = familyGroups.Except( visitorList ).SelectMany( g => g.Members );
//.........这里部分代码省略.........
示例10: SetRelationships
/// <summary>
/// Sets the relationships between a business and it's owner.
/// </summary>
/// <param name="business">The business.</param>
private void SetRelationships( Person business )
{
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
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();
int? principleRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_PRINCIPLE ) ) )
.Select( r => r.Id )
.FirstOrDefault();
// get the known relationship group from the owner
// add the business as a group member of that group using group role of GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS
var owner = personService.Get( (int)ppOwner.PersonId );
var knownRelationshipGroup = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) ) &&
g.PersonId == owner.Id )
.Select( g => g.Group ).FirstOrDefault();
var groupMember = new GroupMember();
groupMember.PersonId = int.Parse( hfBusinessId.Value );
groupMember.GroupRoleId = (int)businessRoleId;
knownRelationshipGroup.Members.Add( groupMember );
rockContext.SaveChanges();
// get the known relationship group from the business
// add the owner as a group member of that group using group role of GROUPROLE_KNOWN_RELATIONSHIPS_PRINCIPLE
var businessKnownRelationshipGroup = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) ) &&
g.PersonId == business.Id )
.Select( g => g.Group ).FirstOrDefault();
var businessGroupMember = new GroupMember();
businessGroupMember.PersonId = owner.Id;
businessGroupMember.GroupRoleId = (int)principleRoleId;
businessKnownRelationshipGroup.Members.Add( businessGroupMember );
rockContext.SaveChanges();
}
示例11: mdAddContact_SaveClick
/// <summary>
/// Handles the SaveClick event of the mdAddContact control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void mdAddContact_SaveClick( object sender, EventArgs e )
{
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
var business = personService.Get( int.Parse( hfBusinessId.Value ) );
var contactId = (int)ppContact.PersonId;
if ( contactId > 0 )
{
int? businessContactRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT ) ) )
.Select( r => r.Id )
.FirstOrDefault();
var groupMember = business.GivingGroup.Members.Where( role => role.GroupRoleId == businessContactRoleId ).FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
business.GivingGroup.Members.Add( groupMember );
}
groupMember.Person = personService.Get( (int)ppContact.PersonId );
groupMember.GroupRoleId = (int)businessContactRoleId;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
rockContext.SaveChanges();
}
mdAddContact.Hide();
hfModalOpen.Value = string.Empty;
BindContactListGrid( business );
}
示例12: BindContactListGrid
/// <summary>
/// Binds the contact list grid.
/// </summary>
/// <param name="business">The business.</param>
private void BindContactListGrid( Person business )
{
// Load up that contact list.
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
int? businessContactRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT ) ) )
.Select( r => r.Id )
.FirstOrDefault();
// I want a list of people that are connected to this business/person by the business contact relationship
List<GroupMember> contactList = new List<GroupMember>();
if ( business.GivingGroup != null )
{
contactList = business.GivingGroup.Members.Where( g => g.GroupRoleId == businessContactRoleId ).ToList();
List<Person> personList = new List<Person>();
foreach ( var contact in contactList )
{
personList.Add( contact.Person );
}
gContactList.DataSource = personList;
gContactList.DataBind();
}
else
{
gContactList.Visible = false;
}
}
示例13: lbSave_Click
//.........这里部分代码省略.........
var impliedRelationshipGroup = new Group();
if ( business.GivingGroupId == null )
{
groupService.Add( businessGroup );
// If there isn't a Giving Group then there aren't any other groups.
// We also need to add the Known Relationship and Implied Relationship groups for this business.
var knownRelationshipGroupTypeId = new GroupTypeService( rockContext ).Get( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS ) ).Id;
knownRelationshipGroup.GroupTypeId = knownRelationshipGroupTypeId;
knownRelationshipGroup.Name = "Known Relationship";
groupService.Add( knownRelationshipGroup );
var impliedRelationshipGroupTypeId = new GroupTypeService( rockContext ).Get( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_IMPLIED_RELATIONSHIPS ) ).Id;
impliedRelationshipGroup.GroupTypeId = impliedRelationshipGroupTypeId;
impliedRelationshipGroup.Name = "Implied Relationship";
groupService.Add( impliedRelationshipGroup );
}
rockContext.SaveChanges();
// Giving Group
int? newGivingGroupId = ddlGivingGroup.SelectedValueAsId();
if ( business.GivingGroupId != newGivingGroupId )
{
string oldGivingGroupName = business.GivingGroup != null ? business.GivingGroup.Name : string.Empty;
string newGivingGroupName = newGivingGroupId.HasValue ? ddlGivingGroup.Items.FindByValue( newGivingGroupId.Value.ToString() ).Text : string.Empty;
History.EvaluateChange( changes, "Giving Group", oldGivingGroupName, newGivingGroupName );
}
business.GivingGroup = businessGroup;
// GroupMember
var groupMemberService = new GroupMemberService( rockContext );
int? adultRoleId = new GroupTypeRoleService( rockContext ).Queryable()
.Where( r =>
r.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ) )
.Select( r => r.Id )
.FirstOrDefault();
var groupMember = businessGroup.Members.Where( role => role.GroupRoleId == adultRoleId ).FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
businessGroup.Members.Add( groupMember );
// If we're in here, then this is a new business.
// Add the known relationship and implied relationship GroupMember entries.
var knownRelationshipGroupMember = new GroupMember();
knownRelationshipGroupMember.Person = business;
knownRelationshipGroupMember.GroupRoleId = new GroupTypeRoleService( rockContext ).Get( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() ).Id;
knownRelationshipGroupMember.GroupId = knownRelationshipGroup.Id;
knownRelationshipGroup.Members.Add( knownRelationshipGroupMember );
var impliedRelationshipGroupMember = new GroupMember();
impliedRelationshipGroupMember.Person = business;
impliedRelationshipGroupMember.GroupRoleId = new GroupTypeRoleService( rockContext ).Get( Rock.SystemGuid.GroupRole.GROUPROLE_IMPLIED_RELATIONSHIPS_OWNER.AsGuid() ).Id;
impliedRelationshipGroupMember.GroupId = impliedRelationshipGroup.Id;
impliedRelationshipGroup.Members.Add( impliedRelationshipGroupMember );
}
groupMember.Person = business;
groupMember.GroupRoleId = new GroupTypeRoleService( rockContext ).Get( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ).Id;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
// GroupLocation & Location
var groupLocationService = new GroupLocationService( rockContext );
var groupLocation = businessGroup.GroupLocations.FirstOrDefault();
示例14: GetInverseRelationship
/// <summary>
/// Gets the inverse relationship.
/// Returns the <see cref="Rock.Model.GroupMember" /> who has an inverse relationship to the provided <see cref="Rock.Model.GroupMember" />.
/// </summary>
/// <param name="groupMember">A <see cref="Rock.Model.GroupMember" /> representing the person to find the inverse relationship for.</param>
/// <param name="createGroup">A <see cref="System.Boolean" /> flag indicating if a new <see cref="Rock.Model.Group" /> can be created
/// for the person with the inverse relationship.</param>
/// <returns>
/// A <see cref="Rock.Model.GroupMember" /> representing the <see cref="Rock.Model.Person" /> with the inverse relationship.
/// </returns>
/// <remarks>
/// In Rock, examples of inverse relationships include: Parent/Child, Can Check In/Check in By, Sibling/Sibling, Grandparent/Grandchild, etc.
/// </remarks>
public GroupMember GetInverseRelationship( GroupMember groupMember, bool createGroup )
{
var groupRole = groupMember.GroupRole;
if ( groupRole == null )
{
groupRole = Queryable( true )
.Where( m => m.Id == groupMember.Id )
.Select( m => m.GroupRole )
.FirstOrDefault();
}
if ( groupRole != null )
{
if ( groupRole.Attributes == null )
{
groupRole.LoadAttributes();
}
if ( groupRole.Attributes.ContainsKey( "InverseRelationship" ) )
{
Guid ownerRoleGuid = new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER );
var memberInfo = Queryable( true )
.Where( m =>
m.GroupId == groupMember.GroupId &&
m.GroupRole.Guid.Equals( ownerRoleGuid ) )
.Select( m => new
{
PersonId = m.PersonId,
RoleId = m.GroupRoleId
} )
.FirstOrDefault();
int? ownerPersonId = null;
int? ownerRoleId = null;
if ( memberInfo != null )
{
ownerPersonId = memberInfo.PersonId;
ownerRoleId = memberInfo.RoleId;
}
if ( ownerPersonId.HasValue && ownerRoleId.HasValue )
{
// Find related person's group
var inverseGroup = Queryable( true )
.Where( m =>
m.PersonId == groupMember.PersonId &&
m.Group.GroupTypeId == groupRole.GroupTypeId &&
m.GroupRole.Guid.Equals( ownerRoleGuid ) )
.Select( m => m.Group )
.FirstOrDefault();
if ( inverseGroup == null && createGroup )
{
var ownerGroupMember = new GroupMember();
ownerGroupMember.PersonId = groupMember.PersonId;
ownerGroupMember.GroupRoleId = ownerRoleId.Value;
inverseGroup = new Group();
inverseGroup.Name = groupRole.GroupType.Name;
inverseGroup.GroupTypeId = groupRole.GroupTypeId.Value;
inverseGroup.Members.Add( ownerGroupMember );
}
if ( inverseGroup != null )
{
Guid inverseRoleGuid = Guid.Empty;
if ( Guid.TryParse( groupRole.GetAttributeValue( "InverseRelationship" ), out inverseRoleGuid ) )
{
var inverseGroupMember = Queryable( true )
.Where( m =>
m.PersonId == ownerPersonId &&
m.GroupId == inverseGroup.Id &&
m.GroupRole.Guid.Equals( inverseRoleGuid ) )
.FirstOrDefault();
if ( inverseGroupMember == null )
{
var inverseRole = new GroupTypeRoleService( (RockContext)Context ).Get( inverseRoleGuid );
if ( inverseRole != null )
{
inverseGroupMember = new GroupMember();
inverseGroupMember.PersonId = ownerPersonId.Value;
inverseGroupMember.Group = inverseGroup;
inverseGroupMember.GroupRoleId = inverseRole.Id;
Add( inverseGroupMember );
//.........这里部分代码省略.........
示例15: GetInverseRole
protected GroupTypeRole GetInverseRole( GroupTypeRole role, GroupTypeRoleService groupRoleServ )
{
role.LoadAttributes();
return groupRoleServ.Get( role.GetAttributeValue( "InverseRelationship" ).AsGuid() );
}