Beispiel #1
0
        private static void PopulateClientCFs(Contact contact, int amo_acc, Client1C client1C)
        {
            if (contact.custom_fields_values is not null)
            {
                foreach (var p in client1C.GetType().GetProperties())
                {
                    if (FieldLists.Contacts[amo_acc].ContainsKey(p.Name) &&
                        contact.custom_fields_values.Any(x => x.field_id == FieldLists.Contacts[amo_acc][p.Name]))
                    {
                        var value = contact.custom_fields_values.First(x => x.field_id == FieldLists.Contacts[amo_acc][p.Name]).values[0].value;
                        if (p.PropertyType == typeof(Guid?) &&
                            Guid.TryParse((string)value, out Guid guidValue))
                        {
                            p.SetValue(client1C, guidValue);
                            continue;
                        }

                        if (p.PropertyType == typeof(DateTime?) ||
                            p.PropertyType == typeof(DateTime))
                        {
                            if ((long)value < -2208996153)
                            {
                                value = -2208996153;
                            }
                            var dt = DateTimeOffset.FromUnixTimeSeconds((long)value).UtcDateTime.AddDays(1);
                            p.SetValue(client1C, new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0));
                            continue;
                        }

                        p.SetValue(client1C, value);
                    }
                }
            }
        }
Beispiel #2
0
        private static void PopulateCFs(Client1C client1C, int acc_id, Contact contact)
        {
            foreach (var p in client1C.GetType().GetProperties())
            {
                if (FieldLists.Contacts[acc_id].ContainsKey(p.Name) &&
                    p.GetValue(client1C) is not null)
                {
                    var value = p.GetValue(client1C);
                    if (p.Name == "dob" ||
                        p.Name == "pass_issued_at")
                    {
                        DateTime dt = (DateTime)p.GetValue(client1C);
                        value = ((DateTimeOffset)dt.AddHours(3)).ToUnixTimeSeconds();
                    }

                    //if (p.Name == "phone" || p.Name == "email") continue;

                    try { if ((string)value == "")
                          {
                              continue;
                          }
                    }
                    catch { }

                    if (contact.custom_fields_values is null)
                    {
                        contact.custom_fields_values = new();
                    }

                    contact.AddNewCF(FieldLists.Contacts[acc_id][p.Name], value);
                }
            }
        }