public void ValidaDados() { Nome = Nome.ToUpper().Trim(); Telefone = Telefone.Replace("(", "").Replace(")", "").Replace("-", ""); TelefoneCelular = TelefoneCelular.Replace("(", "").Replace(")", "").Replace("-", ""); Cnpj = Cnpj.Replace("/", "").Replace("-", ""); if (Nome.Length < 3) { throw new Exception("Nome informado inválido!"); } if (Telefone.Length < 10) { throw new Exception("Telefone informado inválido!"); } if (TelefoneCelular.Length < 11) { throw new Exception("Telefone Celular informado inválido!"); } var opcaoCnpj = ValidaCnpj(Cnpj); var opcaoEmail = ValidaEmail(Email); if (opcaoCnpj.Equals(false)) { throw new Exception("O CNPJ informado inválido!"); } if (opcaoEmail.Equals(false)) { throw new Exception("O E-mail informado inválido!"); } }
public EmpresaDto() { if (!String.IsNullOrEmpty(Cnpj)) { Cnpj = Cnpj.Replace(".", string.Empty).Replace("/", string.Empty); } }
public override bool ValidadorDocumento() { int[] multiplicador1 = new int[12] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; int[] multiplicador2 = new int[13] { 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; int soma; int resto; string digito; string tempCnpj; Cnpj = Cnpj.Trim(); Cnpj = Cnpj.Replace(".", "").Replace("-", "").Replace("/", ""); if (Cnpj.Length != 14) { return(false); } tempCnpj = Cnpj.Substring(0, 12); soma = 0; for (int i = 0; i < 12; i++) { soma += int.Parse(tempCnpj[i].ToString()) * multiplicador1[i]; } resto = (soma % 11); if (resto < 2) { resto = 0; } else { resto = 11 - resto; } digito = resto.ToString(); tempCnpj = tempCnpj + digito; soma = 0; for (int i = 0; i < 13; i++) { soma += int.Parse(tempCnpj[i].ToString()) * multiplicador2[i]; } resto = (soma % 11); if (resto < 2) { resto = 0; } else { resto = 11 - resto; } digito = digito + resto.ToString(); return(Cnpj.EndsWith(digito)); }