/// <summary> /// Sets the empty recurring service destinations to the RecurringService's client's first location. /// </summary> private static void SetEmptyDestinations() { var coreEntitiesContainer = new CoreEntitiesContainer(); var recurringServicesWithoutLocations = coreEntitiesContainer.RecurringServices .Include("Client") .Include("ServiceTemplate.Fields") .Where(rs => rs.ServiceTemplate.Fields.OfType<LocationField>().All(lf => lf.LocationId == null && lf.LocationFieldTypeInt == (decimal) LocationFieldType.Destination)) .ToArray(); foreach (var recurringService in recurringServicesWithoutLocations) { var locationField = recurringService.ServiceTemplate.Fields.OfType<LocationField>().First(); locationField.Value = recurringService.Client.Locations.FirstOrDefault(); } coreEntitiesContainer.SaveChanges(); }
/// <summary> /// Finds the BaseURL for the current QuickBooks user /// </summary> /// <param name="currentBusinessAccount">The current business account.</param> /// <param name="coreEntitiesContainer">The core entities container.</param> public static void GetBaseUrl(BusinessAccount currentBusinessAccount, CoreEntitiesContainer coreEntitiesContainer) { var quickBooksSession = SerializationTools.Deserialize<QuickBooksSession>(currentBusinessAccount.QuickBooksSessionXml); //URL for the QuickBooks Data Service for getting the BaseURL var serviceEndPoint = String.Format("https://qbo.intuit.com/qbo1/rest/user/v2/" + quickBooksSession.RealmId); var oSession = CreateOAuthSessionAndAccessToken(currentBusinessAccount); //Sends and signs the request to the Data Service IConsumerRequest conReq = oSession.Request().Get().ForUrl(serviceEndPoint).SignWithToken(); //OAuth parameters are needed in the header for this call conReq.Context.GenerateOAuthParametersForHeader(); //Reads the response XML var responseString = conReq.ReadBody(); //Splits the response XML into by line string[] responseArray = responseString.Split('<'); //Checks each line for the one containing the BaseURL foreach (string s in responseArray) { if (s.Contains("qbo:BaseURI>")) { responseArray = s.Split('>'); quickBooksSession.BaseUrl = responseArray[1]; break; } } //Ensures that the BaseURL is saved for later use currentBusinessAccount.QuickBooksSessionXml = SerializationTools.Serialize(quickBooksSession); coreEntitiesContainer.SaveChanges(); }
/// <summary> /// Exchanges the request token attained earlier for the access token needed to make calls to QuickBooks /// </summary> /// <param name="currentBusinessAccount">The current business account.</param> /// <param name="coreEntitiesContainer">The current CoreEntitiesContainer</param> public static void GetAccessToken(BusinessAccount currentBusinessAccount, CoreEntitiesContainer coreEntitiesContainer) { //Deserializes QuicBooksSessionXml from the Database to a quickBooksSession Class var quickBooksSession = SerializationTools.Deserialize<QuickBooksSession>(currentBusinessAccount.QuickBooksSessionXml); //Creates the OAuth Session var clientSession = CreateOAuthSession(); //The AccessToken is attained by exchanging the request token and the OAuthVerifier that we attained earlier IToken accessToken = clientSession.ExchangeRequestTokenForAccessToken(quickBooksSession.Token, quickBooksSession.OAuthVerifier); //Saving the Token to private storage currentBusinessAccount.QuickBooksAccessToken = accessToken.Token; currentBusinessAccount.QuickBooksAccessTokenSecret = accessToken.TokenSecret; coreEntitiesContainer.SaveChanges(); }
/// <summary> /// Clear and create the database. Then populate it with design data. /// </summary> public static void ClearCreateCoreEntitiesDatabaseAndPopulateDesignData() { ClearCreateCoreEntitiesDatabase(); var container = new CoreEntitiesContainer(ServerConstants.ContainerConnectionString); //Setup blocks PopulateBlocks(container); //Setup Business Accounts (and ServiceTemplates) var businessAccountsDesignData = new BusinessAccountsDesignData(); //Setup User Accounts var userAccountsDesignData = new UserAccountsDesignData { //Set Passwords Andrew = { PasswordHash = EncryptionTools.Hash("f00sballchamp", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, Jon = { PasswordHash = EncryptionTools.Hash("seltzer", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, Oren = { PasswordHash = EncryptionTools.Hash("nachoman", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, Zach = { PasswordHash = EncryptionTools.Hash("curlyhair", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, David = { PasswordHash = EncryptionTools.Hash("starofdavid", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, Linda = { PasswordHash = EncryptionTools.Hash("auntie", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, Terri = { PasswordHash = EncryptionTools.Hash("iam1randompassword", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }, AlanMcClure = { PasswordHash = EncryptionTools.Hash("youngster", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" } }; //Setup roles new RolesDesignData(businessAccountsDesignData, userAccountsDesignData); //var changes = container.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(o => o.Entity).OfType<ServiceTemplate>().Where(st => st.CreatedDate < DateTime.UtcNow.AddDays(-1) || st.LastModified < DateTime.UtcNow.AddDays(-1)); //container.SaveChanges(); //Populate ServiceProvider Design Data foreach (var serviceProvider in businessAccountsDesignData.DesignServiceProviders) { var employeesDesignData = new EmployeesDesignData(serviceProvider); foreach (var employee in employeesDesignData.DesignEmployees) serviceProvider.Employees.Add(employee); //container.SaveChanges(); //Add Vehicles (and Vehicle Maintenance, and VehicleTypes) var vehiclesDesignData = new VehiclesDesignData(serviceProvider); foreach (var vehicle in vehiclesDesignData.DesignVehicles) serviceProvider.Vehicles.Add(vehicle); //container.SaveChanges(); //Add Regions var regionsDesignData = new RegionsDesignData(); foreach (var region in regionsDesignData.DesignRegions) serviceProvider.Regions.Add(region); //container.SaveChanges(); //Add Clients (and ContactInfo, Locations, and RecurringServices) var clientsDesignData = new ClientsDesignData(serviceProvider, regionsDesignData); foreach (var client in clientsDesignData.DesignClients) serviceProvider.Clients.Add(client); //container.SaveChanges(); //Add Routes (with RouteTasks, Vehicles, Technicians) var routesDesignData = new RoutesDesignData(serviceProvider, clientsDesignData, vehiclesDesignData, employeesDesignData); foreach (var route in routesDesignData.DesignRoutes) serviceProvider.Routes.Add(route); //container.SaveChanges(); //Add Services var servicesDesignData = new ServicesDesignData(serviceProvider, clientsDesignData.DesignClients.ElementAt(0), serviceProvider.ServiceTemplates); foreach (var service in servicesDesignData.DesignServices) serviceProvider.ServicesToProvide.Add(service); //container.SaveChanges(); } container.SaveChanges(); }