/// <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?categoryId = null; var rockContext = new RockContext(); var service = new MergeTemplateService(rockContext); var item = service.Get(hfMergeTemplateId.Value.AsInteger()); if (item != null) { string errorMessage; if (!service.CanDelete(item, out errorMessage)) { ShowReadonlyDetails(item); mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); } else { categoryId = item.CategoryId; service.Delete(item); rockContext.SaveChanges(); // set IsTemporary to true so that the file will eventually get cleaned up BinaryFileService binaryFileService = new BinaryFileService(rockContext); var binaryFile = binaryFileService.Get(item.TemplateBinaryFileId); if (binaryFile != null && binaryFile.IsTemporary) { binaryFile.IsTemporary = false; } // reload page, selecting the deleted item's parent var qryParams = new Dictionary <string, string>(); if (categoryId != null) { qryParams["CategoryId"] = categoryId.ToString(); } qryParams["ExpandedIds"] = PageParameter("ExpandedIds"); NavigateToPage(RockPage.Guid, qryParams); } } }
/// <summary> /// Handles the Delete event of the gMergeTemplates 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 gMergeTemplates_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); MergeTemplateService service = new MergeTemplateService( rockContext ); MergeTemplate item = service.Get( e.RowKeyId ); if ( item != null ) { string errorMessage; if ( !service.CanDelete( item, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } service.Delete( item ); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gMergeTemplates 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 gMergeTemplates_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); MergeTemplateService service = new MergeTemplateService(rockContext); MergeTemplate item = service.Get(e.RowKeyId); if (item != null) { string errorMessage; if (!service.CanDelete(item, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } service.Delete(item); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="mergeTemplateId">The merge template identifier.</param> /// <param name="parentCategoryId">The parent category identifier.</param> public void ShowDetail( int mergeTemplateId, int? parentCategoryId ) { pnlDetails.Visible = false; var rockContext = new RockContext(); var mergeTemplateService = new MergeTemplateService( rockContext ); MergeTemplate mergeTemplate = null; if ( !mergeTemplateId.Equals( 0 ) ) { mergeTemplate = mergeTemplateService.Get( mergeTemplateId ); } var mergeTemplateOwnership = this.GetAttributeValue( "MergeTemplatesOwnership" ).ConvertToEnum<MergeTemplateOwnership>( MergeTemplateOwnership.Global ); if ( mergeTemplate == null ) { mergeTemplate = new MergeTemplate(); mergeTemplate.CategoryId = parentCategoryId ?? 0; if ( mergeTemplateOwnership == MergeTemplateOwnership.Personal ) { mergeTemplate.PersonAliasId = this.CurrentPersonAliasId; mergeTemplate.PersonAlias = this.CurrentPersonAlias; } } pnlDetails.Visible = true; hfMergeTemplateId.Value = mergeTemplateId.ToString(); // render UI based on Authorized bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( mergeTemplate.PersonAliasId.HasValue && mergeTemplate.PersonAlias.PersonId == this.CurrentPersonId ) { // Allow Person to edit their own Merge Templates } else if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( MergeTemplate.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( mergeTemplate ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = mergeTemplateService.CanDelete( mergeTemplate, out errorMessage ); if ( mergeTemplate.Id > 0 ) { ShowReadonlyDetails( mergeTemplate ); } else { ShowEditDetails( mergeTemplate ); } } }
/// <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? categoryId = null; var rockContext = new RockContext(); var service = new MergeTemplateService( rockContext ); var item = service.Get( hfMergeTemplateId.Value.AsInteger() ); if ( item != null ) { string errorMessage; if ( !service.CanDelete( item, out errorMessage ) ) { ShowReadonlyDetails( item ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = item.CategoryId; service.Delete( item ); rockContext.SaveChanges(); // set IsTemporary to true so that the file will eventually get cleaned up BinaryFileService binaryFileService = new BinaryFileService( rockContext ); var binaryFile = binaryFileService.Get( item.TemplateBinaryFileId ); if ( binaryFile != null && binaryFile.IsTemporary ) { binaryFile.IsTemporary = false; } // reload page, selecting the deleted item's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" ); NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="mergeTemplateId">The merge template identifier.</param> /// <param name="parentCategoryId">The parent category identifier.</param> public void ShowDetail(int mergeTemplateId, int?parentCategoryId) { pnlDetails.Visible = false; var rockContext = new RockContext(); var mergeTemplateService = new MergeTemplateService(rockContext); MergeTemplate mergeTemplate = null; if (!mergeTemplateId.Equals(0)) { mergeTemplate = mergeTemplateService.Get(mergeTemplateId); pdAuditDetails.SetEntity(mergeTemplate, ResolveRockUrl("~")); } var mergeTemplateOwnership = this.GetAttributeValue("MergeTemplatesOwnership").ConvertToEnum <MergeTemplateOwnership>(MergeTemplateOwnership.Global); if (mergeTemplate == null) { mergeTemplate = new MergeTemplate(); mergeTemplate.CategoryId = parentCategoryId ?? 0; if (mergeTemplateOwnership == MergeTemplateOwnership.Personal) { mergeTemplate.PersonAliasId = this.CurrentPersonAliasId; mergeTemplate.PersonAlias = this.CurrentPersonAlias; // Don't show security on a personal merge template. btnSecurity.Visible = false; } // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } pnlDetails.Visible = true; hfMergeTemplateId.Value = mergeTemplateId.ToString(); // render UI based on Authorized bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (mergeTemplate.PersonAliasId.HasValue && mergeTemplate.PersonAlias.PersonId == this.CurrentPersonId) { // Allow Person to edit their own Merge Templates } else if (!IsUserAuthorized(Authorization.EDIT)) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(MergeTemplate.FriendlyTypeName); } btnSecurity.Visible = mergeTemplate.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson); btnSecurity.Title = mergeTemplate.Name; btnSecurity.EntityId = mergeTemplate.Id; if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(mergeTemplate); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = mergeTemplateService.CanDelete(mergeTemplate, out errorMessage); if (mergeTemplate.Id > 0) { ShowReadonlyDetails(mergeTemplate); } else { ShowEditDetails(mergeTemplate); } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="mergeTemplateId">The merge template identifier.</param> /// <param name="parentCategoryId">The parent category identifier.</param> public void ShowDetail(int mergeTemplateId, int?parentCategoryId) { pnlDetails.Visible = false; var rockContext = new RockContext(); var mergeTemplateService = new MergeTemplateService(rockContext); MergeTemplate mergeTemplate = null; if (!mergeTemplateId.Equals(0)) { mergeTemplate = mergeTemplateService.Get(mergeTemplateId); } var mergeTemplateOwnership = this.GetAttributeValue("MergeTemplatesOwnership").ConvertToEnum <MergeTemplateOwnership>(MergeTemplateOwnership.Global); if (mergeTemplate == null) { mergeTemplate = new MergeTemplate(); mergeTemplate.CategoryId = parentCategoryId ?? 0; if (mergeTemplateOwnership == MergeTemplateOwnership.Personal) { mergeTemplate.PersonAliasId = this.CurrentPersonAliasId; mergeTemplate.PersonAlias = this.CurrentPersonAlias; } } pnlDetails.Visible = true; hfMergeTemplateId.Value = mergeTemplateId.ToString(); // render UI based on Authorized bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (mergeTemplate.PersonAliasId.HasValue && mergeTemplate.PersonAlias.PersonId == this.CurrentPersonId) { // Allow Person to edit their own Merge Templates } else if (!IsUserAuthorized(Authorization.EDIT)) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(MergeTemplate.FriendlyTypeName); } if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(mergeTemplate); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = mergeTemplateService.CanDelete(mergeTemplate, out errorMessage); if (mergeTemplate.Id > 0) { ShowReadonlyDetails(mergeTemplate); } else { ShowEditDetails(mergeTemplate); } } }