public async Task <IActionResult> Post([FromBody] ParticipanteCadastroDTO participanteDTO)
        {
            var aux = await ParticipanteRepository.GetParticipanteByCPF(participanteDTO.CPF);

            if (aux != null)
            {
                return(Conflict());
            }

            try
            {
                var participante = ConvertToParticipante(participanteDTO);
                var endereco     = participante.Endereco;

                participante.Id_Endereco = await EnderecoRepository.Add(endereco);

                participante.ParticipanteId = await ParticipanteRepository.Add(participante);

                return(new CreatedAtRouteResult("Get",
                                                new { id = participante.ParticipanteId }, participanteDTO));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
 public Participante BuscaPorNome(string nomeParticipante)
 {
     if (_participanteRepository.BuscaPorNome(nomeParticipante) == null)
     {
         _participanteRepository.Add(new Participante()
         {
             Nome = nomeParticipante
         });
     }
     return(_participanteRepository.BuscaPorNome(nomeParticipante));
 }
Exemplo n.º 3
0
        public void Handle(RegistrarParticipanteCommand message)
        {
            Participante participante = message.Participante;

            if (!ParticipanteValido(participante))
            {
                return;
            }

            // Validação de negocio
            // Nome Igual X
            // Email Igual X
            // Login Igual X

            // Persistencia
            _participanteRepository.Add(participante);

            if (Commit())
            {
                _bus.RaiseEvent(new ParticipanteResgistradoEvent(message.Participante));
            }
        }