Exemple #1
0
        public AmoCrmImportContext(IAmoDataProvider provider, IAmoCrmEntityConverter converter, bool excludeHistoricalData = true)
        {
            var contactsResponse         = provider.GetContacts();
            var leadsResponse            = provider.GetLeads();
            var contactLeadLinksResponse = provider.GetContactLeadLinks();
            var accountResponse          = provider.GetAccount();

            ContactsMap = contactsResponse.Response.Entities.Select(converter.Convert).ToDictionaryByFirstOccurence(c => c.AmoId);
            var leads = leadsResponse.Response.Entities.Select(converter.Convert);

            UsersMap = accountResponse.Response.Account.Users.Select(converter.Convert).ToDictionaryByFirstOccurence(c => c.AmoId);

            LeadContactsMap = BuildLeadContactLinks(contactLeadLinksResponse.Response.Entities);

            SetupLevels(converter, accountResponse);
            SetupLeadStatuses(converter, accountResponse);

            if (excludeHistoricalData)
            {
                leads = leads.Where(l => !IsHistorical(l));
            }

            LeadsMap = leads.ToDictionaryByFirstOccurence(c => c.AmoId);
        }