예제 #1
0
        private JobAd PostJobAd(IEmployer employer, DateTime time)
        {
            var jobAd = employer.CreateTestJobAd();

            jobAd.CreatedTime = time;
            _jobAdsCommand.CreateJobAd(jobAd);

            // To get the timing right go directly to the repository.

            _jobAdsRepository.ChangeStatus(jobAd.Id, JobAdStatus.Open, null, time);
            jobAd.Status = JobAdStatus.Open;

            return(jobAd);
        }
예제 #2
0
        void IJobAdsCommand.OpenJobAd(JobAd jobAd)
        {
            if (jobAd.Status == JobAdStatus.Open)
            {
                return;
            }
            if (!CanBeOpened(jobAd))
            {
                throw new InvalidOperationException(string.Format("Cannot open the '{0}' job ad, status: {1}, expiry time: {2}.", jobAd.Id, jobAd.Status, jobAd.ExpiryTime));
            }

            var previousStatus = jobAd.Status;

            // If it requires refreshes set it up.

            if (jobAd.Features.IsFlagSet(JobAdFeatures.Refresh))
            {
                _repository.CreateRefresh(jobAd.Id, DateTime.Now);
            }

            // If the expiry time is not explicitly set then set it now, or if it is set for the past.

            var newExpiryTime = jobAd.ExpiryTime == null || jobAd.ExpiryTime.Value < DateTime.Now
                ? RoundExpiryTime(GetDefaultExpiryTime(jobAd.Features))
                : null;

            _repository.ChangeStatus(jobAd.Id, JobAdStatus.Open, newExpiryTime, DateTime.Now);

            jobAd.Status = JobAdStatus.Open;
            if (newExpiryTime != null)
            {
                jobAd.ExpiryTime = newExpiryTime.Value;
            }

            // Fire events.

            var handlers = JobAdOpened;

            if (handlers != null)
            {
                handlers(this, new JobAdOpenedEventArgs(jobAd.Id, previousStatus));
            }
        }