Ejemplo n.º 1
0
        public async Task <Unit> Handle(CreateEmployerOwnedVacancyCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Creating vacancy with id {vacancyId}.", message.VacancyId);

            var now = _timeProvider.Now;

            var vacancy = new Vacancy
            {
                Id                = message.VacancyId,
                OwnerType         = message.UserType == UserType.Provider ? OwnerType.Provider : OwnerType.Employer,
                SourceOrigin      = message.Origin,
                SourceType        = SourceType.New,
                Title             = message.Title,
                EmployerAccountId = message.EmployerAccountId,
                Status            = VacancyStatus.Draft,
                CreatedDate       = now,
                CreatedByUser     = message.User,
                LastUpdatedDate   = now,
                LastUpdatedByUser = message.User,
                IsDeleted         = false,
                TrainingProvider  = message.TrainingProvider,
                ProgrammeId       = message.ProgrammeId
            };

            await _repository.CreateAsync(vacancy);

            await _messaging.PublishEvent(new VacancyCreatedEvent
            {
                VacancyId = vacancy.Id
            });

            return(Unit.Value);
        }
        public async Task Handle(CloneVacancyCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Cloning new vacancy with id: {vacancyId} from vacancy with id: {clonedVacancyId}", message.IdOfVacancyToClone, message.NewVacancyId);

            var vacancy = await _repository.GetVacancyAsync(message.IdOfVacancyToClone);

            if (vacancy.Status != VacancyStatus.Submitted && vacancy.Status != VacancyStatus.Live && vacancy.Status != VacancyStatus.Closed)
            {
                _logger.LogError($"Unable to clone vacancy {{vacancyId}} due to it having a status of {vacancy.Status}.", message.IdOfVacancyToClone);

                throw new InvalidStateException($"Vacancy is not in correct state to be cloned. Current State: {vacancy.Status}");
            }

            var clone = CreateClone(message, vacancy);

            await _repository.CreateAsync(clone);

            await _messaging.PublishEvent(new VacancyCreatedEvent
            {
                VacancyId = clone.Id
            });
        }