private void Execute(DateTime start, DateTime end, IList <Employer> employers, EmployerSubRole subRole) { const string method = "Execute"; // Grab the number of new candidates. var joinedUserIds = _accountReportsQuery.GetNewUserIds(UserType.Member, new DateTimeRange(start, end)); var updatedResumeCandidateIds = _resumeReportsQuery.GetUpdatedResumeCandidateIds(new DateTimeRange(start, end)); var newCandidates = joinedUserIds.Union(updatedResumeCandidateIds).Count(); // Only send emails if in fact there are new candidates. if (newCandidates > 0) { employers = (from e in employers where e.SubRole == subRole select e).ToList(); EventSource.Raise(Event.Information, method, string.Format("Sending usage reminder emails to {0} {1}...", employers.Count, subRole == EmployerSubRole.Employer ? "employers" : "recruiters")); foreach (var employer in employers.OrderBy(e => e.EmailAddress.Address)) { try { // Only send an email if this employer has not already received one. _emailsCommand.TrySend(new EmployerUsageEmail(employer, newCandidates), DateTime.MinValue); } catch (Exception ex) { EventSource.Raise(Event.Error, method, string.Format("Failed to send a usage reminder email to '{0}'", employer), ex, new StandardErrorHandler()); } } EventSource.Raise(Event.Information, method, string.Format("Finished sending {0} usage reminder emails to {1}.", employers.Count, subRole == EmployerSubRole.Employer ? "employers" : "recruiters")); } return; }