public static void Parse(Token token, ref VCard vcard)
        {
            var deliveryAddress = new DeliveryAddress();

            if (vcard.Version == VCardVersion.V4)
            {
                string address = token.Values[0];
                string type    = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE").Value;

                deliveryAddress.Address = address;
                deliveryAddress.Type    = AddressTypeLookup.Parse(type);
            }

            vcard.DeliveryAddress = deliveryAddress;
        }
 /// <summary>
 /// Creates a address type
 /// </summary>
 /// <param name="addressTypeModel"></param>
 /// <returns></returns>
 public int Create(AddressTypeModel addressTypeModel)
 {
     using (var scope = new TransactionScope())
     {
         var addressType = new AddressTypeLookup()
         {
             AddressType = addressTypeModel.AddressType,
             Archived    = addressTypeModel.Archived
         };
         var addressTypeCheck = _dbActions.AddressTypeRepository.GetSingle(p => p.AddressType == addressTypeModel.AddressType);
         if (addressTypeCheck == null)
         {
             _dbActions.AddressTypeRepository.Insert(addressType);
             _dbActions.Save();
             scope.Complete();
             return(addressType.Id);
         }
         scope.Complete();
         return(-1);
     }
 }
Exemple #3
0
        public static void Parse(Token token, ref VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(string.Join("", token.Values).Trim()))
            {
                return;
            }

            var address = new Address();

            if (vcard.Version == VCardVersion.V4)
            {
                var geo = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "GEO");
                if (!string.IsNullOrWhiteSpace(geo.Value))
                {
                    var coordinates = geo.Value.Split(',').Select(x => x.Trim()).ToList();

                    if (coordinates.Count > 0)
                    {
                        address.Longitude = coordinates[0].ConvertToNullableT <double>();
                    }

                    if (coordinates.Count > 1)
                    {
                        address.Latitude = coordinates[0].ConvertToNullableT <double>();
                    }
                }

                var type = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE");
                address.Type = AddressTypeLookup.Parse(type.Value);

                var pref = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "PREF");
                address.Preference = pref.Value.ConvertTo <int>();

                var label = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "LABEL");
                address.Label = label.Value;

                var timezone = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TZ");
                address.TimeZone = TimeZoneInfoProcessor.FromVCardValue(timezone.Value);
            }

            if (token.Values.Length > 0)
            {
                address.PoBox = token.Values[0];
            }

            if (token.Values.Length > 1)
            {
                address.ExtendedAddress = token.Values[1];
            }

            if (token.Values.Length > 2)
            {
                address.Street = token.Values[2];
            }

            if (token.Values.Length > 3)
            {
                address.Locality = token.Values[3];
            }

            if (token.Values.Length > 4)
            {
                address.Region = token.Values[4];
            }

            if (token.Values.Length > 5)
            {
                address.PostalCode = token.Values[5];
            }

            if (token.Values.Length > 6)
            {
                address.Country = token.Values[6];
            }

            var addresses = (List <Address>)vcard.Addresses ?? new List <Address>();

            addresses.Add(address);
            vcard.Addresses = addresses;
        }
Exemple #4
0
        public static void Parse(Token token, ref VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(string.Join("", token.Values).Trim()))
            {
                return;
            }

            var address = new Address();

            if (vcard.Version == VCardVersion.V4)
            {
                var geo = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "GEO");
                if (!string.IsNullOrWhiteSpace(geo.Value))
                {
                    var coordinates = geo.Value.Split(',').Select(x => x.Trim()).ToList();

                    if (coordinates.Count > 0)
                    {
                        address.Longitude = coordinates[0].ConvertToNullableT <double>();
                    }

                    if (coordinates.Count > 1)
                    {
                        address.Latitude = coordinates[0].ConvertToNullableT <double>();
                    }
                }

                var type = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE");
                address.Type = AddressTypeLookup.Parse(type.Value);

                var pref = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "PREF");
                address.Preference = pref.Value.ConvertTo <int>();

                var label = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "LABEL");
                address.Label = label.Value;

                var timezone = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TZ");
                address.TimeZone = TimeZoneInfoProcessor.FromVCardValue(timezone.Value);
            }

            if (token.Values.Length > 0)
            {
                address.PoBox = token.Values[0];
            }

            if (token.Values.Length > 1)
            {
                address.ExtendedAddress = token.Values[1];
            }

            if (token.Values.Length > 2)
            {
                address.Street = token.Values[2];
            }

            if (token.Values.Length > 3)
            {
                address.Locality = token.Values[3];
            }

            if (token.Values.Length > 4)
            {
                address.Region = token.Values[4];
            }

            if (token.Values.Length > 5)
            {
                address.PostalCode = token.Values[5];
            }

            if (token.Values.Length > 6)
            {
                address.Country = token.Values[6];
            }

            // fix issues deseralizing Non-US Addresses
            if (vcard.Version == VCardVersion.V2_1 && vcard.SerializedCard != null)
            {
                Match match = Regex.Match(vcard.SerializedCard,
                                          "ADR;WORK;PREF(;ENCODING=QUOTED-PRINTABLE)?:;;(?<address>.*)LABEL;WORK;PREF;",
                                          RegexOptions.Singleline);
                if (match.Success)
                {
                    // clean the string
                    string adrstring = match.Groups["address"].Value;
                    adrstring = adrstring.Replace("=0D=0A=", ";")
                                .Replace("\r\n", ";").Replace("\r", ";").Replace("\n", ";");
                    var newtokens = adrstring.Split(';').Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    // interpret depending on token count
                    if (newtokens.Length == 4)
                    {
                        address.Street     = newtokens[0];
                        address.Locality   = newtokens[1];
                        address.PostalCode = newtokens[2];
                        address.Region     = newtokens[3];
                        address.Country    = address.Region;
                    }
                    else if (newtokens.Length == 5)
                    {
                        address.Street     = newtokens[0];
                        address.Locality   = newtokens[1];
                        address.Region     = newtokens[2];
                        address.PostalCode = newtokens[3];
                        address.Country    = newtokens[4];
                    }
                    else if (newtokens.Length == 6)
                    {
                        address.Street     = newtokens[0] + ", " + newtokens[1];
                        address.Locality   = newtokens[2];
                        address.Region     = newtokens[3];
                        address.PostalCode = newtokens[4];
                        address.Country    = newtokens[5];
                    }
                }
            }

            var addresses = (List <Address>)vcard.Addresses ?? new List <Address>();

            addresses.Add(address);
            vcard.Addresses = addresses;
        }
Exemple #5
0
 public static Address Create(int addressId, bool isActive, DateTime endDate, AddressLine address1,
                              AddressLine address2, AddressLine address3, AddressLine address4, bool isPrimary, AddressTypeLookup addressType,
                              Attention attention, City city, string comments, PostalCode postalCode, StateCodeLookup stateCode)
 {
     return(new Address
     {
         Id = addressId,
         IsActive = isActive,
         EndDate = endDate,
         Address1 = address1,
         Address2 = address2,
         Address3 = address3,
         Address4 = address4,
         IsPrimary = isPrimary,
         AddressTypeId = addressType.AddressTypeId,
         Attention = attention,
         City = city,
         Comments = comments,
         PostalCode = postalCode,
         StateCodeId = stateCode.StateCodeId
     });
 }