/// <summary> /// Copies the properties from another FinancialAccount object to this FinancialAccount object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this FinancialAccount target, FinancialAccount source) { target.Id = source.Id; target.AccountTypeValueId = source.AccountTypeValueId; target.CampusId = source.CampusId; target.Description = source.Description; target.EndDate = source.EndDate; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; target.GlCode = source.GlCode; target.ImageBinaryFileId = source.ImageBinaryFileId; target.IsActive = source.IsActive; target.IsPublic = source.IsPublic; target.IsTaxDeductible = source.IsTaxDeductible; target.Name = source.Name; target.Order = source.Order; target.ParentAccountId = source.ParentAccountId; target.PublicDescription = source.PublicDescription; target.PublicName = source.PublicName; target.StartDate = source.StartDate; target.Url = source.Url; target.CreatedDateTime = source.CreatedDateTime; target.ModifiedDateTime = source.ModifiedDateTime; target.CreatedByPersonAliasId = source.CreatedByPersonAliasId; target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }
/// <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> /// Clones this FinancialAccount object to a new FinancialAccount object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static FinancialAccount Clone(this FinancialAccount source, bool deepCopy) { if (deepCopy) { return(source.Clone() as FinancialAccount); } else { var target = new FinancialAccount(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Copies the properties from another FinancialAccount object to this FinancialAccount object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this FinancialAccount target, FinancialAccount source) { target.ParentAccountId = source.ParentAccountId; target.CampusId = source.CampusId; target.Name = source.Name; target.PublicName = source.PublicName; target.Description = source.Description; target.IsTaxDeductible = source.IsTaxDeductible; target.GlCode = source.GlCode; target.Order = source.Order; target.IsActive = source.IsActive; target.StartDate = source.StartDate; target.EndDate = source.EndDate; target.AccountTypeValueId = source.AccountTypeValueId; target.Id = source.Id; target.Guid = source.Guid; }
/// <summary> /// Gets the account hierarchy path as a '^' delimited string.. /// </summary> /// <param name="account">The account.</param> /// <param name="accountHierarchyDirection">The account hierarchy direction.</param> /// <returns>System.String.</returns> public string GetDelimitedAccountHierarchy(FinancialAccount account, AccountHierarchyDirection accountHierarchyDirection = AccountHierarchyDirection.ParentAccountToLastDescendantAccount) { var selectedAccounts = new List <SimpleFinancialAccount>(); var relatedIds = accountHierarchyDirection == AccountHierarchyDirection.CurrentAccountToParent ? GetAllAncestorIds(account.Id) : GetAllDescendentIds(account.Id); var parentAccounts = GetParents(relatedIds?.ToArray())?.ToList(); selectedAccounts = parentAccounts.Select(v => new SimpleFinancialAccount { Id = v.Id, Name = HttpUtility.HtmlEncode(v.PublicName.IsNotNullOrWhiteSpace() ? v.PublicName : v.Name), GlCode = v.GlCode, IsActive = v.IsActive, ParentId = v.ParentAccountId })?.ToList(); return(selectedAccounts?.Select(v => v.Name).JoinStrings("^")); }
/// <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> /// Shows the edit. /// </summary> /// <param name="accountId">The account id.</param> protected void ShowEdit(int accountId) { var accountModel = new FinancialAccountService().Get(accountId); hfAccountId.Value = accountId.ToString(); string actionTitle; if (accountModel == null) { accountModel = new Rock.Model.FinancialAccount(); actionTitle = ActionTitle.Add(Rock.Model.Attribute.FriendlyTypeName); tbName.Text = string.Empty; tbPublicName.Text = string.Empty; tbDescription.Text = string.Empty; tbOrder.Text = string.Empty; tbGLCode.Text = string.Empty; cbIsActive.Checked = false; cbIsTaxDeductible.Checked = false; } else { actionTitle = ActionTitle.Edit(Rock.Model.Attribute.FriendlyTypeName); tbName.Text = accountModel.Name ?? string.Empty; tbPublicName.Text = accountModel.PublicName ?? string.Empty; tbDescription.Text = accountModel.Description ?? string.Empty; tbOrder.Text = accountModel.Order.ToString(); tbGLCode.Text = accountModel.GlCode ?? string.Empty; cbIsActive.Checked = accountModel.IsActive; cbIsTaxDeductible.Checked = accountModel.IsTaxDeductible; dtpStartDate.SelectedDate = accountModel.StartDate; dtpEndDate.SelectedDate = accountModel.EndDate; apParentAccount.SetValue(accountModel.ParentAccount); } pnlAccountList.Visible = false; pnlAccountDetails.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.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(); }