/// <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 ) { int? categoryId = null; var dataViewService = new DataViewService(); var dataView = dataViewService.Get( int.Parse( hfDataViewId.Value ) ); if ( dataView != null ) { string errorMessage; if ( !dataViewService.CanDelete( dataView, out errorMessage ) ) { ShowReadonlyDetails( dataView ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = dataView.CategoryId; dataViewService.Delete( dataView, CurrentPersonId ); dataViewService.Save( dataView, CurrentPersonId ); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <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 ) { int? categoryId = null; var rockContext = new RockContext(); var dataViewService = new DataViewService( rockContext ); var dataView = dataViewService.Get( int.Parse( hfDataViewId.Value ) ); if ( dataView != null ) { string errorMessage; if ( !dataViewService.CanDelete( dataView, out errorMessage ) ) { ShowReadonlyDetails( dataView ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = dataView.CategoryId; // delete report filter try { DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext ); DeleteDataViewFilter( dataView.DataViewFilter, dataViewFilterService ); } catch { // } dataViewService.Delete( dataView ); rockContext.SaveChanges(); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }