Example #1
0
        public void PollforSendingScondScreeningReminders()
        {
            try
            {
                var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.ScreeningReminderNotification);

                if (value.ToLower() != bool.TrueString.ToLower())
                {
                    return;
                }

                var eventCustomers = _eventCustomerRepository.GetEventCustomersForSecondScreeingReminderNotification(_hoursBeforeAppointment, _interval);
                if (eventCustomers != null && eventCustomers.Any())
                {
                    foreach (var eventCustomer in eventCustomers)
                    {
                        try
                        {
                            var account = _corporateAccountRepository.GetbyEventId(eventCustomer.EventId);
                            if (account != null && !(account.SendAppointmentMail && account.AppointmentReminderMailTemplateId > 0))
                            {
                                continue;
                            }

                            _logger.Info(string.Format("Sending second screening reminder for Customer [Id:{0}] and Event[Id:{1}]  ", eventCustomer.CustomerId, eventCustomer.EventId));

                            var customer = _customerRepository.GetCustomer(eventCustomer.CustomerId);

                            var appointmentConfirmationViewModel = _emailNotificationModelsFactory.GetAppointmentConfirmationModel(eventCustomer.EventId, eventCustomer.CustomerId);

                            string emailTemplateAlias = EmailTemplateAlias.ScreeningReminderMail;

                            if (account != null && account.AppointmentReminderMailTemplateId > 0)
                            {
                                var emailTemplate = _emailTemplateRepository.GetById(account.AppointmentReminderMailTemplateId);
                                emailTemplateAlias = emailTemplate.Alias;
                            }

                            _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.TwoHoursBeforeAppointment, emailTemplateAlias, appointmentConfirmationViewModel, customer.Id, eventCustomer.CustomerId, "Second Automated Reminder Notification");
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Message:{0} \nStackTrace: {1}", ex.Message, ex.StackTrace));
                        }
                    }
                }
                else
                {
                    _logger.Info("No Customers Found for Second screening reminder!");
                }
            }
            catch (Exception exception)
            {
                _logger.Error("Exception occurred while Poll for Sending Second Screening Reminders");
                _logger.Error("Exception:  " + exception.Message);
                _logger.Error("Exception:  " + exception.StackTrace);
            }
        }