public async Task Handle(VacancyReviewApprovedEvent notification, CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation("Sending notification for vacancy {vacancyReference} approval.", notification.VacancyReference);

                var vacancyReview = await _vacancyReviewRepository.GetAsync(notification.ReviewId);

                await _notifier.VacancyReviewApproved(vacancyReview);
            }
            catch (NotificationException ex)
            {
                _logger.LogError(ex, $"Unable to send notification for {nameof(VacancyReviewApprovedEvent)} and VacancyReference: {{vacancyReference}}", notification.VacancyReference);
            }
        }
Esempio n. 2
0
        public async Task Handle(ApproveVacancyReviewCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Approving review {reviewId}.", message.ReviewId);

            var review = await _vacancyReviewRepository.GetAsync(message.ReviewId);

            if (!review.CanApprove)
            {
                _logger.LogWarning($"Unable to approve review {{reviewId}} due to review having a status of {review.Status}.", message.ReviewId);
                return;
            }

            review.ManualOutcome           = ManualQaOutcome.Approved;
            review.Status                  = ReviewStatus.Closed;
            review.ClosedDate              = _timeProvider.Now;
            review.ManualQaComment         = message.ManualQaComment;
            review.ManualQaFieldIndicators = message.ManualQaFieldIndicators;

            foreach (var automatedQaOutcomeIndicator in review.AutomatedQaOutcomeIndicators)
            {
                automatedQaOutcomeIndicator.IsReferred = message.SelectedAutomatedQaRuleOutcomeIds
                                                         .Contains(automatedQaOutcomeIndicator.RuleOutcomeId);
            }

            Validate(review);

            await _vacancyReviewRepository.UpdateAsync(review);

            await _messaging.PublishEvent(new VacancyReviewApprovedEvent
            {
                ReviewId         = message.ReviewId,
                VacancyReference = review.VacancyReference
            });
        }
Esempio n. 3
0
        public async Task <Unit> Handle(ApproveVacancyReviewCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Approving review {reviewId}.", message.ReviewId);

            var review = await _vacancyReviewRepository.GetAsync(message.ReviewId);

            var vacancy = await _vacancyRepository.GetVacancyAsync(review.VacancyReference);

            if (!review.CanApprove)
            {
                _logger.LogWarning($"Unable to approve review {{reviewId}} due to review having a status of {review.Status}.", message.ReviewId);
                return(Unit.Value);
            }

            review.ManualOutcome           = ManualQaOutcome.Approved;
            review.Status                  = ReviewStatus.Closed;
            review.ClosedDate              = _timeProvider.Now;
            review.ManualQaComment         = message.ManualQaComment;
            review.ManualQaFieldIndicators = message.ManualQaFieldIndicators;

            foreach (var automatedQaOutcomeIndicator in review.AutomatedQaOutcomeIndicators)
            {
                automatedQaOutcomeIndicator.IsReferred = message.SelectedAutomatedQaRuleOutcomeIds
                                                         .Contains(automatedQaOutcomeIndicator.RuleOutcomeId);
            }

            Validate(review);

            await _vacancyReviewRepository.UpdateAsync(review);

            var closureReason = await TryGetReasonToCloseVacancy(review, vacancy);

            if (closureReason != null)
            {
                await CloseVacancyAsync(vacancy, closureReason.Value);
                await SendNotificationToEmployerAsync(vacancy.TrainingProvider.Ukprn.GetValueOrDefault(), vacancy.EmployerAccountId);

                await _dashboardService.ReBuildDashboardAsync(vacancy.EmployerAccountId);

                return(Unit.Value);
            }

            await PublishVacancyReviewApprovedEventAsync(message, review);

            return(Unit.Value);
        }
Esempio n. 4
0
        public async Task Handle(UnassignVacancyReviewCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Attempting to unassign review {reviewId}.", message.ReviewId);

            var review = await _repository.GetAsync(message.ReviewId);

            if (!review.CanUnassign)
            {
                _logger.LogWarning($"Unable to unassign {review.ReviewedByUser.Name} from review {message.ReviewId}, it may already be unassigned.");
                return;
            }

            review.Status         = ReviewStatus.PendingReview;
            review.ReviewedDate   = null;
            review.ReviewedByUser = null;

            await _repository.UpdateAsync(review);
        }
Esempio n. 5
0
        public async Task Handle(ApproveReferredVacancyReviewCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Approving referred review {reviewId}", message.ReviewId);

            var review = await _vacancyReviewRepository.GetAsync(message.ReviewId);

            if (!review.CanApprove)
            {
                _logger.LogWarning($"Unable to approve review {{reviewId}} for vacancy {{vacancyReference}} due to review having a status of {review.Status}.", message.ReviewId, review.VacancyReference);
                return;
            }

            var vacancy = await _vacancyRepository.GetVacancyAsync(review.VacancyReference);

            if (!vacancy.CanApprove)
            {
                _logger.LogWarning($"Unable to approve review {{reviewId}} for vacancy {{vacancyReference}} due to vacancy having a status of {vacancy.Status}.", message.ReviewId, vacancy.VacancyReference);
                return;
            }

            review.ManualOutcome = ManualQaOutcome.Approved;
            review.Status        = ReviewStatus.Closed;

            vacancy.ShortDescription    = message.ShortDescription;
            vacancy.Description         = message.VacancyDescription;
            vacancy.TrainingDescription = message.TrainingDescription;
            vacancy.OutcomeDescription  = message.OutcomeDescription;
            vacancy.ThingsToConsider    = message.ThingsToConsider;
            vacancy.EmployerDescription = message.EmployerDescription;

            await _vacancyRepository.UpdateAsync(vacancy);

            await _vacancyReviewRepository.UpdateAsync(review);

            await _messaging.PublishEvent(new VacancyReviewApprovedEvent
            {
                ReviewId         = message.ReviewId,
                VacancyReference = vacancy.VacancyReference.Value
            });
        }
Esempio n. 6
0
 public Task <VacancyReview> GetVacancyReviewAsync(Guid reviewId)
 {
     return(_vacancyReviewRepository.GetAsync(reviewId));
 }