本文整理汇总了C#中Rock.Model.GroupMemberService.CanDelete方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService.CanDelete方法的具体用法?C# GroupMemberService.CanDelete怎么用?C# GroupMemberService.CanDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupMemberService
的用法示例。
在下文中一共展示了GroupMemberService.CanDelete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteGroupMember_Click
/// <summary>
/// Handles the Click event of the DeleteGroupMember control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
protected void DeleteGroupMember_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
{
RockContext rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMember groupMember = groupMemberService.Get( e.RowKeyId );
if ( groupMember != null )
{
string errorMessage;
if ( !groupMemberService.CanDelete( groupMember, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
int groupId = groupMember.GroupId;
groupMemberService.Delete( groupMember );
rockContext.SaveChanges();
Group group = new GroupService( rockContext ).Get( groupId );
if ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
// person removed from SecurityRole, Flush
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
}
BindGroupMembersGrid();
}
示例2: 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();
}
}
示例3: 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 );
}