public async Task ProcessBusinessResults(PerformContext hangfireContext) { string[] select = { "incidentid" }; string businessFilter = $@"spice_businessreadyforlcrb eq {(int)ReadyForLCRBStatus.ReadyForLCRB} and (spice_cannabisapplicanttype eq {(int)CannabisApplicantType.Business} or spice_cannabisapplicanttype eq {(int)CannabisApplicantType.MarketingBusiness}) and spice_applicanttype eq {(int)SpiceApplicantType.Cannabis} and statecode eq 1 and statuscode eq 5"; MicrosoftDynamicsCRMincidentCollection resp = _dynamicsClient.Incidents.Get(filter: businessFilter, select: select); if (resp.Value.Count == 0) { hangfireContext.WriteLine("No completed business screenings found."); _logger.LogInformation("No completed business screenings found."); return; } CarlaUtils carlaUtils = new CarlaUtils(Configuration, _loggerFactory, null); hangfireContext.WriteLine($"Found {resp.Value.Count} resolved business screenings."); _logger.LogInformation($"Found {resp.Value.Count} resolved business screenings."); foreach (MicrosoftDynamicsCRMincident incident in resp.Value) { CompletedApplicationScreening screening = GenerateCompletedBusinessScreening(incident.Incidentid); hangfireContext.WriteLine($"Sending business screening [{screening.RecordIdentifier}] to Carla."); _logger.LogError($"Sending business screening [{screening.RecordIdentifier}] to Carla."); ToggleResolution(incident.Incidentid, false); bool statusSet = SetLCRBStatus(incident.Incidentid, (int)ReadyForLCRBStatus.SentToLCRB, isBusiness: true); if (statusSet) { try { bool applicationSendSuccessStatus = await carlaUtils.SendApplicationScreeningResult(new List <CompletedApplicationScreening>() { screening }); if (applicationSendSuccessStatus) { statusSet = SetLCRBStatus(incident.Incidentid, (int)ReadyForLCRBStatus.ReceivedByLCRB, isBusiness: true); ToggleResolution(incident.Incidentid, true); hangfireContext.WriteLine($"Successfully sent completed application screening request [LCRB Job Id: {screening.RecordIdentifier}] to Carla."); _logger.LogError($"Successfully sent completed application screening request [LCRB Job Id: {screening.RecordIdentifier}] to Carla."); } else { this.HandleSendToLCRBFail(incident.Incidentid, screening.RecordIdentifier); } } catch (Exception e) { this.HandleSendToLCRBFail(incident.Incidentid, screening.RecordIdentifier); } } else { this.HandleSendToLCRBFail(incident.Incidentid, screening.RecordIdentifier); } } }
public async Task ProcessWorkerResults(PerformContext hangfireContext) { string[] select = { "incidentid" }; string workerFilter = $"spice_workersreadyforlcrb eq {(int)ReadyForLCRBStatus.ReadyForLCRB} and spice_cannabisapplicanttype eq {(int)CannabisApplicantType.Worker} and statecode eq 1 and statuscode eq 5"; IncidentsGetResponseModel resp = _dynamicsClient.Incidents.Get(filter: workerFilter, select: select); if (resp.Value.Count == 0) { hangfireContext.WriteLine("No completed worker screenings found."); _logger.LogInformation("No completed worker screenings found."); return; } CarlaUtils carlaUtils = new CarlaUtils(Configuration, _loggerFactory, null); hangfireContext.WriteLine($"Found {resp.Value.Count} resolved worker screenings."); _logger.LogInformation($"Found {resp.Value.Count} resolved worker screenings."); foreach (MicrosoftDynamicsCRMincident incident in resp.Value) { CompletedWorkerScreening screening = GenerateCompletedWorkerScreening(incident.Incidentid); hangfireContext.WriteLine($"Sending worker screening [{screening.RecordIdentifier}] to Carla."); _logger.LogError($"Sending worker screening [{screening.RecordIdentifier}] to Carla."); ToggleResolution(incident.Incidentid, false); bool statusSet = SetLCRBStatus(incident.Incidentid, (int)ReadyForLCRBStatus.SentToLCRB, isBusiness: false); if (statusSet) { try { await carlaUtils.SendWorkerScreeningResult(new List <CompletedWorkerScreening>() { screening }); statusSet = SetLCRBStatus(incident.Incidentid, (int)ReadyForLCRBStatus.ReceivedByLCRB, isBusiness: false); ToggleResolution(incident.Incidentid, true); hangfireContext.WriteLine($"Successfully sent completed worker screening request [LCRB Job Id: {screening.RecordIdentifier}] to Carla."); _logger.LogError($"Successfully sent completed worker screening request [LCRB Job Id: {screening.RecordIdentifier}] to Carla."); } catch (HttpOperationException httpOperationException) { _logger.LogError(httpOperationException, $"Failed to send completed worker screening request to Carla: {httpOperationException.Message}"); } } } }