/// <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?parentLocationId = null; var rockContext = new RockContext(); LocationService locationService = new LocationService(rockContext); Location location = locationService.Get(int.Parse(hfLocationId.Value)); if (location != null) { parentLocationId = location.ParentLocationId; string errorMessage; if (!locationService.CanDelete(location, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } locationService.Delete(location); rockContext.SaveChanges(); } // reload page, selecting the deleted location's parent var qryParams = new Dictionary <string, string>(); if (parentLocationId != null) { qryParams["LocationId"] = parentLocationId.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?parentLocationId = null; var rockContext = new RockContext(); LocationService locationService = new LocationService(rockContext); Location location = locationService.Get(hfLocationId.Value.AsInteger()); if (location != null) { parentLocationId = location.ParentLocationId; string errorMessage; if (!locationService.CanDelete(location, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } int locationId = location.Id; locationService.Delete(location); rockContext.SaveChanges(); FlushCampus(locationId); Rock.CheckIn.KioskDevice.FlushAll(); } // reload page, selecting the deleted location's parent var qryParams = new Dictionary <string, string>(); if (parentLocationId != null) { qryParams["LocationId"] = parentLocationId.ToString(); } qryParams["ExpandedIds"] = PageParameter("ExpandedIds"); NavigateToPage(RockPage.Guid, qryParams); }