public async Task <ActionResult <Customer> > GetById(string cpf) { if (_cpfValidator.IsValid(cpf)) { Customer customer = await _customerService.GetAsync(cpf); if (customer == null) { return(NotFound()); } return(Ok(customer)); } else { return(BadRequest(new { errors = new { id = new[] { "CPF inválido" } } })); } }
public async Task <IActionResult> Create([Bind("Prontuario,Nome,SobreNome,DtNasc,Genero,Cpf,Rg,UfRg,Email,Celular,Id_Convenio")] Paciente paciente) { if (ModelState.IsValid) { if (!CpfValidator.IsValid(paciente.Cpf)) { throw new InvalidOperationException("Cpf inválido!!!"); } _context.Add(paciente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(paciente)); }
public async Task <ActionResult <Bill> > Create([FromForm] DateTime dataVencimento, [FromForm] string cpf, [FromForm] double valorCobranca) { CpfValidator cpfValidator = new CpfValidator(); if (!cpfValidator.IsValid(cpf)) { return(BadRequest(new { errors = new { cpf = new[] { "Valor inválido" } } })); } cpf = cpfValidator .Format(cpf, CodeFormat.Trim | CodeFormat.WithoutDigitSeparator | CodeFormat.WithoutNumberSeparator); Bill bill = new Bill() { DueDate = dataVencimento.Date, PersonId = cpf, Value = valorCobranca }; bill = await _billService.CreateAsync(bill); return(Ok(bill)); }
public void ShouldVerifyNullCpfAsInvalid() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid(null)); }
public void ShouldVerifyEmptyCpfAsInvalid() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid(String.Empty)); }
public void ShouldVerifyIfInvalidCpf() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid("907.518.060-8")); }
public void ShouldVerifyIfValidCpf() { CpfValidator cpfValidator = new CpfValidator(); Assert.True(cpfValidator.IsValid("907.518.060-80")); }
protected static bool IsValidCpf(string value) { return(CpfValidator.IsValid(value)); }
public override bool IsValid(object value) { var cpf = (string)value; return(CpfValidator.IsValid(cpf)); }