本文整理汇总了C#中Rock.Model.GroupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId方法的具体用法?C# GroupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId怎么用?C# GroupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupMemberService
的用法示例。
在下文中一共展示了GroupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 );
}
//.........这里部分代码省略.........
示例2: 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 )
{
// Only do group member placement if the request has an assigned placement group
if ( connectionRequest.ConnectionOpportunity.GroupMemberRoleId.HasValue &&
connectionRequest.AssignedGroupId.HasValue )
{
// Only attempt the add if person does not already exist in group with same role
var groupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId( connectionRequest.AssignedGroupId.Value,
connectionRequest.PersonAlias.PersonId, connectionRequest.ConnectionOpportunity.GroupMemberRoleId.Value );
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.PersonId = connectionRequest.PersonAlias.PersonId;
groupMember.GroupRoleId = connectionRequest.ConnectionOpportunity.GroupMemberRoleId.Value;
groupMember.GroupMemberStatus = connectionRequest.ConnectionOpportunity.GroupMemberStatus;
groupMember.GroupId = connectionRequest.AssignedGroupId.Value;
groupMemberService.Add( groupMember );
}
}
// ... 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 );
}
connectionRequest.ConnectionState = ConnectionState.Connected;
rockContext.SaveChanges();
ShowDetail( connectionRequest.Id, connectionRequest.ConnectionOpportunityId );
}
}
}
示例3: btnSaveGroupMember_Click
/// <summary>
/// Handles the Click event of the btnSaveGroupMember 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 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;
// set their status. If HideInactiveGroupMemberStatus is True, and they are already Inactive, keep their status as Inactive;
bool hideGroupMemberInactiveStatus = this.GetAttributeValue( "HideInactiveGroupMemberStatus" ).AsBooleanOrNull() ?? false;
var selectedStatus = rblStatus.SelectedValueAsEnumOrNull<GroupMemberStatus>();
if ( !selectedStatus.HasValue )
{
if ( hideGroupMemberInactiveStatus )
{
selectedStatus = GroupMemberStatus.Inactive;
}
else
{
selectedStatus = GroupMemberStatus.Active;
}
}
groupMember.GroupMemberStatus = selectedStatus.Value;
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
// if the groupMember IsValid 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
cvEditGroupMember.IsValid = groupMember.IsValid;
if ( !cvEditGroupMember.IsValid )
{
cvEditGroupMember.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 );
}
pnlEditGroupMember.Visible = false;
pnlGroupView.Visible = true;
DisplayViewGroup();
//.........这里部分代码省略.........
示例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 )
{
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() );
//.........这里部分代码省略.........
示例5: 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;
}
示例6: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
{
errorMessages = new List<string>();
var groupAttribute = GetAttributeValue( action, "GroupAttribute" );
Guid groupAttrGuid = groupAttribute.AsGuid();
var personAttribute = GetAttributeValue( action, "PersonAttribute" );
Guid personAttrGuid = personAttribute.AsGuid();
var groupRoleAttr = GetAttributeValue( action, "Group Role" );
Guid groupRoleGuid = groupRoleAttr.AsGuid();
var memberStatus = (GroupMemberStatus)Enum.Parse( typeof( GroupMemberStatus ), GetAttributeValue( action, "MemberStatus" ) );
if (!groupAttrGuid.IsEmpty())
{
string attributeGroupValue = action.GetWorklowAttributeValue( groupAttrGuid );
Guid groupGuid = attributeGroupValue.AsGuid();
if (!personAttrGuid.IsEmpty())
{
string attributePersonValue = action.GetWorklowAttributeValue( personAttrGuid );
Guid personAliasGuid = attributePersonValue.AsGuid();
if (!groupRoleGuid.IsEmpty())
{
if (!groupGuid.IsEmpty())
{
if (!personAliasGuid.IsEmpty())
{
using (var ctx = new RockContext())
{
var group = (new GroupService( ctx )).Get( groupGuid );
var personAlias = (new PersonAliasService( ctx )).Get( personAliasGuid );
var groupRole = (new GroupTypeRoleService( ctx )).Get( groupRoleGuid );
if (groupRole != null)
{
var groupMemberService = new GroupMemberService( ctx );
var groupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId( group.Id, personAlias.Person.Id, groupRole.Id );
if (groupMember == null)
{
groupMember = new GroupMember();
groupMemberService.Add( groupMember );
}
else
{
action.AddLogEntry( string.Format( "{0} is already in group {1} as {2} with status {3}", personAlias.Person.FullName, group.Name, groupRole.Name, memberStatus.GetDescription() ) );
}
groupMember.Person = personAlias.Person;
groupMember.Group = group;
groupMember.GroupRole = groupRole;
groupMember.GroupMemberStatus = memberStatus;
ctx.SaveChanges();
action.AddLogEntry( string.Format( "{0} added to group {1} as {2} with status {3}", personAlias.Person.FullName, group.Name, groupRole.Name, memberStatus.GetDescription() ) );
return true;
}
else
{
action.AddLogEntry( string.Format( "GroupRole does not exist: {0}", groupRoleGuid ) );
}
}
}
else
{
action.AddLogEntry( "Person attribute, person does not exist" );
}
}
else
{
action.AddLogEntry( "Group attribute, Group does not exist" );
}
}
}
}
return false;
}