public async Task <CreateJobOfferPropositionCommandResponse> Handle(CreateJobOfferPropositionCommand request, CancellationToken cancellationToken)
        {
            var entity = await _jobOfferRepository.GetByIdIncludeAllEntities(request.JobOfferId);

            if (entity == null)
            {
                _logger.LogWarning("Entity not found from database. Request ID: {0}", request.JobOfferId);

                throw new NotFoundException(nameof(JobOffer), request.JobOfferId);
            }

            JobOfferProposition jobOfferProposition = new JobOfferProposition()
            {
                Content = request.Content
            };

            entity.Propositions.Add(jobOfferProposition);

            await _jobOfferPropositionRepository.AddAsync(jobOfferProposition);

            _logger.LogInformation("Created JobOfferProposition for JobOffer Id: {0}, Name: {1}", entity.Id, entity.Position);

            var uri = _uriService.Get(jobOfferProposition.Id, nameof(JobOfferProposition));

            return(new CreateJobOfferPropositionCommandResponse(uri));
        }
Example #2
0
        public async Task <Unit> Handle(UpdateJobOfferCommand request, CancellationToken cancellationToken)
        {
            var entity = await _jobOfferRepository.GetByIdIncludeAllEntities(request.Id);

            if (entity == null)
            {
                _logger.LogWarning("Entity not found from database. Request ID: {0}", request.Id);

                throw new NotFoundException(nameof(JobOffer), request.Id);
            }

            var userOwns = await _jobOfferRepository.UserOwnsEntityAsync(request.Id, _currentUserService.UserId);

            if (!userOwns)
            {
                _logger.LogWarning("User is not own for this entity, Id: {0}, UserId: {1}", request.Id, _currentUserService.UserId);

                throw new ForbiddenAccessException(nameof(JobOffer), request.Id);
            }

            _mapper.Map(request, entity);

            await _jobOfferRepository.UpdateAsync(entity);

            _logger.LogInformation("Updated JobOffer Id: {0}", request.Id);

            return(Unit.Value);
        }
        public async Task <JobOfferRequirementViewModel> Handle(GetJobOfferRequirementListQuery request, CancellationToken cancellationToken)
        {
            var entity = await _jobOfferRepository.GetByIdIncludeAllEntities(request.JobOfferId);

            if (entity == null)
            {
                _logger.LogWarning("Entity not found from database. Request ID: {0}", request.JobOfferId);

                throw new NotFoundException(nameof(JobOffer), request.JobOfferId);
            }

            return(_mapper.Map <JobOfferRequirementViewModel>(entity));
        }
        public async Task <CreateJobOfferSkillCommandResponse> Handle(CreateJobOfferSkillCommand request, CancellationToken cancellationToken)
        {
            var entity = await _jobOfferRepository.GetByIdIncludeAllEntities(request.JobOfferId);

            if (entity == null)
            {
                throw new NotFoundException(nameof(JobOffer), request.JobOfferId);
            }

            JobOfferSkill jobOfferSkill = new JobOfferSkill()
            {
                Content = request.Content
            };

            entity.Skills.Add(jobOfferSkill);

            await _jobOfferSkillRepository.AddAsync(jobOfferSkill);

            _logger.LogInformation("Created JobOfferSkill for JobOffer Id: {0}, Name: {1}", entity.Id, entity.Position);

            var uri = _uriService.Get(jobOfferSkill.Id, nameof(JobOfferSkill));

            return(new CreateJobOfferSkillCommandResponse(uri));
        }