Exemple #1
0
        public async Task <ValidationResult> Handle(AddLanguageCandidateCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                return(message.ValidationResult);
            }
            var candidate = await _candidateRepository.GetCandidateLanguages(message.CandidateId);

            if (candidate == null)
            {
                AddError("Candidato inválido");
                return(ValidationResult);
            }
            var language = await _candidateRepository.FindLanguageById(message.LanguageId);

            if (language == null)
            {
                AddError("Idioma inválido.");
                return(ValidationResult);
            }

            if (HasLanguage(message.LanguageId, candidate.Id))
            {
                AddError("Idioma já cadastrado.");
                return(ValidationResult);
            }
            var languageCandidate = new LanguageCandidate(message.Id, message.CandidateId, message.LanguageId, message.FluencyLevel);

            candidate.AddLanguageCandidate(languageCandidate);

            await _candidateRepository.AddLanguageCandidate(languageCandidate);

            return(await SaveChanges(_candidateRepository.UnitOfWork));
        }