/// <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; } groupType.ParentGroupTypes.Clear(); groupType.ChildGroupTypes.Clear(); groupTypeService.Delete( groupType ); rockContext.SaveChanges(); GroupTypeCache.Flush( groupTypeId ); } BindGrid(); }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); GroupTypeService groupTypeService = new GroupTypeService( rockContext ); GroupType groupType = groupTypeService.Get( hfGroupTypeId.Value.AsInteger() ); if ( groupType != null ) { string errorMessage; if ( !groupTypeService.CanDelete( groupType, out errorMessage ) ) { mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); return; } int groupTypeId = groupType.Id; groupType.ParentGroupTypes.Clear(); groupType.ChildGroupTypes.Clear(); groupTypeService.Delete( groupType ); rockContext.SaveChanges(); GroupTypeCache.Flush( groupTypeId ); Rock.CheckIn.KioskDevice.FlushAll(); } var pageRef = new PageReference( CurrentPageReference.PageId, CurrentPageReference.RouteId ); NavigateToPage( pageRef ); }
private void CheckinAreaRow_DeleteAreaClick( object sender, EventArgs e ) { var row = sender as CheckinAreaRow; using ( var rockContext = new RockContext() ) { var groupTypeService = new GroupTypeService( rockContext ); var groupType = groupTypeService.Get( row.GroupTypeGuid ); if ( groupType != null ) { // Warn if this GroupType or any of its child grouptypes (recursive) is being used as an Inherited Group Type. Probably shouldn't happen, but just in case if ( IsInheritedGroupTypeRecursive( groupType, groupTypeService ) ) { nbDeleteWarning.Text = "WARNING - Cannot delete. This group type or one of its child group types is assigned as an inherited group type."; nbDeleteWarning.Visible = true; return; } string errorMessage; if ( !groupTypeService.CanDelete( groupType, out errorMessage ) ) { nbDeleteWarning.Text = "WARNING - Cannot Delete: " + errorMessage; nbDeleteWarning.Visible = true; return; } int id = groupType.Id; groupType.ParentGroupTypes.Clear(); groupType.ChildGroupTypes.Clear(); groupTypeService.Delete( groupType ); rockContext.SaveChanges(); GroupTypeCache.Flush( id ); Rock.CheckIn.KioskDevice.FlushAll(); SelectArea( null ); } } BuildRows(); }
/// <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 ) { RockTransactionScope.WrapTransaction( () => { GroupTypeService groupTypeService = new GroupTypeService(); 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, CurrentPersonId ); groupTypeService.Save( groupType, CurrentPersonId ); GroupTypeCache.Flush( groupTypeId ); } } ); BindGrid(); }