public virtual async Task SaveJobOfferAsync(JobOffer jobOfferToSave) { var recruiterExists = await _recruiterRepository.CheckEntityExistsAsync(jobOfferToSave.RecruiterId); if (!recruiterExists) { throw new InvalidOperationException(DomainErrorMessages.INVALID_RECRUITER); } var companyExists = await _companyRepository.CheckEntityExistsAsync(jobOfferToSave.CompanyId); if (!companyExists) { throw new InvalidOperationException(DomainErrorMessages.COMPANY_INVALID); } var jobOfferExists = await _jobOfferRepository.CheckEntityExistsAsync(jobOfferToSave.Id); if (jobOfferExists) { var jobOfferCreatedBySameRecruiter = await _jobOfferRepository.JobOfferBelongsToRecruiter(jobOfferToSave); if (!jobOfferCreatedBySameRecruiter) { throw new InvalidOperationException(DomainErrorMessages.RECRUITER_WHO_SAVE_THE_JOBOFFER_SHOULD_BE_THE_SAME_THAN_CREATED_IT); } } await _jobOfferRepository.UpsertAsync(jobOfferToSave); }
public virtual async Task CreateJobOffer(JobOffer jobOffer, Recruiter recruiter) { jobOffer.Validate(); if (jobOffer.HasIdCreated) { throw new InvalidOperationException(DomainErrorMessages.JOBOFFER_ALREADY_EXISTS); } var jobOffersCreatedByRecruiter = await _jobOfferRepository.GetActiveJobOffers(recruiter); if (jobOffersCreatedByRecruiter.Any(j => j.Company == jobOffer.Company && j.Title == jobOffer.Title)) { throw new InvalidOperationException(DomainErrorMessages.JOBOFFER_ALREADY_EXISTS); } await _jobOfferRepository.UpsertAsync(jobOffer); }
public virtual async Task ApplyToJobOfferAsync(string jobOfferId, string accountId) { var account = await _accountRepository.GetByIdAsync(accountId); if (account != null) { var jobOffer = await _jobOffersRepository.GetByIdAsync(jobOfferId); if (jobOffer != null) { var person = await _personRepository.GetByIdAsync(account.PersonId); if (person != null) { person.ApplyToJobOffer(jobOffer); //This should be transactional await _jobOffersRepository.UpsertAsync(jobOffer); await _personRepository.UpsertAsync(person); } else { throw new InvalidOperationException(ServicesErrorMessages.PERSON_DOES_NOT_EXISTS); } } else { throw new InvalidOperationException(ServicesErrorMessages.INVALID_JOB_OFFER); } } else { throw new InvalidOperationException(ServicesErrorMessages.INVALID_USER_ACCOUNT); } }