예제 #1
0
        public async Task <Unit> Handle(ReviewVacancyCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Reviewing vacancy {vacancyId}.", message.VacancyId);

            var vacancy = await _vacancyRepository.GetVacancyAsync(message.VacancyId);

            if (vacancy == null)
            {
                throw new ArgumentException(string.Format(VacancyNotFoundExceptionMessageFormat, message.VacancyId));
            }

            if (vacancy.VacancyReference.HasValue == false)
            {
                throw new InvalidOperationException(string.Format(MissingReferenceNumberExceptionMessageFormat, vacancy.Id));
            }

            if (vacancy.CanSubmit == false)
            {
                throw new InvalidOperationException(string.Format(InvalidStateExceptionMessageFormat, vacancy.Id, vacancy.Status));
            }

            if (vacancy.OwnerType != message.SubmissionOwner)
            {
                throw new InvalidOperationException(string.Format(InvalidOwnerExceptionMessageFormat, vacancy.Id, message.SubmissionOwner, vacancy.OwnerType));
            }

            var now = _timeProvider.Now;

            if (!string.IsNullOrEmpty(message.EmployerDescription))
            {
                vacancy.EmployerDescription = message.EmployerDescription;
            }

            vacancy.EmployerName = await _employerService.GetEmployerNameAsync(vacancy);

            vacancy.Status = VacancyStatus.Review;
            vacancy.EmployerRejectedReason = null;
            vacancy.ReviewDate             = now;
            vacancy.ReviewCount           += 1;
            vacancy.ReviewByUser           = message.User;
            vacancy.LastUpdatedDate        = now;
            vacancy.LastUpdatedByUser      = message.User;

            await _vacancyRepository.UpdateAsync(vacancy);

            await _messaging.PublishEvent(new VacancyReviewedEvent
            {
                EmployerAccountId = vacancy.EmployerAccountId,
                VacancyId         = vacancy.Id,
                VacancyReference  = vacancy.VacancyReference.Value,
                Ukprn             = vacancy.TrainingProvider.Ukprn.GetValueOrDefault()
            });

            return(Unit.Value);
        }
        public async Task Handle(SubmitVacancyCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Submitting vacancy {vacancyId}.", message.VacancyId);

            var vacancy = await _vacancyRepository.GetVacancyAsync(message.VacancyId);

            if (vacancy == null || vacancy.CanSubmit == false)
            {
                _logger.LogWarning($"Unable to submit vacancy {{vacancyId}} due to vacancy having a status of {vacancy?.Status}.", message.VacancyId);
                return;
            }

            if (vacancy.VacancyReference.HasValue == false)
            {
                throw new Exception("Cannot submit vacancy without a vacancy reference");
            }

            var now = _timeProvider.Now;

            if (!string.IsNullOrEmpty(message.EmployerDescription))
            {
                vacancy.EmployerDescription = message.EmployerDescription;
            }

            vacancy.EmployerName = await _employerService.GetEmployerNameAsync(vacancy);

            vacancy.Status            = VacancyStatus.Submitted;
            vacancy.SubmittedDate     = now;
            vacancy.SubmittedByUser   = message.User;
            vacancy.LastUpdatedDate   = now;
            vacancy.LastUpdatedByUser = message.User;

            await _vacancyRepository.UpdateAsync(vacancy);

            await _messaging.PublishEvent(new VacancySubmittedEvent
            {
                EmployerAccountId = vacancy.EmployerAccountId,
                VacancyId         = vacancy.Id,
                VacancyReference  = vacancy.VacancyReference.Value
            });
        }
 public Task <string> GetEmployerNameAsync(Vacancy vacancy)
 {
     return(_employerService.GetEmployerNameAsync(vacancy));
 }