/// <summary> /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService( rockContext ); MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get( e.RowKeyId ); if ( marketingCampaignAd != null ) { string errorMessage; if ( !marketingCampaignAdService.CanDelete( marketingCampaignAd, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } marketingCampaignAdService.Delete( marketingCampaignAd ); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService(); MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get(e.RowKeyId); if (marketingCampaignAd != null) { string errorMessage; if (!marketingCampaignAdService.CanDelete(marketingCampaignAd, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } marketingCampaignAdService.Delete(marketingCampaignAd, CurrentPersonId); marketingCampaignAdService.Save(marketingCampaignAd, CurrentPersonId); } }); BindGrid(); }