CloseReport IJobAdPostsManager.CloseJobAds(Guid integratorUserId, IEmployer jobPoster, IEnumerable <string> externalReferenceIds) { var report = new CloseReport(); // Read the existing job ads for this integrator/job poster combination. var existingJobAdIds = GetExistingJobAdIds(integratorUserId, jobPoster.Id); // Find which of the specified job ad external IDs exist and close those. var externalReferenceIdList = externalReferenceIds.ToList(); var jobAdIds = FilterJobAdIds(externalReferenceIdList, existingJobAdIds, report); if (jobAdIds.Count > 0) { var jobAds = _jobAdsQuery.GetJobAds <JobAd>(jobAdIds); foreach (var jobAd in jobAds) { if (_jobAdsCommand.CanBeClosed(jobAd)) { _jobAdsCommand.CloseJobAd(jobAd); } } } // Fill in the report. report.Closed = jobAdIds.Count; report.Failed = externalReferenceIdList.Count - jobAdIds.Count; return(report); }