private string HandleSBNCreateProgramAccountResponse(string inputXML) { IDynamicsClient dynamicsClient = DynamicsSetupUtil.SetupDynamics(_configuration); Log.Logger.Information("Reached HandleSBNCreateProgramAccountResponse"); if (!_env.IsProduction()) { Log.Logger.Information($"InputXML is: {inputXML}"); } string httpStatusCode = "200"; // deserialize the inputXML var serializer = new XmlSerializer(typeof(SBNCreateProgramAccountResponse1)); SBNCreateProgramAccountResponse1 licenseData; using (TextReader reader = new StringReader(inputXML)) { licenseData = (SBNCreateProgramAccountResponse1)serializer.Deserialize(reader); } string licenceNumber = OneStopUtils.GetLicenceNumberFromPartnerNote(licenseData.header.partnerNote); Log.Logger.Information($"Getting licence with number of {licenceNumber}"); // Get licence from dynamics string businessProgramAccountNumber = "1"; MicrosoftDynamicsCRMadoxioLicences licence; string filter = $"adoxio_licencenumber eq '{licenceNumber}'"; try { licence = dynamicsClient.Licenceses.Get(filter: filter).Value.FirstOrDefault(); businessProgramAccountNumber = licenseData.body.businessProgramAccountNumber.businessProgramAccountReferenceNumber; } catch (Exception e) { Log.Logger.Error($"Unable to get licence data for licence number {licenceNumber} {e.Message}"); licence = null; } if (licence == null) { Log.Logger.Information("licence is null - returning 400."); httpStatusCode = "400"; } else { Log.Logger.Information("Licence record retrieved from Dynamics."); //save the program account number to dynamics int tempBpan = int.Parse(businessProgramAccountNumber); string sanitizedBpan = tempBpan.ToString(); MicrosoftDynamicsCRMadoxioLicences pathLicence = new MicrosoftDynamicsCRMadoxioLicences() { AdoxioBusinessprogramaccountreferencenumber = sanitizedBpan, AdoxioOnestopsent = true }; Log.Logger.Information("Sending update to Dynamics for BusinessProgramAccountNumber."); try { dynamicsClient.Licenceses.Update(licence.AdoxioLicencesid, pathLicence); Log.Logger.Information($"ONESTOP Updated Licence {licenceNumber} record {licence.AdoxioLicencesid} to {businessProgramAccountNumber}"); } catch (HttpOperationException odee) { Log.Logger.Error(odee, "Error updating Licence {licence.AdoxioLicencesid}"); // fail if we can't get results. throw (odee); } //Trigger the Send ProgramAccountDetailsBroadcast Message BackgroundJob.Enqueue(() => new OneStopUtils(_configuration, _cache).SendProgramAccountDetailsBroadcastMessageRest(null, licence.AdoxioLicencesid)); Log.Logger.Information("send program account details broadcast done."); } return(httpStatusCode); }
private string HandleSBNCreateProgramAccountResponse(string inputXML) { _logger.LogInformation("Reached HandleSBNCreateProgramAccountResponse"); _logger.LogInformation($"inputXML is: {inputXML}"); string httpStatusCode = "200"; // deserialize the inputXML var serializer = new XmlSerializer(typeof(SBNCreateProgramAccountResponse1)); SBNCreateProgramAccountResponse1 licenseData; using (TextReader reader = new StringReader(inputXML)) { licenseData = (SBNCreateProgramAccountResponse1)serializer.Deserialize(reader); _logger.LogInformation(inputXML); } string licenceNumber = OneStopUtils.GetLicenceNumberFromPartnerNote(licenseData.header.partnerNote); _logger.LogInformation($"Getting licence with number of {licenceNumber}"); // Get licence from dynamics var filter = $"adoxio_licencenumber eq '{licenceNumber}'"; MicrosoftDynamicsCRMadoxioLicences licence = _dynamicsClient.Licenceses.Get(filter: filter).Value.FirstOrDefault(); if (licence == null) { _logger.LogInformation("licence is null - returning 400."); httpStatusCode = "400"; } else { _logger.LogInformation($"Licence record retrieved from Dynamics."); //save the program account number to dynamics var businessProgramAccountNumber = licenseData.body.businessProgramAccountNumber.businessProgramAccountReferenceNumber; MicrosoftDynamicsCRMadoxioLicences pathLicence = new MicrosoftDynamicsCRMadoxioLicences() { AdoxioBusinessprogramaccountreferencenumber = businessProgramAccountNumber }; _logger.LogInformation($"Sending update to Dynamics for BusinessProgramAccountNumber."); try { _dynamicsClient.Licenceses.Update(licence.AdoxioLicencesid, pathLicence); _logger.LogInformation($"Updated Licence record {licence.AdoxioLicencesid} to {businessProgramAccountNumber}"); } catch (OdataerrorException odee) { _logger.LogError("Error updating Licence"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); // fail if we can't get results. throw (odee); } //Trigger the Send ProgramAccountDetailsBroadcast Message BackgroundJob.Enqueue(() => new OneStopUtils(Configuration, _logger).SendProgramAccountDetailsBroadcastMessageREST(null, licence.AdoxioLicencesid)); _logger.LogInformation("send program account details broadcast done."); } return(httpStatusCode); }