Exemple #1
0
        private static void PopulateCFs(Lead1C lead1C, int acc_id, Lead lead)
        {
            foreach (var p in lead1C.GetType().GetProperties())
            {
                if (FieldLists.Leads[acc_id].ContainsKey(p.Name) &&
                    p.GetValue(lead1C) is not null)
                {
                    try { if ((string)p.GetValue(lead1C) == "")
                          {
                              continue;
                          }
                    }
                    catch { }

                    lead.custom_fields_values.Add(new Custom_fields_value()
                    {
                        field_id = FieldLists.Leads[acc_id][p.Name],
                        values   = new Custom_fields_value.Values[] { new Custom_fields_value.Values()
                                                                      {
                                                                          value = p.GetValue(lead1C)
                                                                      } }
                    });
                }
            }
        }
Exemple #2
0
        private static void PopulateCFs(Lead lead, int amo_acc, Lead1C lead1C)
        {
            if (lead.custom_fields_values is not null)
            {
                foreach (var p in lead1C.GetType().GetProperties())
                {
                    if (FieldLists.Leads[amo_acc].ContainsKey(p.Name) &&
                        lead.custom_fields_values.Any(x => x.field_id == FieldLists.Leads[amo_acc][p.Name]))
                    {
                        var value = lead.custom_fields_values.First(x => x.field_id == FieldLists.Leads[amo_acc][p.Name]).values[0].value;
                        if ((p.PropertyType == typeof(Guid?) ||
                             p.PropertyType == typeof(Guid)) &&
                            Guid.TryParse((string)value, out Guid guidValue))
                        {
                            p.SetValue(lead1C, guidValue);
                            continue;
                        }

                        p.SetValue(lead1C, value);
                    }
                }
            }
        }