public async Task <ApplicationDto> Handle( ApplyLoggedApplicantToOpeningCommand request, CancellationToken cancellationToken ) { var loggedPerson = await _personRepository.GetLoggedPerson(); var applicant = loggedPerson is null ? null : await _applicantRepository.GetApplicantFromPerson(loggedPerson.Id); if (applicant is null) { throw new ValidationException("You must create a resume before applying to an opening."); } var opening = await _openingRepository.FindAsync(request.OpeningId, cancellationToken); if (opening is null) { throw new ValidationException("The selected opening doesn't exist."); } var application = await _openingApplicator.ApplyToOpening(applicant, opening); return(new ApplicationDto { ApplicantId = application.ApplicantId, OpeningId = application.OpeningId }); }
public async Task <ResumeDto> Handle( UpdateResumeForLoggedApplicantCommand request, CancellationToken cancellationToken ) { var loggedPerson = await _personRepository.GetLoggedPerson(); if (loggedPerson is null) { throw new ValidationException("The current logged user is not a person."); } var applicant = await _applicantRepository.GetApplicantFromPerson(loggedPerson.Id); Resume resume = new(request.Resume.Introduction !, new Experiences( request.Resume.Experiences?.Select( e => new Experience( e.Company !, e.Description !, new OpenEndedPeriod(e.PeriodStartDate, e.PeriodEndDate) ) ) ! )); if (applicant is null) { applicant = new Domain.Applicant.Applicant(loggedPerson, resume); await _applicantRepository.CreateAsync(applicant, cancellationToken); } else { applicant.ChangeResume(resume); await _applicantRepository.UpdateAsync(applicant, cancellationToken); } return(request.Resume); }