public override void ExecuteTask(string[] args) { const string method = "ExecuteTask"; EventSource.Raise(Event.FlowEnter, method, "Entering task.", Event.Arg("args", args)); var totalEmployers = 0; var totalSent = 0; try { // Get all enabled employers. var employerIds = _employersQuery.GetEmployerIds(); employerIds = _userAccountsQuery.GetEnabledAccountIds(employerIds); totalEmployers = employerIds.Count; EventSource.Raise(Event.Flow, method, "Total enabled employers: " + totalEmployers, Event.Arg("totalEmployers", totalEmployers)); // Send each one an email. foreach (var employerId in employerIds) { totalSent += Send(employerId) ? 1 : 0; } } catch (Exception ex) { EventSource.Raise(Event.NonCriticalError, method, "Failed to send all employer newsletter emails.", ex, new StandardErrorHandler()); } finally { EventSource.Raise(Event.Flow, method, totalSent + " employer newsletter emails have been sent.", Event.Arg("totalEmployers", totalEmployers), Event.Arg("totalSent", totalSent)); } }
public ActionResult Newsletter(CommunicationsContext context) { var employer = _employersQuery.GetEmployer(context.UserId); if (employer == null) { return(HttpNotFound()); } // Other enabled employers in the same organisation. var organisationHierarchy = _organisationsQuery.GetOrganisationHierarchy(employer.Organisation.Id); var employerIds = _recruitersQuery.GetRecruiters(organisationHierarchy); employerIds = _userAccountsQuery.GetEnabledAccountIds(employerIds); var lastLastLastMonth = new MonthRange(DateTime.Now.AddMonths(-3)); var lastLastMonth = new MonthRange(DateTime.Now.AddMonths(-2)); var lastMonth = new MonthRange(DateTime.Now.AddMonths(-1)); var model = CreateModel <NewsletterModel>(context); model.LoginId = _loginCredentialsQuery.GetLoginId(employer.Id); model.Employer = employer; model.SampleSearches = GetCachedSampleSearches(); model.PreviousSearches = GetPreviousSearches(employer, employerIds, lastMonth); model.Ranks = GetRanks(employer.Id, employerIds, lastLastLastMonth, lastLastMonth, lastMonth); return(View(model)); }