/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e) { FinancialAccount account; var rockContext = new RockContext(); var accountService = new Rock.Model.FinancialAccountService(rockContext); int accountId = hfAccountId.Value.AsInteger(); if (accountId == 0) { account = new Rock.Model.FinancialAccount(); accountService.Add(account); account.CreatedByPersonAliasId = CurrentPersonAliasId; account.CreatedDateTime = RockDateTime.Now; } else { account = accountService.Get(accountId); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.IsPublic = cbIsPublic.Checked; account.Description = tbDescription.Text; account.PublicDescription = cePublicDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.Url = tbUrl.Text; account.CampusId = cpCampus.SelectedValueAsInt(); account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; account.ModifiedDateTime = RockDateTime.Now; account.ModifiedByPersonAliasId = CurrentPersonAliasId; account.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, account); // if the account IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of account didn't pass. // So, make sure a message is displayed in the validation summary cvAccount.IsValid = account.IsValid; if (!cvAccount.IsValid) { cvAccount.ErrorMessage = account.ValidationResults.Select(a => a.ErrorMessage).ToList().AsDelimited("<br />"); return; } rockContext.SaveChanges(); account.SaveAttributeValues(rockContext); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSaveAccount 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 btnSaveAccount_Click(object sender, EventArgs e) { using (new Rock.Data.UnitOfWorkScope()) { var accountService = new Rock.Model.FinancialAccountService(); Rock.Model.FinancialAccount modifiedAccount; int accountId = (hfAccountId.Value) != null?Int32.Parse(hfAccountId.Value) : 0; if (accountId == 0) { modifiedAccount = new Rock.Model.FinancialAccount(); accountService.Add(modifiedAccount, CurrentPersonId); } else { modifiedAccount = accountService.Get(accountId); } modifiedAccount.Name = tbName.Text; modifiedAccount.PublicName = tbPublicName.Text; modifiedAccount.Description = tbDescription.Text; modifiedAccount.Order = Int32.Parse(tbOrder.Text); modifiedAccount.GlCode = tbGLCode.Text; modifiedAccount.IsActive = cbIsActive.Checked; modifiedAccount.IsTaxDeductible = cbIsTaxDeductible.Checked; modifiedAccount.StartDate = dtpStartDate.SelectedDate; modifiedAccount.EndDate = dtpEndDate.SelectedDate; modifiedAccount.ParentAccountId = apParentAccount.SelectedValueAsInt(); modifiedAccount.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); accountService.Save(modifiedAccount, CurrentPersonId); } //BindCategoryFilter(); BindGrid(); pnlAccountDetails.Visible = false; pnlAccountList.Visible = true; }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e) { FinancialAccount account; var rockContext = new RockContext(); var accountService = new Rock.Model.FinancialAccountService(rockContext); int accountId = hfAccountId.Value.AsInteger(); if (accountId == 0) { account = new Rock.Model.FinancialAccount(); accountService.Add(account); } else { account = accountService.Get(accountId); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.IsPublic = cbIsPublic.Checked; account.Description = tbDescription.Text; account.PublicDescription = cePublicDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.Url = tbUrl.Text; account.CampusId = cpCampus.SelectedValueAsInt(); account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; rockContext.SaveChanges(); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { FinancialAccount account; using ( new Rock.Data.UnitOfWorkScope() ) { var accountService = new Rock.Model.FinancialAccountService(); int accountId = Int32.Parse( hfAccountId.Value ); if ( accountId == 0 ) { account = new Rock.Model.FinancialAccount(); accountService.Add( account, CurrentPersonId ); } else { account = accountService.Get( accountId ); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.Description = tbDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; accountService.Save( account, CurrentPersonId ); } NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e) { FinancialAccount account; using (new Rock.Data.UnitOfWorkScope()) { var accountService = new Rock.Model.FinancialAccountService(); int accountId = Int32.Parse(hfAccountId.Value); if (accountId == 0) { account = new Rock.Model.FinancialAccount(); accountService.Add(account, CurrentPersonId); } else { account = accountService.Get(accountId); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.Description = tbDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; accountService.Save(account, CurrentPersonId); } NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { FinancialAccount account; var rockContext = new RockContext(); var accountService = new Rock.Model.FinancialAccountService( rockContext ); int accountId = hfAccountId.Value.AsInteger(); if ( accountId == 0 ) { account = new Rock.Model.FinancialAccount(); accountService.Add( account ); } else { account = accountService.Get( accountId ); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.Description = tbDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.CampusId = cpCampus.SelectedValueAsInt(); account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; rockContext.SaveChanges(); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e) { FinancialAccount account; var rockContext = new RockContext(); var accountService = new Rock.Model.FinancialAccountService(rockContext); int accountId = hfAccountId.Value.AsInteger(); if (accountId == 0) { account = new Rock.Model.FinancialAccount(); accountService.Add(account); account.CreatedByPersonAliasId = CurrentPersonAliasId; account.CreatedDateTime = RockDateTime.Now; } else { account = accountService.Get(accountId); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.IsPublic = cbIsPublic.Checked; account.Description = tbDescription.Text; account.PublicDescription = cePublicDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = dvpAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.Url = tbUrl.Text; account.CampusId = cpCampus.SelectedValueAsInt(); account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; account.ModifiedDateTime = RockDateTime.Now; account.ModifiedByPersonAliasId = CurrentPersonAliasId; account.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, account); // if the account IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of account didn't pass. // So, make sure a message is displayed in the validation summary cvAccount.IsValid = account.IsValid; if (!cvAccount.IsValid) { cvAccount.ErrorMessage = account.ValidationResults.Select(a => a.ErrorMessage).ToList().AsDelimited("<br />"); return; } if (accountId == 0) { // just added, but we'll need an Id to set account participants rockContext.SaveChanges(); accountId = new FinancialAccountService(new RockContext()).GetId(account.Guid) ?? 0; } var accountParticipantsPersonAliasIdsByPurposeKey = AccountParticipantState.GroupBy(a => a.PurposeKey).ToDictionary(k => k.Key, v => v.Select(x => x.PersonAliasId).ToList()); foreach (var purposeKey in accountParticipantsPersonAliasIdsByPurposeKey.Keys) { var accountParticipantsPersonAliasIds = accountParticipantsPersonAliasIdsByPurposeKey.GetValueOrNull(purposeKey); if (accountParticipantsPersonAliasIds?.Any() == true) { var accountParticipants = new PersonAliasService(rockContext).GetByIds(accountParticipantsPersonAliasIds).ToList(); accountService.SetAccountParticipants(accountId, accountParticipants, purposeKey); } } rockContext.SaveChanges(); account.SaveAttributeValues(rockContext); var qryParams = new Dictionary <string, string>(); qryParams["AccountId"] = account.Id.ToString(); qryParams["ExpandedIds"] = PageParameter("ExpandedIds"); NavigateToPage(RockPage.Guid, qryParams); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { FinancialAccount account; var rockContext = new RockContext(); var accountService = new Rock.Model.FinancialAccountService( rockContext ); int accountId = hfAccountId.Value.AsInteger(); if ( accountId == 0 ) { account = new Rock.Model.FinancialAccount(); accountService.Add( account ); } else { account = accountService.Get( accountId ); } account.Name = tbName.Text; account.IsActive = cbIsActive.Checked; account.IsPublic = cbIsPublic.Checked; account.Description = tbDescription.Text; account.PublicDescription = cePublicDescription.Text; account.ParentAccountId = apParentAccount.SelectedValueAsInt(); account.AccountTypeValueId = ddlAccountType.SelectedValueAsInt(); account.PublicName = tbPublicName.Text; account.Url = tbUrl.Text; account.CampusId = cpCampus.SelectedValueAsInt(); account.GlCode = tbGLCode.Text; account.StartDate = dtpStartDate.SelectedDate; account.EndDate = dtpEndDate.SelectedDate; account.IsTaxDeductible = cbIsTaxDeductible.Checked; // if the account IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of account didn't pass. // So, make sure a message is displayed in the validation summary cvAccount.IsValid = account.IsValid; if ( !cvAccount.IsValid ) { cvAccount.ErrorMessage = account.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" ); return; } rockContext.SaveChanges(); NavigateToParentPage(); }