Example #1
0
        public void SendReminderEmails()
        {
            var token = _apiUserService.GetToken();

            var reminders      = _responseService.GetServeReminders(token);
            var serveReminders = reminders.Select(Mapper.Map <ServeReminder>);

            var fromId    = AppSetting("DefaultContactEmailId");
            var fromEmail = _contactService.GetContactById(fromId).Email_Address;

            serveReminders.ForEach(reminder =>
            {
                try
                {
                    var contact = _contactService.GetContactById(reminder.SignedupContactId);

                    // is there a template set?
                    var templateId = reminder.TemplateId ?? AppSetting("DefaultServeReminderTemplate");
                    var mergeData  = new Dictionary <string, object>()
                    {
                        { "Opportunity_Title", reminder.OpportunityTitle },
                        { "Nickname", contact.Nickname },
                        { "Event_Start_Date", reminder.EventStartDate.ToShortDateString() },
                        { "Event_End_Date", reminder.EventEndDate.ToShortDateString() },
                        { "Shift_Start", reminder.ShiftStart.FormatAsString() },
                        { "Shift_End", reminder.ShiftEnd.FormatAsString() }
                    };
                    var communication = _communicationService.GetTemplateAsCommunication(templateId,
                                                                                         fromId,
                                                                                         fromEmail,
                                                                                         reminder.OpportunityContactId,
                                                                                         reminder.OpportunityEmailAddress,
                                                                                         reminder.SignedupContactId,
                                                                                         reminder.SignedupEmailAddress,
                                                                                         mergeData);
                    _communicationService.SendMessage(communication);
                }
                catch (Exception ex)
                {
                    logger.Error("Error sending Serve Reminder.", ex);
                }
            });
        }