/// <summary>
/// Handles the Delete event of the gGroups control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gGroups_Delete( object sender, RowEventArgs e )
{
RockTransactionScope.WrapTransaction( () =>
{
GroupService groupService = new GroupService();
AuthService authService = new AuthService();
Group group = groupService.Get( (int)e.RowKeyValue );
if ( group != null )
{
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole;
if ( isSecurityRoleGroup )
{
foreach ( var auth in authService.Queryable().Where( a => a.GroupId.Equals( group.Id ) ).ToList() )
{
authService.Delete( auth, CurrentPersonId );
authService.Save( auth, CurrentPersonId );
}
}
groupService.Delete( group, CurrentPersonId );
groupService.Save( group, CurrentPersonId );
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
Rock.Security.Role.Flush( group.Id );
}
}
} );
BindGrid();
}