Esempio n. 1
0
        /// <summary>
        /// Handles the Command event of the lnkAccount control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="CommandEventArgs"/> instance containing the event data.</param>
        protected void lnkAccount_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == LinkCommand.AccountClick)
            {
                var accountService = new FinancialAccountService(new RockContext());

                var queryParams = new Dictionary <string, string>();

                var accountId = e.CommandArgument.ToString();

                if (accountId.IsNotNullOrWhiteSpace())
                {
                    var accountIdNum = accountId.AsInteger();
                    var parentIds    = accountService.GetAllAncestorIds(accountIdNum).Reverse()?.ToList();
                    if (parentIds == null)
                    {
                        parentIds = new List <int>();
                    }

                    queryParams.Add("AccountId", accountId);
                    queryParams.Add("ExpandedIds", parentIds.Select(v => v.ToString()).JoinStrings(","));
                    NavigateToPage(Rock.SystemGuid.Page.ACCOUNTS.AsGuid(), queryParams);
                }
            }
        }
Esempio n. 2
0
        public Dictionary <string, List <string> > GetParentIds([FromUri] IEnumerable <string> ids)
        {
            var accountService = new FinancialAccountService(new Data.RockContext());
            var retVal         = new Dictionary <string, List <string> >();

            foreach (var id in ids)
            {
                var idString  = id.ToString();
                var ancestors = accountService.GetAllAncestorIds(id.AsInteger())?
                                .Reverse()?
                                .Select(v => v.ToString());

                if (!retVal.ContainsKey(idString))
                {
                    retVal.Add(idString, new List <string>(ancestors));
                }
            }

            return(retVal);
        }
Esempio n. 3
0
        public IEnumerable <int> GetParentIds(int id)
        {
            var accountService = new FinancialAccountService(new Data.RockContext());

            return(accountService.GetAllAncestorIds(id)?.Reverse());
        }
Esempio n. 4
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            string searchTerm = PageParameter("SearchTerm");

            var accountService = new FinancialAccountService(new RockContext());
            var accounts       = new List <FinancialAccount>();

            var glCodeStart = searchTerm.LastIndexOf('(');

            if (glCodeStart > -1)
            {
                searchTerm = searchTerm.Substring(glCodeStart).Replace("(", "").Replace(")", "");
            }

            searchTerm = searchTerm.Trim();

            accounts = accountService.GetAccountsBySearchTerm(searchTerm)?.ToList();

            if (accounts?.Count == 1)
            {
                var pageService = new PageService(new RockContext());

                var queryParams = new Dictionary <string, string>();

                var accountId = accounts.First().Id;
                var parentIds = accountService.GetAllAncestorIds(accountId).Reverse()?.ToList();
                if (parentIds == null)
                {
                    parentIds = new List <int>();
                }
                queryParams.Add("AccountId", accountId.ToString());
                queryParams.Add("ExpandedIds", parentIds.Select(v => v.ToString()).JoinStrings(","));
                NavigateToPage(Rock.SystemGuid.Page.ACCOUNTS.AsGuid(), queryParams);
            }
            else
            {
                gAccounts.EntityTypeId = EntityTypeCache.Get <FinancialAccount>().Id;
                gAccounts.DataSource   = accounts?
                                         .Select(act => new
                {
                    act.Id,
                    Name        = act.Name,
                    PublicName  = act.PublicName.IsNullOrWhiteSpace() ? "" : act.PublicName,
                    GlCode      = act.GlCode,
                    AccountType = act.AccountTypeValue?.Value,
                    Description = act.Description,
                    Path        = accountService.GetDelimitedAccountHierarchy(act, FinancialAccountService.AccountHierarchyDirection.CurrentAccountToParent)?.Replace("^", " > ")
                })
                                         .ToList();

                gAccounts.DataBind();

                foreach (DataControlField dcf in gAccounts.Columns)
                {
                    var rtf = dcf as RockTemplateField;
                    var rtfAccountDescription = dcf as RockTemplateField;

                    if (rtf != null)
                    {
                        if (rtf.ID == "rtfAccountType")
                        {
                            rtf.Visible = this.GetAttributeValue(AttributeKey.ShowAccountType).AsBoolean();
                        }
                    }

                    if (rtfAccountDescription != null)
                    {
                        if (rtfAccountDescription.ID == "rtfAccountDescription")
                        {
                            rtfAccountDescription.Visible = this.GetAttributeValue(AttributeKey.ShowAccountDescription).AsBoolean();
                        }
                    }
                }
            }
        }