public async Task <IActionResult> GetCurrentBCeIDBusiness() { _logger.LogInformation(LoggingEvents.HttpGet, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name); // get the current user. string temp = _httpContextAccessor.HttpContext.Session.GetString("UserSettings"); UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp); _logger.LogDebug(LoggingEvents.HttpGet, "UserSettings: " + JsonConvert.SerializeObject(userSettings)); // query the BCeID API to get the business record. var business = await _bceid.ProcessBusinessQuery(userSettings.SiteMinderGuid); var cleanNumber = BusinessNumberSanitizer.SanitizeNumber(business?.businessNumber); if (cleanNumber != null) { business.businessNumber = cleanNumber; } if (business == null) { _logger.LogWarning(LoggingEvents.NotFound, "No Business Found."); return(new NotFoundResult()); } _logger.LogDebug(LoggingEvents.HttpGet, "BCeID business record: " + JsonConvert.SerializeObject(business, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); return(Json(business)); }
public async Task <IActionResult> GetCurrentBCeIDBusiness() { // get the current user. string temp = _httpContextAccessor.HttpContext.Session.GetString("UserSettings"); UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp); // query the BCeID API to get the business record. var business = await _bceid.ProcessBusinessQuery(userSettings.SiteMinderGuid); //var business = await _bceid.ProcessBusinessQuery("44437132CF6B4E919FE6FBFC5594FC44"); if (business == null) { return(new NotFoundResult()); } return(Json(business)); }
public void Execute(IDynamicsClient _dynamicsClient, BCeIDBusinessQuery _bceidQuery) { // first find bad accounts string filter = "accountnumber eq '' or accountnumber eq null"; try { var badAccounts = _dynamicsClient.Accounts.Get().Value; Console.Out.WriteLine($"Found {badAccounts.Count} accounts missing the BN9 Account Number."); Console.Out.WriteLine($"Account ID - Account Name - Account Siteminder ID - BN9"); foreach (var badAccount in badAccounts) { if (string.IsNullOrEmpty(badAccount._primarycontactidValue)) { Console.Out.WriteLine($"{badAccount.Accountid} - {badAccount.Name} - {badAccount.AdoxioExternalid} - no primary contact."); } else { // get the primary contact external id. var contact = _dynamicsClient.GetContactById(badAccount._primarycontactidValue).GetAwaiter().GetResult(); if (contact == null || string.IsNullOrEmpty(contact.AdoxioExternalid)) { Console.Out.WriteLine($"{badAccount.Accountid} - {badAccount.Name} - {badAccount.AdoxioExternalid} - no primary contact user identifier."); } else { // get the BN9. string bn9 = ""; try { var result = _bceidQuery.ProcessBusinessQuery(contact.AdoxioExternalid).GetAwaiter().GetResult(); bn9 = result.businessNumber; Console.Out.WriteLine("** Found BN9"); Console.Out.WriteLine($"{badAccount.Accountid} - {badAccount.Name} - {badAccount.AdoxioExternalid} - {bn9} - {result.incorporationNumber}"); } catch (Exception e) { Console.Out.WriteLine("ERROR during get BCEID"); Console.Out.WriteLine(e.Message); } } } } } catch (Exception e) { Console.Out.WriteLine("Error getting bad accounts."); Console.Out.WriteLine(e.Message); } }
// the one parameter is the BCeID guid for an individual. static void Main(string[] args) { bool isBackfill = false; bool isSingleQuery = false; string singleQuery = null; if (args.Length > 0) { string arg = args[0]; if (!string.IsNullOrEmpty(arg)) { if (arg.ToLower().Equals("backfill")) { isBackfill = true; Console.Out.WriteLine("Backfill enabled."); } else { isSingleQuery = true; singleQuery = arg; Console.Out.WriteLine("Single query enabled."); } } } // get the environment settings. string bceidServiceSvcid = Environment.GetEnvironmentVariable("BCEID_SERVICE_SVCID"); string bceidServiceUser = Environment.GetEnvironmentVariable("BCEID_SERVICE_USER"); string bceidServicePasswd = Environment.GetEnvironmentVariable("BCEID_SERVICE_PASSWD"); string bceidServiceUrl = Environment.GetEnvironmentVariable("BCEID_SERVICE_URL"); string dynamicsOdataUri = Environment.GetEnvironmentVariable("DYNAMICS_ODATA_URI"); string ssgUsername = Environment.GetEnvironmentVariable("SSG_USERNAME"); string ssgPassword = Environment.GetEnvironmentVariable("SSG_PASSWORD"); string dynamicsNativeOdataUri = Environment.GetEnvironmentVariable("DYNAMICS_NATIVE_ODATA_URI"); BCeIDBusinessQuery bCeIDBusinessQuery = new BCeIDBusinessQuery(bceidServiceSvcid, bceidServiceUser, bceidServicePasswd, bceidServiceUrl); var serviceClientCredentials = new BasicAuthenticationCredentials() { UserName = ssgUsername, Password = ssgPassword }; var _dynamicsClient = new DynamicsClient(new Uri(dynamicsOdataUri), serviceClientCredentials); if (isBackfill) { var contacts = _dynamicsClient.Contacts.Get().Value; foreach (MicrosoftDynamicsCRMcontact contact in contacts) { if (string.IsNullOrEmpty(contact.Emailaddress1)) { string externalId = contact.AdoxioExternalid; if (!string.IsNullOrEmpty(externalId)) { var caller = bCeIDBusinessQuery.ProcessBusinessQuery(externalId); caller.Wait(); Gov.Lclb.Cllb.Interfaces.BCeIDBusiness bceidBusiness = caller.Result; if (bceidBusiness != null) { MicrosoftDynamicsCRMcontact patchRecord = new MicrosoftDynamicsCRMcontact(); if (string.IsNullOrEmpty(contact.Firstname)) { patchRecord.Firstname = bceidBusiness.individualFirstname; } if (string.IsNullOrEmpty(contact.Lastname)) { patchRecord.Lastname = bceidBusiness.individualSurname; } if (string.IsNullOrEmpty(contact.Middlename)) { patchRecord.Middlename = bceidBusiness.individualMiddlename; } if (string.IsNullOrEmpty(contact.Emailaddress1)) { patchRecord.Emailaddress1 = bceidBusiness.contactEmail; } if (string.IsNullOrEmpty(contact.Telephone1)) { patchRecord.Telephone1 = bceidBusiness.contactPhone; } // update the contact. try { _dynamicsClient.Contacts.Update(contact.Contactid, patchRecord); Console.Out.WriteLine("Updated contact " + contact.Firstname + " " + contact.Lastname); } catch (OdataerrorException odee) { Console.Out.WriteLine("Error patching contact"); Console.Out.WriteLine("Request:"); Console.Out.WriteLine(odee.Request.Content); Console.Out.WriteLine("Response:"); Console.Out.WriteLine(odee.Response.Content); } } } } } IList <MicrosoftDynamicsCRMaccount> accounts = null; // now get a list of all the related accounts. try { accounts = _dynamicsClient.Accounts.Get().Value; } catch (OdataerrorException odee) { Console.Out.WriteLine("Error getting accounts"); Console.Out.WriteLine("Request:"); Console.Out.WriteLine(odee.Request.Content); Console.Out.WriteLine("Response:"); Console.Out.WriteLine(odee.Response.Content); } if (accounts != null) { foreach (var account in accounts) { // get the contact. string contactid = account._primarycontactidValue; // only process accounts with missing email address. if (!string.IsNullOrEmpty(contactid) && string.IsNullOrEmpty(account.Emailaddress1)) { var contact = _dynamicsClient.Contacts.GetByKey(contactid); string guid = contact.AdoxioExternalid; if (!string.IsNullOrEmpty(guid)) { var caller = bCeIDBusinessQuery.ProcessBusinessQuery(guid); caller.Wait(); Gov.Lclb.Cllb.Interfaces.BCeIDBusiness bceidBusiness = caller.Result; if (bceidBusiness != null) { MicrosoftDynamicsCRMaccount accountPatchRecord = new MicrosoftDynamicsCRMaccount(); if (string.IsNullOrEmpty(account.Emailaddress1)) { accountPatchRecord.Emailaddress1 = bceidBusiness.contactEmail; } if (string.IsNullOrEmpty(account.Telephone1)) { accountPatchRecord.Telephone1 = bceidBusiness.contactEmail; } if (string.IsNullOrEmpty(account.Address1City)) { accountPatchRecord.Address1City = bceidBusiness.addressCity; } if (string.IsNullOrEmpty(account.Address1Postalcode)) { accountPatchRecord.Address1Postalcode = bceidBusiness.addressPostal; } if (string.IsNullOrEmpty(account.Address1Line1)) { accountPatchRecord.Address1Line1 = bceidBusiness.addressLine1; } if (string.IsNullOrEmpty(account.Address1Line2)) { accountPatchRecord.Address1Line2 = bceidBusiness.addressLine2; } try { _dynamicsClient.Accounts.Update(account.Accountid, accountPatchRecord); Console.Out.WriteLine("Updated account " + account.Name); } catch (OdataerrorException odee) { Console.Out.WriteLine("Error patching account"); Console.Out.WriteLine("Request:"); Console.Out.WriteLine(odee.Request.Content); Console.Out.WriteLine("Response:"); Console.Out.WriteLine(odee.Response.Content); } } } } } } } else if (isSingleQuery) { Console.Out.WriteLine("\"BCEID GUID\",\"Given name\",\"Surname\",\"Email\",\"Phone\",\"Business Number\""); // query BCeID if (!string.IsNullOrEmpty(singleQuery)) { var caller = bCeIDBusinessQuery.ProcessBusinessQuery(singleQuery); caller.Wait(); var result = caller.Result; if (result != null) { Console.Out.WriteLine("\"" + singleQuery + "\",\"" + result.individualFirstname + "\",\"" + result.individualSurname + "\",\"" + result.contactEmail + "\",\"" + result.contactPhone + "\",\"" + result.businessNumber + "\""); } } } else // get all contacts. { // first parse the contacts file. List <string> stringList = new List <string>(); // read from file. /* * string jsonString = File.ReadAllText("filename"); * * var jsonData = JsonConvert.DeserializeObject<GetOKResponseModelModelModelModelModelModelModelModel>(jsonString); * var contacts = jsonData.Value; */ // Get contacts from dynamics. var contacts = _dynamicsClient.Contacts.Get().Value; foreach (var contact in contacts) { stringList.Add(contact.AdoxioExternalid); } Console.Out.WriteLine("\"BCEID GUID\",\"Given name\",\"Surname\",\"Email\",\"Phone\",\"Business Number\""); foreach (string guid in stringList) { // query BCeID if (!string.IsNullOrEmpty(guid)) { var caller = bCeIDBusinessQuery.ProcessBusinessQuery(guid); caller.Wait(); var result = caller.Result; if (result != null) { Console.Out.WriteLine("\"" + guid + "\",\"" + result.individualFirstname + "\",\"" + result.individualSurname + "\",\"" + result.contactEmail + "\",\"" + result.contactPhone + "\",\"" + result.businessNumber + "\""); } } } } }