/// <summary>
/// Handles the Delete event of the gGroupType 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 gGroupType_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
GroupTypeService groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = groupTypeService.Get( e.RowKeyId );
if ( groupType != null )
{
int groupTypeId = groupType.Id;
if ( !groupType.IsAuthorized( "Administrate", CurrentPerson ) )
{
mdGridWarning.Show( "Sorry, you're not authorized to delete this group type.", ModalAlertType.Alert );
return;
}
string errorMessage;
if ( !groupTypeService.CanDelete( groupType, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
return;
}
groupTypeService.Delete( groupType );
rockContext.SaveChanges();
GroupTypeCache.Flush( groupTypeId );
}
BindGrid();
}