public ActionResult <ProfessorSalarioDTO> Get(string cpf) { try { if (!ValidaDigitoCPF.ValidaCPF(cpf)) { throw new ValidacaoException("Campo cpf inválido!"); } ConsultaProfessorSalarioQuery command = new ConsultaProfessorSalarioQuery(cpf); var professor = this.mediator.Send(command).Result; return(new CreatedResult("", professor)); } catch (Exception ex) { if (ex.InnerException is ConflitException) { return(Conflict(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else if (ex.InnerException is NaoEncontradoException) { return(NotFound(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else { return(UnprocessableEntity(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } } }
public Cliente(string nome, string cpf) { if (!ValidaDigitoCPF.ValidaCPF(cpf)) { throw new Exception("Cpf Inválido"); // throw new Exception(); } this.nome = nome; this.cpf = cpf; }
public void CriarCliente_Cpf_ok() { string nome = "Rodrigo"; string cpfValido = "980.699.080-33"; var cliente = new Cliente(nome, cpfValido); Assert.True(ValidaDigitoCPF.ValidaCPF(cliente.cpf)); Assert.Equal(nome, cliente.nome); Assert.Equal(cpfValido, cliente.cpf); }
private void btnSave_Click(object sender, EventArgs e) { string senha; if (txtUsuario.Text != string.Empty && txtNome.Text != string.Empty && txtCpf.Text != string.Empty && txtCnh.Text != string.Empty && txtRg.Text != string.Empty && txtSenha.Text != string.Empty && txtConfSenha.Text != string.Empty) { if (!ValidaDigitoCPF.ValidaCPF(txtCpf.Text)) { MessageBox.Show("Cpf digitado é invávlido!", "Sistema ABC"); return; } if (!ValidaCNH.ValidacaoCNH(txtCnh.Text)) { MessageBox.Show("CNH digitado é invávlido!", "Sistema ABC"); return; } if (txtSenha.Text != txtConfSenha.Text) { MessageBox.Show("Senha digitadas estão incorretas!", "Sistema ABC"); return; } else { senha = Descrypt.RetornarMD5(txtConfSenha.Text); } } else { MessageBox.Show("Todos os campos são obrigatorios, preencha de forma correta.", "Sistema ABC"); return; } entityRole = (EntityRole)Enum.Parse(typeof(EntityRole), cmbRole.Text); string[] enderecoArray = cmbEndereco.Text.Split(','); string endereco = enderecoArray[0]; TblUsuarioModel usuarioModel = new TblUsuarioModel(txtUsuario.Text, txtNome.Text, txtCpf.Text, txtRg.Text, txtCnh.Text, senha, txtEmail.Text, entityRole, int.Parse(endereco), true) { State = EntityState.Add }; MessageBox.Show(usuarioModel.saveChange(), "Sistema ABC", MessageBoxButtons.OKCancel); }
public ActionResult <AlunoDTO> Post(AlunoDTO aluno) { try { if (!ValidaDigitoCPF.ValidaCPF(aluno.Cpf)) { throw new ValidacaoException("Campo cpf inválido!"); } if (aluno.Ra <= 0) { throw new ValidacaoException("Campo RA deve ser maior que 0!"); } NovoAlunoCommand command = new NovoAlunoCommand() { Usuario = new Usuario( aluno.Cpf, aluno.Email, aluno.Nome, aluno.Login, aluno.Senha, new Aluno(aluno.Cpf, aluno.Ra) ) }; aluno = this.mediator.Send(command).Result; return(new CreatedResult("", aluno)); } catch (Exception ex) { if (ex.InnerException is ConflitException) { return(Conflict(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else if (ex.InnerException is NaoEncontradoException) { return(NotFound(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else { return(UnprocessableEntity(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } } }
public ActionResult <ProfessorDTO> Post(ProfessorDTO professor) { try { if (!ValidaDigitoCPF.ValidaCPF(professor.Cpf)) { throw new ValidacaoException("Campo cpf inválido!"); } if (professor.Codigo <= 0) { throw new ValidacaoException("Campo CodFuncionario deve ser maior que 0!"); } NovoProfessorCommand command = new NovoProfessorCommand() { Usuario = new Usuario( professor.Cpf, professor.Email, professor.Nome, professor.Login, professor.Senha, new Professor(professor.Cpf, professor.Codigo) ) }; professor = this.mediator.Send(command).Result; return(new CreatedResult("", professor)); } catch (Exception ex) { if (ex.InnerException is ConflitException) { return(Conflict(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else if (ex.InnerException is NaoEncontradoException) { return(NotFound(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else { return(UnprocessableEntity(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } } }
private void btCalcula_Click(object sender, EventArgs e) { // Declara variaveis string mensagem; MessageBoxIcon mIcon; // Verifica se CPF e valido if (ValidaDigitoCPF.ValidaCPF(txtCPF.Text)) { mensagem = "CPF informado é valido"; mIcon = MessageBoxIcon.Information; } else { mensagem = "CPF informado não é valido"; mIcon = MessageBoxIcon.Error; } // Exibe mensagem da validade do CPF MessageBox.Show(mensagem, "Atenção", MessageBoxButtons.OK, mIcon); txtCPF.Focus(); }
public JsonResult Incluir(ClienteModel model) { BoCliente bo = new BoCliente(); if (!this.ModelState.IsValid) { List <string> erros = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, erros))); } else { if (ValidaDigitoCPF.possuiCpfsRepetidos(model.beneficiarios)) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "Há um ou mais CPFs iguais na lista de beneficiarios"))); } try { foreach (Beneficiarios novoBenef in model.beneficiarios) { if (ValidaDigitoCPF.ValidaCPF(ValidaDigitoCPF.Tratador(novoBenef.CPFBeneficiario)).Equals(false)) { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "CPF do beneficiário " + novoBenef.NomeBeneficiario + " é inválido"))); } } } catch (Exception e) { Console.WriteLine("Cliente não possui beneficiarios"); } if (ValidaDigitoCPF.ValidaCPF(ValidaDigitoCPF.Tratador(model.CPF)).Equals(true)) { if (bo.VerificarExistencia(model.CPF).Equals(false)) { model.Id = bo.Incluir(new Cliente() { CPF = model.CPF, CEP = model.CEP, Cidade = model.Cidade, Email = model.Email, Estado = model.Estado, Logradouro = model.Logradouro, Nacionalidade = model.Nacionalidade, Nome = model.Nome, Sobrenome = model.Sobrenome, Telefone = model.Telefone, beneficiarios = model.beneficiarios }); return(Json("Cadastro efetuado com sucesso")); } else { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "CPF já cadastrado"))); } } else { Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, "CPF inválido"))); } } }