Exemplo n.º 1
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            Guid?guid = value.AsGuidOrNull();

            if (guid.HasValue)
            {
                bool displayPublicName = true;

                if (configurationValues != null &&
                    configurationValues.ContainsKey(DISPLAY_PUBLIC_NAME))
                {
                    displayPublicName = configurationValues[DISPLAY_PUBLIC_NAME].Value.AsBoolean();
                }

                using (var rockContext = new RockContext())
                {
                    var service = new FinancialAccountService(rockContext);
                    var account = service.GetNoTracking(guid.Value);

                    if (account != null)
                    {
                        formattedValue = displayPublicName ? account.PublicName : account.Name;
                    }
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }