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()); }
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); }
public AmoCrmImportManager(IAmoDataProvider amoDataProvider, IAttendanceUow attendanceUow, IAmoCrmEntityConverter entityConverter) { this.amoDataProvider = amoDataProvider; this.attendanceUow = attendanceUow; this.entityConverter = entityConverter; }