public async Task Update(ApplicantModel applicantModel) { ValidateApplicantIfNotExist(applicantModel); var editApplicant = await _applicantRepository.GetByIdAsync(applicantModel.ID); if (editApplicant == null) { throw new Exception($"Entity could not be loaded."); } ObjectMapper.Mapper.Map(applicantModel, editApplicant); await _applicantRepository.UpdateAsync(editApplicant); _logger.LogInformation($"Entity successfully updated - ApplicantService"); }
public async Task <Unit> Handle(UpdateApplicantCommand request, CancellationToken cancellationToken) { var applicantToUpdate = await _applicantRepository.GetByIdAsync(request.Id); if (applicantToUpdate == null) { throw new NotFoundException(nameof(Applicant), request.Id); } var validator = new UpdateApplicantCommandValidator(_applicantRepository); var validationResult = await validator.ValidateAsync(request); if (validationResult.Errors.Count > 0) { throw new ValidationException(validationResult); } _mapper.Map(request, applicantToUpdate, typeof(UpdateApplicantCommand), typeof(Applicant)); await _applicantRepository.UpdateAsync(applicantToUpdate); return(Unit.Value); }
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); }