/// <summary> /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e) { var rockContext = new RockContext(); ImageCashLetterFileFormat fileFormat = null; var fileFormatService = new ImageCashLetterFileFormatService(rockContext); if (FileFormatId != 0) { fileFormat = fileFormatService.Get(FileFormatId); } if (fileFormat == null) { fileFormat = new ImageCashLetterFileFormat(); fileFormatService.Add(fileFormat); } if (fileFormat != null) { var completedProjectIds = new List <int>(); fileFormat.Name = tbName.Text; fileFormat.Description = tbDescription.Text; fileFormat.IsActive = cbIsActive.Checked; fileFormat.FileNameTemplate = tbFileNameTemplate.Text; fileFormat.EntityTypeId = cpFileFormatType.SelectedEntityTypeId; // // Store the attribute values. // fileFormat.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phEditAttributes, fileFormat); if (!Page.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); fileFormat.SaveAttributeValues(rockContext); }); NavigateToParentPage(); } }
/// <summary> /// Handles the Delete event of the 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 gFileFormat_Delete(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var rockContext = new RockContext(); var fileFormatService = new ImageCashLetterFileFormatService(rockContext); var fileFormat = fileFormatService.Get(e.RowKeyId); if (fileFormat != null) { int fileFormatId = fileFormat.Id; if (!fileFormat.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson)) { mdGridWarning.Show("Sorry, you're not authorized to delete this file format.", ModalAlertType.Alert); return; } fileFormatService.Delete(fileFormat); rockContext.SaveChanges(); } BindGrid(); }