Пример #1
0
        public CompletedApplicationScreening GenerateCompletedBusinessScreening(string incidentId)
        {
            string[] expand = { "customerid_account" };
            string[] select = { "customerid_account", "incidentid", "spice_applicationstatus" };
            MicrosoftDynamicsCRMincident incident = _dynamicsClient.Incidents.GetByKey(incidentId, expand: expand, select: select);

            SpiceApplicationStatus application = (SpiceApplicationStatus)incident.SpiceApplicationstatus;


            CompletedApplicationScreening screening = new CompletedApplicationScreening()
            {
                RecordIdentifier = incident.CustomeridAccount.SpiceLcrbjobid,
                Result           = SpiceApplicationStatusMapper.MapToCarlaApplicationResult((SpiceApplicationStatus)incident.SpiceApplicationstatus).ToString(),
                Associates       = new List <Associate>()
            };

            string filter = $"_parentcaseid_value eq {incident.Incidentid}";

            string[] associateExpand       = { "customerid_contact" };
            string[] associateSelect       = { "customerid_contact", "incidentid" };
            IncidentsGetResponseModel resp = _dynamicsClient.Incidents.Get(filter: filter, expand: associateExpand, select: associateSelect);

            foreach (var associate in resp.Value)
            {
                screening.Associates.Add(new Associate()
                {
                    SpdJobId   = associate.CustomeridContact.Contactid,
                    LastName   = associate.CustomeridContact.Lastname,
                    FirstName  = associate.CustomeridContact.Firstname,
                    MiddleName = associate.CustomeridContact.Middlename
                });
            }

            return(screening);
        }
Пример #2
0
        public CompletedApplicationScreening ParseApplicationResponse(string businessFileContent, string associatesFileContent)
        {
            CsvHelper.Configuration.Configuration config = new CsvHelper.Configuration.Configuration();
            config.SanitizeForInjection = true;
            config.IgnoreBlankLines     = true;

            config.TrimOptions      = CsvHelper.Configuration.TrimOptions.Trim;
            config.ShouldSkipRecord = record =>
            {
                return(record.All(string.IsNullOrEmpty));
            };

            // fix for unexpected spaces in header
            config.PrepareHeaderForMatch = (string header, int index) => header = header.Trim().ToLower();

            TextReader businessTextReader = new StringReader(businessFileContent);
            var        businessCsv        = new CsvReader(businessTextReader, config);

            businessCsv.Configuration.RegisterClassMap <CsvBusinessImportMap>();

            TextReader associatesTextReader = new StringReader(associatesFileContent);
            var        associatesCsv        = new CsvReader(associatesTextReader, config);

            associatesCsv.Configuration.RegisterClassMap <CsvAssociateImportMap>();

            try
            {
                CsvBusinessImport         businessImport   = businessCsv.GetRecords <CsvBusinessImport>().ToList().First();
                List <CsvAssociateImport> associatesImport = associatesCsv.GetRecords <CsvAssociateImport>().ToList();


                CompletedApplicationScreening response = new CompletedApplicationScreening()
                {
                    RecordIdentifier = businessImport.LcrbBusinessJobId.PadLeft(6, '0'),
                    Result           = CsvBusinessImport.TranslateStatus(businessImport.Result),
                    Associates       = new List <Associate>()
                };
                foreach (var associate in associatesImport)
                {
                    response.Associates.Add(new Associate()
                    {
                        SpdJobId   = associate.LcrbAssociateJobId,
                        LastName   = associate.Last,
                        FirstName  = associate.First,
                        MiddleName = associate.Middle
                    });
                }
                return(response);
            }
            catch (Exception e)
            {
                _logger.LogError("Error parsing worker response.");
                _logger.LogError("Message:");
                _logger.LogError(e.Message);
                // return an empty list so we continue processing other files.
                return(new CompletedApplicationScreening());
            }
        }
Пример #3
0
        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);
                }
            }
        }