/// <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(); }); } 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 metricValueService = new MetricValueService(); MetricValue metricValue = metricValueService.Get((int)e.RowKeyValue); if (metricValue != null) { metricValueService.Delete(metricValue, CurrentPersonId); metricValueService.Save(metricValue, CurrentPersonId); } BindGrid(); }