Esempio n. 1
0
        /// <summary>
        /// Formats the customer name
        /// </summary>
        /// <param name="customer">Source</param>
        /// <param name="stripTooLong">Strip too long customer name</param>
        /// <param name="maxLength">Maximum customer name length</param>
        /// <returns>Formatted text</returns>
        public static string FormatUserName(this Customer customer, CustomerNameFormat customerNameFormat, bool stripTooLong = false, int maxLength = 0)
        {
            if (customer == null)
            {
                return(string.Empty);
            }

            if (customer.IsGuest())
            {
                return("Customer.Guest");
            }

            string result = string.Empty;

            switch (customerNameFormat)
            {
            case CustomerNameFormat.ShowEmails:
                result = customer.Email;
                break;

            case CustomerNameFormat.ShowUsernames:
                result = customer.Username;
                break;

            case CustomerNameFormat.ShowFullNames:
                result = customer.GetFullName();
                break;

            case CustomerNameFormat.ShowFirstName:
                result = customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.FirstName);
                break;

            default:
                break;
            }

            if (stripTooLong && maxLength > 0)
            {
                result = CommonHelper.EnsureMaximumLength(result, maxLength);
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Formats the customer name
        /// </summary>
        /// <param name="customer">Source</param>
        /// <returns>Formatted text</returns>
        public static string FormatUserName(this Customer customer, CustomerNameFormat customerNameFormat)
        {
            if (customer == null)
            {
                return(string.Empty);
            }

            if (string.IsNullOrEmpty(customer.Email))
            {
                return("Customer.Guest");
            }

            string result = string.Empty;

            switch (customerNameFormat)
            {
            case CustomerNameFormat.Emails:
                result = customer.Email;
                break;

            case CustomerNameFormat.Usernames:
                result = customer.Username;
                break;

            case CustomerNameFormat.FullNames:
                result = customer.GetFullName();
                break;

            case CustomerNameFormat.FirstName:
                result = customer.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.FirstName);
                break;

            default:
                break;
            }

            return(result);
        }