Beispiel #1
0
        /// <summary>
        /// Formats the address according to the specified format string.
        /// </summary>
        /// <remarks>
        /// Valid format specifiers are as follows:
        ///     %C - country code, preceded by +
        ///     %c - country code if different from default country code specified in <see cref="FormatSettings"/>
        ///     %A - area code
        ///     %N - phone number in form XXX-XXXX
        ///     %X - extension, preceded by x
        /// </remarks>
        /// <param name="tn"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string Format(TelephoneDetail tn, string format)
        {
            string result = format;

            result = result.Replace("%C", tn.CountryCode == null ? "" : string.Format("+{0}", tn.CountryCode));

            result = result.Replace("%c",
                                    (tn.CountryCode == null || tn.CountryCode == FormatSettings.Default.TelephoneNumberSuppressCountryCode) ? ""
                : string.Format("+{0}", tn.CountryCode));

            result = result.Replace("%A", tn.AreaCode == null ? "" : tn.AreaCode);
            result = result.Replace("%N", StringMask.Apply(tn.Number, FormatSettings.Default.TelephoneNumberLocalMask) ?? "");
            result = result.Replace("%X", string.IsNullOrEmpty(tn.Extension) ? "" : string.Format("x{0}", tn.Extension));

            return(result.Trim());
        }
        public TelephoneNumber CreateTelephoneNumber(TelephoneDetail telephoneDetail)
        {
            if (telephoneDetail == null)
            {
                return(null);
            }

            TelephoneNumber telephoneNumber = new TelephoneNumber();

            telephoneNumber.CountryCode      = telephoneDetail.CountryCode;
            telephoneNumber.AreaCode         = telephoneDetail.AreaCode;
            telephoneNumber.Number           = telephoneDetail.Number;
            telephoneNumber.Extension        = telephoneDetail.Extension;
            telephoneNumber.ValidRange.From  = telephoneDetail.ValidRangeFrom;
            telephoneNumber.ValidRange.Until = telephoneDetail.ValidRangeUntil;

            SimplifiedPhoneTypeAssembler simplePhoneTypeAssembler = new SimplifiedPhoneTypeAssembler();

            simplePhoneTypeAssembler.UpdatePhoneNumber(telephoneDetail.Type, telephoneNumber);

            return(telephoneNumber);
        }
        public TelephoneDetail CreateTelephoneDetail(TelephoneNumber telephoneNumber, IPersistenceContext context)
        {
            if (telephoneNumber == null)
            {
                return(null);
            }

            TelephoneDetail telephoneDetail = new TelephoneDetail();

            telephoneDetail.CountryCode = telephoneNumber.CountryCode;
            telephoneDetail.AreaCode    = telephoneNumber.AreaCode;
            telephoneDetail.Number      = telephoneNumber.Number;
            telephoneDetail.Extension   = telephoneNumber.Extension;

            SimplifiedPhoneTypeAssembler simplePhoneTypeAssembler = new SimplifiedPhoneTypeAssembler();

            telephoneDetail.Type = simplePhoneTypeAssembler.GetSimplifiedPhoneType(telephoneNumber);

            telephoneDetail.ValidRangeFrom  = telephoneNumber.ValidRange.From;
            telephoneDetail.ValidRangeUntil = telephoneNumber.ValidRange.Until;

            return(telephoneDetail);
        }
Beispiel #4
0
 /// <summary>
 /// Formats the telephone number according to the default format as specified in <see cref="FormatSettings"/>
 /// </summary>
 /// <param name="tn"></param>
 /// <returns></returns>
 public static string Format(TelephoneDetail tn)
 {
     return(Format(tn, FormatSettings.Default.TelephoneNumberDefaultFormat));
 }
 public PhoneNumberEditorComponent(TelephoneDetail phoneNumber, List <EnumValueInfo> phoneTypeChoices)
 {
     _phoneNumber      = phoneNumber;
     _phoneTypeChoices = phoneTypeChoices;
     _phoneTypeEnabled = phoneTypeChoices.Count > 1;
 }