private string ReplaceCodeStringwithMacroParameterValue(string body, IEnumerable <TemplateMacro> templateMacros, long emailTemplateId) { var emailTemplate = _emailTemplateRepository.GetById(emailTemplateId); var model = Edit(emailTemplate); return(templateMacros.Where(tm => model.Body.ToLower().Contains(tm.IdentifierUiString.ToLower()) && !string.IsNullOrEmpty(tm.ParameterValue)) .Aggregate(body, (current, templateMacro) => current.Replace(templateMacro.CodeString, templateMacro.ParameterValue))); }
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); } }
public ContentResult PreviewTemplate(long emailTemplateId, long notificationTypeId, string emailTemplateAlias, string body) { if (emailTemplateId > 0) { var emailTemplate = _emailTemplateRepository.GetById(emailTemplateId); var isValid = _emailTemplateService.IsEmailTemplateValid(emailTemplateId, body, emailTemplate.NotificationTypeId); if (!isValid) { return(Content("<h2>Parsed unsuccessfully. This Email Template body contains some errors. Please review.</h2>")); } return(LoadTemplate(emailTemplateAlias, notificationTypeId, _emailTemplateService.ReplaceMacroswithCodeString(body, emailTemplateId))); } return(LoadTemplate(emailTemplateAlias, notificationTypeId, _emailTemplateService.ReplaceCodeStringwithMacroParameterValueForNotificationTypeId(body, notificationTypeId))); }
public EmailTemplateEditModel GetModel(long id) { var emailTemplate = _emailTemplateRepository.GetById(id); return(_emailTemplateEditModelFactory.Edit(emailTemplate)); }
public void PollforSendingScreeningReminders() { var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.ScreeningReminderNotification); if (value.ToLower() != bool.TrueString.ToLower()) { return; } const int pageSize = 50; int pageNumber = 1; _logger.Info("\n"); _logger.Info(string.Format("Screening Reminder Queuing. Date: {0:MM/dd/yyyy} ", DateTime.Now)); _logger.Info("\n"); var filter = new EventBasicInfoViewModelFilter { DateFrom = DateTime.Now.Date.AddDays(_daysIntervalBeforeEvent), DateTo = DateTime.Now.Date.AddDays(_daysIntervalBeforeEvent) }; while (true) { int totalRecords; var events = _eventRepository.GetEventsbyFilters(filter, pageNumber, pageSize, out totalRecords); events = events.Where(e => e.Status == EventStatus.Active || (e.Status == EventStatus.Suspended && e.IsLocked)); if (events == null || !events.Any()) { _logger.Info("No Events Found!"); break; } foreach (var theEvent in events) { CorporateAccount account = null; if (theEvent.EventType == EventType.Corporate) { var sendNotification = false; if (theEvent.AccountId.HasValue && theEvent.AccountId.Value > 0) { account = ((IUniqueItemRepository <CorporateAccount>)_corporateAccountRepository).GetById(theEvent.AccountId.Value); sendNotification = account.SendAppointmentMail && account.AppointmentReminderMailTemplateId > 0; } if (!sendNotification) { continue; } } _logger.Info(string.Format("Queuing Event [Id:{0}] [Name:{1}] [Date:{2:MM/dd/yyyy}] ", theEvent.Id, theEvent.Name, theEvent.EventDate)); _logger.Info("\n"); var eventCustomers = _eventCustomerRepository.GetbyEventId(theEvent.Id); var customerIds = eventCustomers.Where(ec => ec.AppointmentId.HasValue && !ec.NoShow && !ec.LeftWithoutScreeningReasonId.HasValue).Select(ec => ec.CustomerId).Distinct().ToArray(); if (!customerIds.Any()) { _logger.Info("No Customers Found!"); continue; } var customers = _customerRepository.GetCustomers(customerIds); foreach (var customer in customers) { _logger.Info(string.Format("Queuing Customer [Id:{0}] [Name:{1}] ", customer.CustomerId, customer.NameAsString)); try { var appointmentConfirmationViewModel = _emailNotificationModelsFactory.GetAppointmentConfirmationModel(theEvent.Id, customer.CustomerId); string emailTemplateAlias = EmailTemplateAlias.ScreeningReminderMail; if (account != null && account.AppointmentReminderMailTemplateId > 0) { var emailTemplate = _emailTemplateRepository.GetById(account.AppointmentReminderMailTemplateId); emailTemplateAlias = emailTemplate.Alias; } _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.ScreeningReminderMail, emailTemplateAlias, appointmentConfirmationViewModel, customer.Id, customer.CustomerId, "Automated Reminder Notification", useAlternateEmail: true); } catch (Exception ex) { _logger.Error(string.Format("Message:{0} \nStackTrace: {1}", ex.Message, ex.StackTrace)); } } } if ((pageNumber * pageSize) >= totalRecords) { break; } pageNumber++; } }
public void SendEmail(string[] to, string[] cc, string[] bcc, int emailTemplateID, Hashtable param, string userID) { try { EmailTemplate emailTemplate = _serviceEmailTemplate.GetById(emailTemplateID); param.Add("%TemplateName", emailTemplate.Description); string subject = emailTemplate.Subject; string emailBody = emailTemplate.Body; //replace the tags with actual values if (param != null) { foreach (DictionaryEntry p in param) { if (emailTemplate.Subject.Contains(p.Key.ToString())) { subject = subject.Replace(p.Key.ToString(), p.Value.ToString()); } if (emailTemplate.Body.Contains(p.Key.ToString())) { emailBody = emailBody.Replace(p.Key.ToString(), p.Value.ToString()); } } } else { subject = emailTemplate.Subject; emailBody = emailTemplate.Body; } //save the email in the queue table to be sent later on if (!string.IsNullOrEmpty(subject) && !string.IsNullOrEmpty(emailBody)) { EmailQueue emailQueue = new EmailQueue(); if (to != null) { if (to.Length > 0) { foreach (string toAddress in to) { emailQueue.Recipient = emailQueue.Recipient + toAddress + ","; } //remove the last comma emailQueue.Recipient = emailQueue.Recipient.Remove(emailQueue.Recipient.LastIndexOf(",")); } } if (cc != null) { if (cc.Length > 0) { foreach (string ccAddress in cc) { emailQueue.CC = ccAddress + ","; } //remove the last comma emailQueue.CC = emailQueue.CC.Remove(emailQueue.CC.LastIndexOf(",")); } } else { emailQueue.CC = ""; } if (bcc != null) { if (bcc.Length > 0) { foreach (string bccAddress in cc) { emailQueue.Bcc = bccAddress + ","; } //remove the last comma emailQueue.Bcc = emailQueue.Bcc.Remove(emailQueue.Bcc.LastIndexOf(",")); } } else { emailQueue.Bcc = ""; } DateTime currentDateTime = DateTime.Now; emailQueue.ToUserID = userID; emailQueue.Subject = subject; emailQueue.Email = emailBody; emailQueue.IsSent = false; emailQueue.CreatedDate = currentDateTime; emailQueue.SentDate = currentDateTime; try { if (!emailQueue.IsSent) { SendEmail(emailQueue.Recipient, emailQueue.CC.ToString(), emailQueue.Bcc, emailQueue.Subject, emailQueue.Email); emailQueue.IsSent = true; emailQueue.SentDate = DateTime.Now; _serviceEmailQueue.Add(emailQueue); _serviceEmailQueue.Save(); } } catch (Exception ex) { ApplicationLog log = new ApplicationLog(); log.CreatedDate = DateTime.UtcNow; log.Source = ex.Source; log.Type = "Error in Sending Email."; log.Description = ex.Message; _serviceAppLog.Add(log); _serviceAppLog.Save(); } } } catch (Exception ex) { ApplicationLog log = new ApplicationLog(); log.CreatedDate = DateTime.UtcNow; log.Source = ex.Source; log.Type = "Error in Sending Email."; log.Description = ex.Message; _serviceAppLog.Add(log); _serviceAppLog.Save(); } }
//[HttpPost] public JsonResult SendConfirmationSms(long eventId, long customerId) { var currentSession = _sessionContext.UserSession; var eventCustomer = _eventCustomerRepository.Get(eventId, customerId); var customer = _customerRepository.GetCustomer(customerId); var message = string.Empty; if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false) { _logger.Info("customer has not Subscribed for SMS customerId " + customer.CustomerId); message = "customer has not Subscribed for SMS"; _logger.Info(message); return(Json(new { message }, JsonRequestBehavior.AllowGet)); } if (eventCustomer.EnableTexting) { var account = _corporateAccountRepository.GetbyEventId(eventId); if (account != null && !account.EnableSms) { message = "SMS has been disabled for Corporate Account Tag: " + account.Tag; _logger.Info(message); return(Json(new { message }, JsonRequestBehavior.AllowGet)); } var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation); var messageCount = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0; if (account != null && messageCount >= account.MaximumSms) { _logger.Info("Maximum SMS has Been Sent "); _logger.Info(string.Format("Allowed SMS {0}, SMS Already Sent {0} " + account.MaximumSms, messageCount)); message = "Maximum SMS limit has been reached."; return(Json(new { message }, JsonRequestBehavior.AllowGet)); } if (account == null && messageCount > 0) { message = "Appointment confirmation SMS has already been sent."; _logger.Info(message); return(Json(new { message }, JsonRequestBehavior.AllowGet)); } var eventData = _eventRepository.GetById(eventId); var smsNotificaionModel = _phoneNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData); var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation; if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0) { var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value); smsTemplateAlias = smsTemplate.Alias; } var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsNotificaionModel, customer.Id, currentSession.CurrentOrganizationRole.OrganizationRoleUserId, Request.Url.AbsolutePath); if (notification != null) { var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; _eventCustomerNotificationRepository.Save(eventCustomerNotification); } else { message = "Queuing is disabled for Appointment Confirmation SMS."; _logger.Info(message); return(Json(new { message }, JsonRequestBehavior.AllowGet)); } } else { message = "Customer has not opted for SMS"; _logger.Info(message); return(Json(new { message }, JsonRequestBehavior.AllowGet)); } message = "Message Sent Successfully"; return(Json(new { message }, JsonRequestBehavior.AllowGet)); }
public void SendAppointmentConfirmationMail(Customer customer, Event eventData, long createdByOrgRoleUserId, string source, CorporateAccount account) { var sendNotification = false; if (eventData.EventType == EventType.Retail) { sendNotification = true; } else if (eventData.AccountId.HasValue && eventData.AccountId.Value > 0 && account != null) { // account = ((IUniqueItemRepository<CorporateAccount>)_corporateAccountRepository).GetById(eventData.AccountId.Value); sendNotification = account.SendAppointmentMail && account.AppointmentConfirmationMailTemplateId > 0; } if (sendNotification) { var appointmentConfirmationViewModel = _emailNotificationModelsFactory.GetAppointmentConfirmationModel(eventData.Id, customer.CustomerId); string emailTemplateAlias = EmailTemplateAlias.AppointmentConfirmationWithEventDetails; if (account != null && account.AppointmentConfirmationMailTemplateId > 0) { var emailTemplate = _emailTemplateRepository.GetById(account.AppointmentConfirmationMailTemplateId); emailTemplateAlias = emailTemplate.Alias; } _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.AppointmentConfirmationWithEventDetails, emailTemplateAlias, appointmentConfirmationViewModel, customer.Id, createdByOrgRoleUserId, source, useAlternateEmail: true); } var eventCustomer = _eventCustomerRepository.Get(eventData.Id, customer.CustomerId); if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false) { _logger.Info("Customer has not subscribed for SMS " + customer.CustomerId); return; } if (account != null && !account.EnableSms) { _logger.Info("SMS feature has been disabled by corporate account: " + account.Tag + " EventId: " + eventData.Id); return; } var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation); var messageCount = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0; if (account != null && messageCount >= account.MaximumSms) { _logger.Info(string.Format("Maximum Number of reminder message sms has been sent for this event. eventId {0} Customer Id: {1}", eventCustomer.EventId, eventCustomer.Id)); return; } var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation; if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0) { var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value); smsTemplateAlias = smsTemplate.Alias; } if (eventCustomer.EnableTexting) { var smsAppointmentConfirmation = _smsNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData); var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsAppointmentConfirmation, customer.Id, createdByOrgRoleUserId, source); if (notification != null) { var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; _eventCustomerNotificationRepository.Save(eventCustomerNotification); } } }