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()); }
private void SaveImportData <T>(string responseString) { var type = typeof(T); var attribute = type.GetAttribute <AmoCrmResponseTypeAttribute>(); if (attribute == null) { throw new AttributeMissingException("Could not save import data: type " + type.Name + " is not marked with " + typeof(AmoCrmResponseTypeAttribute).Name + " attribute."); } var importData = attendanceUow.ImportData.GetByResponseType(attribute.ResponseType); if (importData == null) { importData = new ImportData { ResponseType = attribute.ResponseType, ResponseData = responseString }; attendanceUow.ImportData.Add(importData); } else { importData.ResponseData = responseString; attendanceUow.ImportData.Update(importData); } attendanceUow.Commit(); }