/// <summary> /// Handles the Delete event of the gMetrics 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 gMetrics_Delete(object sender, RowEventArgs e) { var metricService = new MetricService(); Metric metric = metricService.Get((int)e.RowKeyValue); if (metric != null) { metricService.Delete(metric, CurrentPersonId); metricService.Save(metric, CurrentPersonId); } 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(); MetricService metricService = new MetricService(rockContext); Metric metric = metricService.Get(hfMetricId.Value.AsInteger()); // intentionally get metricCategory with new RockContext() so we don't confuse SaveChanges() int?parentCategoryId = null; var metricCategory = new MetricCategoryService(new RockContext()).Get(hfMetricCategoryId.ValueAsInt()); if (metricCategory != null) { parentCategoryId = metricCategory.CategoryId; } if (metric != null) { string errorMessage; if (!metricService.CanDelete(metric, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } metricService.Delete(metric); rockContext.SaveChanges(); } var qryParams = new Dictionary <string, string>(); if (parentCategoryId != null) { qryParams["CategoryId"] = parentCategoryId.ToString(); } NavigateToPage(RockPage.Guid, qryParams); }