/// <summary> /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); CampusService campusService = new CampusService(rockContext); Campus campus = campusService.Get(e.RowKeyId); if (campus != null) { // Don't allow deleting the last campus if (!campusService.Queryable().Where(c => c.Id != campus.Id).Any()) { mdGridWarning.Show(campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information); return; } string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } CampusCache.Flush(campus.Id); campusService.Delete(campus); rockContext.SaveChanges(); } 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(); var campusService = new CampusService(rockContext); var campus = new CampusService(rockContext).Get(HiddenCampusId); if (campus != null) { // Don't allow deleting the last campus if (!campusService.Queryable().Where(c => c.Id != campus.Id).Any()) { mdDeleteWarning.Show(campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information); return; } string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus); rockContext.SaveChanges(); NavigateToParentPage(); } }
/// <summary> /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); CampusService campusService = new CampusService(rockContext); Campus campus = campusService.Get((int)e.RowKeyValue); if (campus != null) { string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { CampusService campusService = new CampusService(); Campus campus = campusService.Get((int)e.RowKeyValue); if (campus != null) { string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus, CurrentPersonId); campusService.Save(campus, CurrentPersonId); } }); BindGrid(); }