/// <summary> /// Handles the Delete event of the gMetricValues 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 gMetricValues_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var metricValueService = new MetricValueService(rockContext); var metricValuePartitionService = new MetricValuePartitionService(rockContext); int?metricValueId = e.RowKeyValues["MetricValueId"] as int?; if (metricValueId.HasValue) { var metricValue = metricValueService.Get(metricValueId.Value); if (metricValue != null) { string errorMessage; if (!metricValueService.CanDelete(metricValue, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } if (!metricValueService.CanDelete(metricValue, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } rockContext.WrapTransaction(() => { metricValuePartitionService.DeleteRange(metricValue.MetricValuePartitions); metricValueService.Delete(metricValue); rockContext.SaveChanges(); }); } BindGrid(); } }
/// <summary> /// Handles the Delete event of the gMetricValues 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 gMetricValues_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var metricValueService = new MetricValueService(rockContext); var metricValuePartitionService = new MetricValuePartitionService(rockContext); var metricValue = metricValueService.Get(e.RowKeyId); if (metricValue != null) { string errorMessage; if (!metricValueService.CanDelete(metricValue, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } rockContext.WrapTransaction(() => { metricValuePartitionService.DeleteRange(metricValue.MetricValuePartitions); metricValueService.Delete(metricValue); rockContext.SaveChanges(); }); } NavigateToCurrentPageReference(); }
/// <summary> /// Handles the Delete event of the gMetricValues 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 gMetricValues_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); MetricValueService metricValueService = new MetricValueService( rockContext ); MetricValue metricValue = metricValueService.Get( e.RowKeyId ); if ( metricValue != null ) { string errorMessage; if ( !metricValueService.CanDelete( metricValue, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } metricValueService.Delete( metricValue ); rockContext.SaveChanges(); } BindGrid(); }