private void UpdateSuggestedCandidates(IEmployer employer, bool showSuggestedCandidates, bool sendSuggestedCandidates, bool receiveSuggestedCandidates) { // Update the job poster. var jobPoster = _jobPostersQuery.GetJobPoster(employer.Id) ?? new JobPoster { Id = employer.Id }; if (showSuggestedCandidates != jobPoster.ShowSuggestedCandidates || sendSuggestedCandidates != jobPoster.SendSuggestedCandidates) { jobPoster.ShowSuggestedCandidates = showSuggestedCandidates; jobPoster.SendSuggestedCandidates = sendSuggestedCandidates; _jobPostersCommand.UpdateJobPoster(jobPoster); } // Update the non-member settings. var nonMemberSettings = _nonMemberSettingsQuery.GetNonMemberSettings(employer.EmailAddress.Address); if (nonMemberSettings != null) { if (receiveSuggestedCandidates == nonMemberSettings.SuppressSuggestedCandidatesEmails) { nonMemberSettings.SuppressSuggestedCandidatesEmails = !receiveSuggestedCandidates; _nonMemberSettingsCommand.UpdateNonMemberSettings(nonMemberSettings); } } else if (!receiveSuggestedCandidates) { // !Suppress is the default state, so if there are no settings that's fine. nonMemberSettings = new NonMemberSettings { EmailAddress = employer.EmailAddress.Address, SuppressSuggestedCandidatesEmails = true }; _nonMemberSettingsCommand.CreateNonMemberSettings(nonMemberSettings); } }
public static bool ChangeSuggestedCandidatesSubscription(string emailAddress, bool subscribe, out int registeredCount) { // Is this a registered employer? var employers = _employersQuery.GetEmployers(emailAddress); registeredCount = employers.Count; // Change the NonMemberSettings for that email address (regardless of whether they're registered). var nms = _nonMemberSettingsQuery.GetNonMemberSettings(emailAddress); if (nms != null) { if (subscribe != nms.SuppressSuggestedCandidatesEmails) { return(false); } nms.SuppressSuggestedCandidatesEmails = !subscribe; _nonMemberSettingsCommand.UpdateNonMemberSettings(nms); } else if (subscribe) { // "Subscribed" is the default state, so if there are no settings that's fine. return(false); } else { nms = new NonMemberSettings { EmailAddress = emailAddress, SuppressSuggestedCandidatesEmails = true }; _nonMemberSettingsCommand.CreateNonMemberSettings(nms); } return(true); }