/// <summary> /// Handles the Click event of the btnSaveFinancialBatch 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 btnSaveFinancialBatch_Click(object sender, EventArgs e) { using (new Rock.Data.UnitOfWorkScope()) { var financialBatchService = new FinancialBatchService(); FinancialBatch financialBatch = null; int financialBatchId = 0; if (!string.IsNullOrEmpty(hfBatchId.Value)) { financialBatchId = int.Parse(hfBatchId.Value); } if (financialBatchId == 0) { financialBatch = new Rock.Model.FinancialBatch(); financialBatch.CreatedByPersonId = CurrentPersonId.Value; financialBatchService.Add(financialBatch, CurrentPersonId); } else { financialBatch = financialBatchService.Get(financialBatchId); } financialBatch.Name = tbName.Text; financialBatch.BatchStartDateTime = dtBatchDate.LowerValue; financialBatch.BatchEndDateTime = dtBatchDate.UpperValue; financialBatch.CampusId = cpCampus.SelectedCampusId; financialBatch.Status = (BatchStatus)ddlStatus.SelectedIndex; decimal fcontrolamt = 0; decimal.TryParse(tbControlAmount.Text, out fcontrolamt); financialBatch.ControlAmount = fcontrolamt; if (!financialBatch.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { financialBatchService.Save(financialBatch, CurrentPersonId); hfBatchId.SetValue(financialBatch.Id); }); } var savedFinancialBatch = new FinancialBatchService().Get(hfBatchId.ValueAsInt()); ShowReadOnly(savedFinancialBatch); }