示例#1
0
        public AmoCrmImportResult Import(AmoCrmImportOptions options)
        {
            if (options.SimulateImport)
            {
                amoDataProvider = new SimulationImportDataProvider(attendanceUow);
            }

            amoDataProvider.SaveDataDuringImport = options.SaveImportData;

            if (!amoDataProvider.Authenticate())
            {
                return(new AmoCrmImportResult(new []
                {
                    new AmoCrmImportResultError
                    {
                        EntityType = AmoCrmEntityTypes.None,
                        Message = "Could not authenticate in amoCRM API"
                    }
                }));
            }

            if (options.StartFromScratch)
            {
                ClearExistingAttendanceData();
            }

            AmoCrmImportContext context;

            try
            {
                context = new AmoCrmImportContext(amoDataProvider, entityConverter, !options.IncludeHistoricalData);
            }
            catch (ImportSimulationException e)
            {
                return(new AmoCrmImportResult(new[]
                {
                    new AmoCrmImportResultError
                    {
                        EntityType = AmoCrmEntityTypes.None,
                        Message = e.Message
                    }
                }));
            }

            ImportUsers(context);
            ImportLevels(context);
            ImportLeadStatuses(context);
            SetupContactLeadLinks(context);
            ImportContacts(context);
            ImportLeads(context);

            attendanceUow.Commit();

            return(new AmoCrmImportResult());
        }
示例#2
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);
        }
示例#3
0
 public AmoCrmImportManager(IAmoDataProvider amoDataProvider, IAttendanceUow attendanceUow, IAmoCrmEntityConverter entityConverter)
 {
     this.amoDataProvider = amoDataProvider;
     this.attendanceUow   = attendanceUow;
     this.entityConverter = entityConverter;
 }