Exemplo n.º 1
0
        public void Add(CadastroPessoaViewModel obj)
        {
            try
            {
                Pessoas p = _mapper.Map <Pessoas>(obj);

                int id = _pessoaRepository.CriarPessoa(p);
                try
                {
                    Usuarios user = new Usuarios
                    {
                        FkTipoUsuario = 3,
                        FkPessoa      = id,
                        Email         = obj.Email,
                        Senha         = obj.Senha
                    };
                    _usuarioRepository.Add(user);
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2601)
                    {
                        _pessoaRepository.Remove(id);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error: " + e);
            };
        }
Exemplo n.º 2
0
        public IActionResult Post(CadastroPessoaViewModel pessoa)
        {
            try
            {
                if (_CadastroPessoaMapper.CpfExists(pessoa.Cpf))
                {
                    return(BadRequest(new { error = "CPF informado já está em uso" }));
                }

                if (_CadastroPessoaMapper.MatriculaExists(pessoa.Matricula))
                {
                    return(BadRequest(new { error = "Matricula já está em uso!" }));
                }

                if (_CadastroPessoaMapper.EmailExists(pessoa.Email))
                {
                    return(BadRequest(new { error = "Email já está em uso!" }));
                }
                _CadastroPessoaMapper.Add(pessoa);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
        }
 public bool Cadastro(CadastroPessoaViewModel Cadastro)
 {
     try
     {
         return(VisitaService.CadastrarPessoa(new Pessoa()
         {
             CPF = Cadastro.Cpf,
             Nome = Cadastro.Nome,
             Sexo = Cadastro.Sexo,
             Telefone = Cadastro.Telefone
         }));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }