public void TestSetup() { this._consumerProfile = new ConsumerProfile() { ConsumerKey = "ConsumerKey", ConsumerSecret = "ConsumerSecret" }; this._restProfile = new RestProfile() { AppToken = "AppToken", DataSource = 1, OAuthAccessToken = "OAuthAccessToken", OAuthAccessTokenSecret = "OAuthAccessTokenSecret", RealmId = "RealmId" }; this._quickBooksAuthenticatedUserCredentials = new QuickBooksOnlineAuthenticatedUserCredentials( this._restProfile.RealmId, this._restProfile.OAuthAccessToken, this._restProfile.OAuthAccessTokenSecret, this._restProfile.DataSource); this._quickBooksNonAuthenticatedUserCredentials = new QuickBooksOnlineNonAuthenticatedUserCredentials( this._restProfile.AppToken, this._consumerProfile.ConsumerKey, this._consumerProfile.ConsumerSecret, "http://localhost:27286/home/Callback"); this._quickBooksService = new QuickBooksOnlineService(this._quickBooksAuthenticatedUserCredentials, this._quickBooksNonAuthenticatedUserCredentials); }
public QuickBooksOnlineServiceSdk(RestProfile restProfile, ConsumerProfile consumerProfile) { this.RestProfile = restProfile; this.ConsumerProfile = consumerProfile; this._requestValidator = new OAuthRequestValidator(this.RestProfile.OAuthAccessToken, this.RestProfile.OAuthAccessTokenSecret, this.ConsumerProfile.ConsumerKey, this.ConsumerProfile.ConsumerSecret); this._serviceContext = new ServiceContext(this.RestProfile.AppToken, this.RestProfile.RealmId, IntuitServicesType.QBO, this._requestValidator); this._dataService = new DataService(this._serviceContext); this._queryServiceItem = new QueryService <Item>(this._serviceContext); this._queryServicePayment = new QueryService <Payment>(this._serviceContext); this._queryServiceAccount = new QueryService <Account>(this._serviceContext); this._queryServicePurchaseOrder = new QueryService <PurchaseOrder>(this._serviceContext); this._queryServiceBill = new QueryService <Bill>(this._serviceContext); this._queryServiceSalesReceipt = new QueryService <SalesReceipt>(this._serviceContext); this._queryServiceInvoice = new QueryService <Invoice>(this._serviceContext); this._queryServiceCustomer = new QueryService <Customer>(this._serviceContext); }
public QuickBooksOnlineService(QuickBooksOnlineAuthenticatedUserCredentials quickBooksAuthenticatedUserCredentials, QuickBooksOnlineNonAuthenticatedUserCredentials quickBooksNonAuthenticatedUserCredentials) { this._restProfile = new RestProfile() { AppToken = quickBooksNonAuthenticatedUserCredentials.AppToken, DataSource = quickBooksAuthenticatedUserCredentials.DataSource, OAuthAccessToken = quickBooksAuthenticatedUserCredentials.OAuthAccessToken, OAuthAccessTokenSecret = quickBooksAuthenticatedUserCredentials.OAuthAccessTokenSecret, RealmId = quickBooksAuthenticatedUserCredentials.RealmId, }; this._consumerProfile = new ConsumerProfile() { ConsumerKey = quickBooksNonAuthenticatedUserCredentials.ConsumerKey, ConsumerSecret = quickBooksNonAuthenticatedUserCredentials.ConsumerSecret, }; this._quickBooksOnlineServiceSdk = new QuickBooksOnlineServiceSdk(this._restProfile, this._consumerProfile); }
public void TestSetup() { this._consumerProfile = this._testDataReader.ConsumerProfile; this._restProfile = this._testDataReader.RestProfile; //this._quickBooksOnlineServiceSdk = new QuickBooksOnlineServiceSdk( this._restProfile, this._consumerProfile ); this._quickBooksAuthenticatedUserCredentials = new QuickBooksOnlineAuthenticatedUserCredentials( this._restProfile.RealmId, this._restProfile.OAuthAccessToken, this._restProfile.OAuthAccessTokenSecret, this._restProfile.DataSource); this._quickBooksNonAuthenticatedUserCredentials = new QuickBooksOnlineNonAuthenticatedUserCredentials( this._restProfile.AppToken, this._consumerProfile.ConsumerKey, this._consumerProfile.ConsumerSecret, "http://localhost:27286/home/Callback"); this._quickBooksService = new QuickBooksOnlineService(this._quickBooksAuthenticatedUserCredentials, this._quickBooksNonAuthenticatedUserCredentials); }
public void TestSetup() { this._consumerProfile = this._testDataReader.ConsumerProfile; this._restProfile = this._testDataReader.RestProfile; this._quickBooksOnlineServiceSdk = new QuickBooksOnlineServiceSdk(this._restProfile, this._consumerProfile); }
public void Migrate() { try { _logger.LogInformation("################# Migration of Consumers"); _sugarDataContext.Database.SetCommandTimeout(600); var idsOld = _repository.Query <MfeUserIds>().Select(x => x.Id).ToList(); var consumersFromSugar = _sugarDataContext.Query <CConsumers>().OrderByDescending(x => x.DateModified) .Where(x => idsOld.Contains(x.Id)).AsNoTracking().ToList(); var sugarGolferProfileAll = _sugarDataContext.Query <CConsumersCstm>() .Where(x => idsOld.Contains(x.IdC)).AsNoTracking().ToList(); var countFromSugar = consumersFromSugar.Count(); var loopCount = countFromSugar / _splitCount; _logger.LogInformation("#################Starting Migration of Consumers"); _logger.LogInformation($"Found {countFromSugar} to migrate"); var systemId = getSystemId(); var regionId = _repository.Query <Region>().FirstOrDefault(y => y.Code == "USA").Id.Value; for (var x = 0; x < loopCount; x++) { var skip = _startCount + (x * _splitCount); if (skip > countFromSugar) { break; } _logger.LogInformation($"Starting segment starting at {skip}"); _repository.ReloadContext(); _repository.GetDatabase().ChangeTracker.AutoDetectChangesEnabled = false; var sugarItems = consumersFromSugar.Skip(skip).Take(_splitCount).ToList(); foreach (var sItem in sugarItems) { if (string.IsNullOrWhiteSpace(sItem.Email)) { continue; } var exists = _repository.Query <ConsumerData.Models.Consumer>().Any(y => y.PrimaryEmail.ToLower().Trim() == sItem.Email.ToLower().Trim()); if (exists) { continue; } emailsSaved.Add(sItem.Email); var cdmItem = new ConsumerData.Models.Consumer(); cdmItem.FirstName = sItem.Fname; cdmItem.LastName = sItem.Lname; cdmItem.PrimaryEmail = sItem.Email; cdmItem.Created = sItem.DateEntered ?? DateTime.UtcNow; cdmItem.Modified = sItem.DateModified ?? DateTime.UtcNow; cdmItem.Dob = sItem.Dob; cdmItem.Gender = sItem.Gender; try { var consumerProfile = new ConsumerProfile { RegionId = regionId, PhoneHome = sItem.Phonehm, PhoneCell = sItem.Phonemb, Notes = sItem.Description, Created = sItem.DateEntered ?? DateTime.UtcNow }; if (sItem.AddressPostalcode != null) { consumerProfile.Address = new Address { Created = sItem.DateEntered ?? DateTime.UtcNow, AddressLine1 = sItem.AddressStreet, City = sItem.AddressCity, State = sItem.AddressState, Country = sItem.AddressCountry ?? "USA", ZipCode = sItem.AddressPostalcode, SystemId = systemId }; } if (consumerProfile.SystemToConsumerProfiles == null) { consumerProfile.SystemToConsumerProfiles = new List <SystemToConsumerProfile>(); } if (consumerProfile.SystemToConsumerProfiles.All(y => y.SystemId != systemId)) { consumerProfile.SystemToConsumerProfiles.Add(new SystemToConsumerProfile() { SystemId = systemId, Created = DateTime.UtcNow }); } consumerProfile.ConsumerExperiences = new List <ConsumerExperience>(); cdmItem.ConsumerProfiles = new List <ConsumerProfile>() { consumerProfile }; } catch (Exception e) { _logger.LogError($"broke in comsumer profile create "); if (e.Message != null) { _logger.LogError(e.Message); } _logger.LogError(e.StackTrace); if (e.InnerException != null && e.InnerException.Message != null) { _logger.LogError(e.InnerException.Message); } } try { var sugarGolferProfile = sugarGolferProfileAll.FirstOrDefault(y => y.IdC == sItem.Id); if (sugarGolferProfile != null) { var golferProfile = new GolferProfile(); if (!string.IsNullOrEmpty(sugarGolferProfile.HandicapC)) { int handicap = 0; var wasNumber = int.TryParse(sugarGolferProfile.HandicapC, out handicap); if (wasNumber) { golferProfile.Handicap = handicap; } } if (!string.IsNullOrEmpty(sugarGolferProfile.DriverLoftC)) { golferProfile.DriverLoftId = _staticTableHelper.GetLoftId(sugarGolferProfile.DriverLoftC); } if (!string.IsNullOrEmpty(sugarGolferProfile.DriverShaftFlexC)) { golferProfile.CurrentDriverFlexId = _staticTableHelper.GetFlexId(sugarGolferProfile.DriverShaftFlexC); } golferProfile.CurrentDriverBallFlight = sugarGolferProfile.CurrentDriverBallFlightC; golferProfile.DesiredDriverBallFlight = sugarGolferProfile.DesiredDriverBallFlightC; golferProfile.TypicalDriverDistance = sugarGolferProfile.TypicalDriverDistanceC; if (!string.IsNullOrEmpty(sugarGolferProfile.IronLengthC)) { golferProfile.CurrentIronLengthId = _staticTableHelper.GetChaftLengthId(sugarGolferProfile.IronLengthC); } golferProfile.Current7IronBallFlight = sugarGolferProfile.CurrentIronBallFlightC; if (!string.IsNullOrEmpty(sugarGolferProfile.IronLieC)) { golferProfile.CurrentIronLieId = _staticTableHelper.GetLieId(sugarGolferProfile.IronLieC); } golferProfile.Desired7IronBallFlight = sugarGolferProfile.DesiredIronBallFlightC; golferProfile.Typical7IronDistance = sugarGolferProfile.TypicalIronDistanceC; golferProfile.Created = DateTime.UtcNow; int rpms = 0; int.TryParse(sItem.Rpm, out rpms); golferProfile.RoundsPerMonth = rpms; if (!string.IsNullOrEmpty(sItem.Dexterity)) { golferProfile.ClubHandId = _staticTableHelper.GetClubHandId(sItem.Dexterity); } cdmItem.GolferProfile = golferProfile; } } catch (Exception e) { _logger.LogError($"broke on golfer profile create "); if (e.Message != null) { _logger.LogError(e.Message); } _logger.LogError(e.StackTrace); if (e.InnerException != null && e.InnerException.Message != null) { _logger.LogError(e.InnerException.Message); } } try { _repository.SaveQueue(cdmItem); } catch (Exception e) { _logger.LogError($"failed to save "); if (e.Message != null) { _logger.LogError(e.Message); } _logger.LogError(e.StackTrace); if (e.InnerException != null && e.InnerException.Message != null) { _logger.LogError(e.InnerException.Message); } } } _logger.LogError($"Saving Consumers "); try { _repository.Save(); } catch (Exception e) { _logger.LogError($"failed to save "); if (e.Message != null) { _logger.LogError(e.Message); } _logger.LogError(e.StackTrace); if (e.InnerException != null && e.InnerException.Message != null) { _logger.LogError(e.InnerException.Message); } } _logger.LogError($"Saving Consumer"); } } catch (Exception e) { _logger.LogError("failed", e); if (e.Message != null) { _logger.LogError(e.Message); } _logger.LogError(e.StackTrace); if (e.InnerException != null && e.InnerException.Message != null) { _logger.LogError(e.StackTrace); } } }
private static void CreateOrUpdateConsumerProfile(ConsumerTo consumerModel, ConsumerProfile consumerProfile, Consumer cdmItem) { Debug.Assert(consumerModel.RegionId != null, "consumerModel.RegionId != null"); consumerProfile.RegionId = consumerModel.RegionId.Value; if (consumerModel.PhoneHome != null) { consumerProfile.PhoneHome = consumerModel.PhoneHome; } if (consumerModel.PhoneCell != null) { consumerProfile.PhoneCell = consumerModel.PhoneCell; } if (consumerModel.Description != null) { consumerProfile.Notes = consumerModel.Description; } if (consumerModel.MemberRank != null) { consumerProfile.MemberRank = consumerModel.MemberRank; } if (consumerProfile.SystemToConsumerProfiles == null) { consumerProfile.SystemToConsumerProfiles = new List <SystemToConsumerProfile>(); } if (consumerProfile.SystemToConsumerProfiles.All(x => x.SystemId != consumerModel.SystemId)) { consumerProfile.SystemToConsumerProfiles.Add( new SystemToConsumerProfile { SystemId = consumerModel.SystemId, Created = DateTime.UtcNow }); } if (cdmItem.ConsumerProfiles == null) { cdmItem.ConsumerProfiles = new List <ConsumerProfile> { consumerProfile }; } else if (!consumerProfile.Id.HasValue) //when consumer profile id is NULL then add new profile { cdmItem.ConsumerProfiles.Add(consumerProfile); } if (consumerModel.Postalcode != null) { var address = consumerProfile.Address ?? new Address(); address.ZipCode = consumerModel.Postalcode; address.State = consumerModel.State; address.Country = consumerModel.Country; address.Created = DateTime.UtcNow; address.SystemId = consumerModel.SystemId; address.AddressLine1 = consumerModel.AddressLine1; address.AddressLine2 = consumerModel.AddressLine2; address.AddressLine3 = consumerModel.AddressLine3; address.City = consumerModel.City; if (!address.Id.HasValue) { consumerProfile.Address = address; } } }
private static void CreateNewConsumerProfile(ConsumerTo consumerModel, Consumer consumer) { var consumerProfile = new ConsumerProfile(); CreateOrUpdateConsumerProfile(consumerModel, consumerProfile, consumer); }