예제 #1
0
 static void AddCustomElement(XElement contactElement, CustomElement customElement)
 {
     XElement customElementType = new XElement("{http://www.aimscrm.com/schema/2011/common/contact}CustomElement");
     XElement nameElement = new XElement("{http://www.aimscrm.com/schema/2011/common/contact}Name", customElement.Name);
     XElement valueElement = new XElement("{http://www.aimscrm.com/schema/2011/common/contact}Value", customElement.Value);
     customElementType.Add(nameElement);
     customElementType.Add(valueElement);
     contactElement.Element("{http://www.aimscrm.com/schema/2011/common/contact}Custom").Add(customElementType);
 }
예제 #2
0
        private static ConversionResult ConvertRowsToContacts(IEnumerable<DataRow> rawRows, IEnumerable<FieldMap> fieldMaps, Category category, Flag flag)
        {
            int successCount = 0, failureCount = 0, duplicateCount = 0;

            var contacts = new List<AllClientsContact>();
            foreach (var rawRow in rawRows)
            {
                var contact = new AllClientsContact();
                contact.FirstName = GetFieldMapValue(rawRow, fieldMaps, "FirstName");
                contact.LastName = GetFieldMapValue(rawRow, fieldMaps, "LastName");
                contact.City = GetFieldMapValue(rawRow, fieldMaps, "City");
                contact.State = GetFieldMapValue(rawRow, fieldMaps, "State");
                contact.Zip = GetFieldMapValue(rawRow, fieldMaps, "Zip");
                contact.Email = GetFieldMapValue(rawRow, fieldMaps, "Email");
                contact.Company = GetFieldMapValue(rawRow, fieldMaps, "Company");
                contact.Phone = GetFieldMapValue(rawRow, fieldMaps, "Phone");
                contact.Categories.Add(category);

                contact.Custom = new List<CustomElement>();
                var birthDate = new CustomElement { Name = "Birthday", Value = GetFieldMapValue(rawRow, fieldMaps, "Birthday") };
                contact.Custom.Add(birthDate);
                contact.Flags.Add(flag);

                if (!contact.IsValid())
                {
                    failureCount++;
                    continue;
                }
                if (contacts.Where(x => x.Email == contact.Email).Count() != 0)
                {
                    duplicateCount++;
                    continue;
                }
                successCount++;
                contacts.Add(contact);
            }
            return new ConversionResult { SuccessCount = successCount, FailureCount = failureCount, DuplicateCount = duplicateCount, Contacts = contacts };
        }