Пример #1
0
        public async Task <ValidationResult> Handle(AddAddressCandidateCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                return(message.ValidationResult);
            }

            var candidate = await _candidateRepository.FindById(message.CandidateId);

            if (candidate == null)
            {
                AddError("Informe um candidato valido.");
                return(ValidationResult);
            }

            var address = new Address(message.Id, message.CountryId, message.ZipCode, message.District, message.Street, message.Number, message.Complement, message.State, message.City);
            await _candidateRepository.AddAddress(address);

            candidate.AddAddress(address);
            _candidateRepository.Update(candidate);

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