public async Task Delete(ApplicantModel applicantModel)
        {
            ValidateApplicantIfNotExist(applicantModel);
            var deletedApplicant = await _applicantRepository.GetByIdAsync(applicantModel.ID);

            if (deletedApplicant == null)
            {
                throw new Exception($"Entity could not be loaded.");
            }

            await _applicantRepository.DeleteAsync(deletedApplicant);

            _logger.LogInformation($"Entity successfully deleted - ApplicantService");
        }
        public async Task <ApplicantDto> GetApplicant(int id)
        {
            Applicant applicant = await _applicantrepository.GetByIdAsync(id);

            var result = _mapper.Map <ApplicantDto>(applicant);

            return(result);
        }
        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);
        }
Exemple #4
0
        public async Task <Applicant> GetById(Guid id)
        {
            var applicant = await _repository.GetByIdAsync(id);

            return(applicant);
        }