コード例 #1
0
        private void GenerateJsonforEventCustomers(Event eventData, ILogger logger)
        {
            int totalrecords;

            logger.Info("Getting event customers......");

            var eventCusomters = _eventCustomerRepository.GetMyBioCheckEventCustomers(1, 400, new MyBioCheckCustomerModelFilter {
                EventId = eventData.Id
            }, out totalrecords);

            if (eventCusomters == null || !eventCusomters.Any())
            {
                logger.Info(string.Format("No event customers found for Event Id {0} EventDate {1}", eventData.Id, eventData.EventDate));
                return;
            }

            logger.Info(string.Format("{0} event customers found.", eventCusomters.Count()));

            var customers = _customerRepository.GetCustomers(eventCusomters.Select(x => x.CustomerId).ToArray());
            var healthAssessmentAnswer = _healthAssessmentRepository.GetCustomerHealthInfoByEventCustomerIds(eventCusomters.Select(ec => ec.Id).ToArray());

            foreach (var ec in eventCusomters)
            {
                try
                {
                    var customer  = customers.Single(c => c.CustomerId == ec.CustomerId);
                    var hafAnswer = healthAssessmentAnswer.Where(c => c.EventCustomerId == ec.Id);

                    logger.Info("Started For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);

                    var bioCheckJsonViewModel = GenerateBioCheckResponseModel(ec, customer, hafAnswer, eventData, logger);

                    if (bioCheckJsonViewModel != null)
                    {
                        bioCheckJsonViewModel.ProfileId = _profileId;
                        logger.Info("Saving Request JSON For eventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        SaveRequestJson(bioCheckJsonViewModel, ec.EventId, ec.CustomerId);

                        logger.Info("Submitting Post Request For eventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        var response = _trailApiService.Post <BioCheckJsonViewModel>(bioCheckJsonViewModel);

                        if (response != null)
                        {
                            logger.Info("Saving response For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                            SaveReports(response, ec.EventId, ec.CustomerId, logger);
                        }
                        else
                        {
                            logger.Info("No Response found for EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        }
                    }
                    logger.Info("Complete For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                }
                catch (Exception exception)
                {
                    logger.Error(string.Format("Error while generating My Bio-Check Assessment Data for customer Id: {0} and EventId {1} Message: {2}, StackTrace {3}", ec.CustomerId, ec.EventId, exception.Message, exception.StackTrace));
                }
            }
        }
コード例 #2
0
        public void GenerateJsonforEventCustomers(Event eventData, ILogger logger)
        {
            int totalrecords;

            logger.Info("Getting event customers......");

            var eventCusomters = _eventCustomerRepository.GetMyBioCheckEventCustomers(1, 400, new MyBioCheckCustomerModelFilter {
                EventId = eventData.Id
            }, out totalrecords);

            if (eventCusomters == null || !eventCusomters.Any())
            {
                logger.Info(string.Format("No event customers found for Event Id {0} EventDate {1}", eventData.Id, eventData.EventDate));
                return;
            }

            logger.Info(string.Format("{0} event customers found.", eventCusomters.Count()));

            var eventCustomerIds = eventCusomters.Select(x => x.Id).ToArray();
            var customerIds      = eventCusomters.Select(x => x.CustomerId).ToArray();

            var          customers = _customerRepository.GetCustomers(customerIds);
            var          healthAssessmentAnswer = _healthAssessmentRepository.GetCustomerHealthInfoByEventCustomerIds(eventCustomerIds);
            var          account      = _corporateAccountRepository.GetbyEventId(eventData.Id);
            Organization organization = null;

            if (account != null)
            {
                organization = _organizationRepository.GetOrganizationbyId(account.Id);
                account.Name = organization.Name;
            }


            DirectoryOperationsHelper.CreateDirectoryIfNotExist(_bioCheckAssessmentFailedListPath);

            var fileName = Path.Combine(_bioCheckAssessmentFailedListPath, string.Format("failedCustomerRecord_{0}.xml", DateTime.Now.Ticks));

            var failedCustomerList = new BioCheckAssessmentFailedList {
                EventCustomers = new List <BioCheckAssessmentFailed>()
            };

            var eventCustomerResultTrales = _eventCustomerResultTraleRepository.GetByEventCustomerResultIds(eventCustomerIds);
            var customerTrales            = _customerTraleRepository.GetByCustomerIds(customerIds);

            eventCustomerResultTrales = eventCustomerResultTrales.IsNullOrEmpty() ? new List <EventCustomerResultTrale>() : eventCustomerResultTrales.ToList();
            customerTrales            = customerTrales.IsNullOrEmpty() ? new List <CustomerTrale>() : customerTrales;

            foreach (var ec in eventCusomters)
            {
                try
                {
                    var customer  = customers.Single(c => c.CustomerId == ec.CustomerId);
                    var hafAnswer = healthAssessmentAnswer.Where(c => c.EventCustomerId == ec.Id);

                    logger.Info("Started For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);

                    var bioCheckJsonViewModel = GenerateBioCheckResponseModel(ec, customer, hafAnswer, eventData, logger, eventCustomerResultTrales, customerTrales, account);

                    if (bioCheckJsonViewModel != null)
                    {
                        bioCheckJsonViewModel.ProfileId = _profileId;
                        logger.Info("Saving Request JSON For eventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        SaveRequestJson(bioCheckJsonViewModel, ec.EventId, ec.CustomerId);

                        logger.Info("Submitting Post Request For eventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        var response        = _trailApiService.Post <BioCheckJsonViewModel>(bioCheckJsonViewModel);
                        var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate;

                        if (response != null)
                        {
                            logger.Info("Saving response For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                            SaveReports(response, ec.EventId, ec.CustomerId, logger, isNewResultFlow);
                        }
                        else
                        {
                            logger.Info("No Response found for EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                        }
                    }
                    logger.Info("Complete For EventId: " + ec.EventId + " customerId: " + ec.CustomerId);
                }
                catch (Exception exception)
                {
                    failedCustomerList.EventCustomers.Add(new BioCheckAssessmentFailed {
                        CustomerId = ec.CustomerId, EventId = ec.EventId
                    });
                    logger.Error(string.Format("Error while generating My Bio-Check Assessment Data for customer Id: {0} and EventId {1} Message: {2}, StackTrace {3}", ec.CustomerId, ec.EventId, exception.Message, exception.StackTrace));
                }
            }

            if (!failedCustomerList.EventCustomers.IsNullOrEmpty())
            {
                _bioCheckAssessmentFailedListXmlSerializer.SerializeandSave(fileName, failedCustomerList);
            }
        }