Esempio n. 1
0
        public string DocumentoComFormatacao()
        {
            if (string.IsNullOrEmpty(Cpf))
            {
                return("");
            }

            var doc = Cpf.Replace("-", "").Replace(".", "").Replace("/", "");

            if (doc.Length <= 11)
            {
                var onzeDigitosCpf = doc.PadLeft(11, '0');
                var digitos        = Convert.ToInt64(Regex.Replace(onzeDigitosCpf, "[^0-9]", ""));
                return(digitos.ToString(@"000\.000\.000\-00"));
            }
            else
            {
                var onzeDigitosCpf = doc.PadLeft(14, '0');
                var digitos        = Convert.ToInt64(Regex.Replace(onzeDigitosCpf, "[^0-9]", ""));
                return(digitos.ToString(@"00\.000\.000/0000-00"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns true if Cliente instances are equal
        /// </summary>
        /// <param name="other">Instance of Cliente to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Cliente other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Titular == other.Titular ||
                     Titular != null &&
                     Titular.Equals(other.Titular)
                 ) &&
                 (
                     Cpf == other.Cpf ||
                     Cpf != null &&
                     Cpf.Equals(other.Cpf)
                 ) &&
                 (
                     Senha == other.Senha ||
                     Senha != null &&
                     Senha.Equals(other.Senha)
                 ) &&
                 (
                     Conta == other.Conta ||
                     Conta != null &&
                     Conta.SequenceEqual(other.Conta)
                 ));
        }
Esempio n. 3
0
        public static string LerCpf(List <Cliente> lista)
        {
            string cpf;

            do
            {
                Console.Write("Informe o CPF( Apenas números e com o dígito): ");
                cpf = Console.ReadLine();

                if (!Cpf.Check(cpf))
                {
                    Console.WriteLine("CPF inválido");
                }

                if (lista.Where(cliente => cliente.Cpf == cpf).FirstOrDefault() != null)
                {
                    Console.WriteLine("CPF já cadastrado");
                }
            } while (!(Cpf.Check(cpf)) || (lista.Where(cliente => cliente.Cpf == cpf).FirstOrDefault() != null));
            /// VERIFICA SE CPF É VALIDO      VERIFICA SE CPF JÁ EXISTE NA LISTA

            return(cpf);
        }
        public ClienteViewModelValidations()
        {
            RuleFor(x => x.PrimeiroNome).MinimumLength(2).WithMessage("Nome deve ter ao menos 2 caracteres.");
            RuleFor(x => x.Sobrenome).MinimumLength(2).WithMessage("Sobrenome deve ter ao menos 2 caracteres.");
            RuleFor(x => x.TelefoneDDD).MinimumLength(2).WithMessage("DDD deve ter ao menos 2 números.");
            RuleFor(x => x.TelefoneNumero).MinimumLength(8).WithMessage("Telefone deve ter ao menos 8 números.");
            RuleFor(x => x.Endereco).MinimumLength(2).WithMessage("Endereço deve ter ao menos 2 caracteres.");
            RuleFor(x => x.Cidade).MinimumLength(2).WithMessage("Cidade deve ter ao menos 2 caracteres.");
            RuleFor(x => x.Bairro).MinimumLength(2).WithMessage("Cidade deve ter ao menos 2 caracteres.");
            RuleFor(x => x.Cep).MinimumLength(8).WithMessage("Cep deve ter ao menos 8 caracteres.")
            .MaximumLength(9).WithMessage("Cep deve ter no máximo 9 caracteres.");
            RuleFor(x => x.Email).EmailAddress().WithMessage("Endereço de email inválido.");

            RuleFor(x => x.Cpf).Custom((cpf, context) =>
            {
                Cpf validacpf = Cpf.Vazio;

                if (!validacpf.Valida(cpf))
                {
                    context.AddFailure("Número de CPF inválido.");
                }
            });
        }
        public async Task GetPayment_Hamdler_Test()
        {
            //Arrange
            var tid         = new Guid("ef01bedb-2d4c-418e-ac52-1e8a10b9b2a8");
            Cpf cpf         = "434.443.474-99";
            var paymentDate = new DateTime(2020, 12, 01);
            var service     = GetInstance();

            var request = new GetPaymentModel.Request
            {
                Cpf     = cpf.Value,
                DueDate = paymentDate.ToString("yyyy-MM-ddTHH:mm:ss")
            };

            var response = new GetPaymentModel.Response
            {
                Payments = new List <GetPaymentModel.ResponsePayments>
                {
                    new GetPaymentModel.ResponsePayments {
                        Tid = tid, Cpf = cpf.Value, Value = 10
                    },
                    new GetPaymentModel.ResponsePayments {
                        Tid = tid, Cpf = cpf.Value, Value = 30
                    }
                }
            };

            _mapper.Map <GetPaymentModel.Response>(Arg.Any <List <Payment> >()).Returns(response);

            //Act
            var result = await service.Handle(request, new System.Threading.CancellationToken());

            //Assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Payments.Count());
            Assert.Equal(40M, result.Payments.Sum(s => s.Value));
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the SkinTone References in the 3IDR Files
        /// </summary>
        /// <param name="reffile">the 3IDR File</param><param name="skin">the new skintone</param>
        /// <param name="skinfiles">a Hashtable listing al Proerty Sets for each available skintone (key=skintone string, value= ArrayList of Cpf Objects)</param>
        void UpdateSkintone(SimPe.Plugin.RefFile reffile, string skin, Hashtable skinfiles)
        {
            if (reffile == null)
            {
                return;
            }
            if (reffile.Items == null)
            {
                return;
            }
            if (reffile.Package == null)
            {
                return;
            }

            for (int i = 0; i < reffile.Items.Length; i++)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor pfd = (SimPe.Interfaces.Files.IPackedFileDescriptor)reffile.Items[i];
                if (pfd == null)
                {
                    continue;
                }
                if (pfd.Type == Data.MetaData.GZPS)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] fii = FileTable.FileIndex.FindFile(pfd, reffile.Package);
                    if (fii.Length > 0)
                    {
                        Cpf skinfile = new Cpf();
                        skinfile.ProcessData(fii[0]);

                        reffile.Items[i] = UpdateSkintone(skinfile, skin, skinfiles);
                    }
                }
            }

            reffile.SynchronizeUserData();
        }
        public async Task CreateCustomer_Handler_Test()
        {
            //Arrange
            var uniqueId = new Guid("ef01bedb-2d4c-418e-ac52-1e8a10b9b2a8");
            Cpf cpf      = "434.443.474-99";
            var name     = "Pedro de Oliveira";
            var state    = "PR";

            var customer = new Customer
            {
                UniqueId = uniqueId,
                Cpf      = cpf.Value,
                Name     = name,
                State    = state
            };

            _mapper.Map <Customer>(Arg.Any <CreateCustomerModel.Request>()).Returns(customer);

            var service = GetInstance();

            var request = new CreateCustomerModel.Request
            {
                Cpf   = cpf.Value,
                Name  = name,
                State = state
            };

            //Act
            var result = await service.Handle(request, new System.Threading.CancellationToken());

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.Equal("Success", result.Message);
            Assert.Equal(uniqueId, result.ClientUniqueId);
        }
Esempio n. 8
0
        public async Task <Result> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            Result result = new Result();

            var name  = new Name(request.FirstName, request.LastName);
            var cpf   = new Cpf(request.Cpf);
            var email = new Email(request.Email);

            result.AddNotifications(name.Notifications);
            result.AddNotifications(cpf.Notifications);
            result.AddNotifications(email.Notifications);

            if (result.Notifications.Any())
            {
                return(result);
            }

            if (_customerRepository.ExistDocument(cpf.Number))
            {
                result.AddNotification(new FluentValidator.Notification("Cpf", "Cpf já cadastrado!"));
                return(result);
            }

            if (_customerRepository.ExistEmail(email.Address))
            {
                result.AddNotification(new FluentValidator.Notification("Email", "E-mail já cadastrado!"));
                return(result);
            }

            var customer = new Customer(name, cpf, email, request.Phone);
            await _customerRepository.Save(customer);

            result = new ResultCommand <string>("Cliente cadastrado com sucesso!");

            return(result);
        }
Esempio n. 9
0
        public async Task <GetCustomerPaymentsModel.Response> Handle(GetCustomerPaymentsModel.Request request, CancellationToken cancellationToken)
        {
            var cpf           = string.Empty;
            var paymentPeriod = string.Empty;
            var totalValue    = 0M;

            var payments = await GetPayments(request);

            if (payments.HaveAny())
            {
                var paymentRef = payments.FirstOrDefault();

                cpf           = new Cpf(paymentRef.Cpf).FormatedValue;
                paymentPeriod = $"{paymentRef.YearReference}-{paymentRef.MonthReference}";
                totalValue    = payments.Sum(s => s.Value);
            }

            return(new GetCustomerPaymentsModel.Response
            {
                Cpf = cpf,
                PaymentPeriod = paymentPeriod,
                TotalValue = totalValue
            });
        }
Esempio n. 10
0
        public void CriarMembro()
        {
            var nome  = "Artur Araújo Santos Ribeiro";
            var email = new Email("*****@*****.**");
            var telefoneResidencial = new Telefone("552127620534");
            var telefoneMovel       = new Telefone("55212987413978");
            var telefoneComercial   = new Telefone("552127620534");
            var cpf      = new Cpf("09436015763");
            var rg       = new Rg("");
            var endereco = new Endereco();
            var foto     = "";

            var membro = Membro.Factor.Create(nome
                                              , foto
                                              , email
                                              , DateTime.Now
                                              , DateTime.Now
                                              , telefoneResidencial
                                              , telefoneMovel
                                              , telefoneComercial
                                              , Sexo.Masculino
                                              , EstadoCivil.Casado
                                              , cpf
                                              , rg
                                              , endereco);

            Assert.Equal(membro.Nome, nome);
            Assert.Equal(membro.Email.Value, email.Value);
            Assert.Equal(membro.Residencial.Value, telefoneResidencial.Value);
            Assert.Equal(membro.Celular.Value, telefoneMovel.Value);
            Assert.Equal(membro.Comercial.Value, telefoneComercial.Value);
            Assert.Equal(membro.Sexo, Sexo.Masculino);
            Assert.Equal(membro.EstadoCivil, EstadoCivil.Casado);
            Assert.Equal(membro.Cpf.Value, cpf.Value);
            Assert.Equal(membro.Rg.Value, rg.Value);
        }
Esempio n. 11
0
 public void AddValues(ref MySqlCommand c, string _q)
 // método para substituir os parâmetros da query de forma segura, impedindo ataques por SQL Injection
 {
     try
     {
         if ((Matricula != 0) && (_q.Contains("@matricula")))
         {
             c.Parameters.AddWithValue("@matricula", Matricula);
         }
         if ((!Cpf.Equals("")) && (_q.Contains("@cpf")))
         {
             c.Parameters.AddWithValue("@cpf", Cpf);
         }
         if ((!Nome.Equals("")) && (_q.Contains("@nome")))
         {
             c.Parameters.AddWithValue("@nome", Nome);
         }
         if ((!DataNascimento.Equals("  /  /")) && (_q.Contains("@data_nascimento")))
         {
             //ajuste da data de nascimento para o padrão do MySQL
             dia            = DataNascimento.Substring(0, 2);
             mes            = DataNascimento.Substring(3, 2);
             ano            = DataNascimento.Substring(6, 4);
             DataNascimento = ano + "-" + mes + "-" + dia;
             c.Parameters.AddWithValue("@data_nascimento", DataNascimento);
         }
         if ((!Endereco.Equals("")) && (_q.Contains("@endereco")))
         {
             c.Parameters.AddWithValue("@endereco", Endereco);
         }
     }
     catch (Exception e)
     {
         throw (e);
     }
 }
Esempio n. 12
0
        public void ValidateReturnsFalseIfCpfIsInvalidAndStrict()
        {
            var actual = Cpf.Validate(CpfTest.strictInvalidCpf, CpfPunctuation.Strict);

            Assert.False(actual);
        }
Esempio n. 13
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            string Cpf1 = Cpf.Replace(".", "").Replace("-", "");

            if (Cpf1.Length > 11)
            {
                yield return(new ValidationResult("Cpf inválido"));
            }

            while (Cpf1.Length != 11)
            {
                Cpf1 = '0' + Cpf;
            }

            bool igual = true;

            for (int i = 1; i < 11 && igual; i++)
            {
                if (Cpf1[i] != Cpf1[0])
                {
                    igual = false;
                }
            }

            if (igual || Cpf1 == "12345678909")
            {
                yield return(new ValidationResult("Cpf inválido"));
            }

            int[] numeros = new int[11];

            for (int i = 0; i < 11; i++)
            {
                numeros[i] = int.Parse(Cpf1[i].ToString());
            }

            int soma = 0;

            for (int i = 0; i < 9; i++)
            {
                soma += (10 - i) * numeros[i];
            }

            int resultado = soma % 11;

            if (resultado == 1 || resultado == 0)
            {
                if (numeros[9] != 0)
                {
                    yield return(new ValidationResult("Cpf inválido"));
                }
            }
            else if (numeros[9] != 11 - resultado)
            {
                yield return(new ValidationResult("Cpf inválido"));
            }

            soma = 0;
            for (int i = 0; i < 10; i++)
            {
                soma += (11 - i) * numeros[i];
            }

            resultado = soma % 11;

            if (resultado == 1 || resultado == 0)
            {
                if (numeros[10] != 0)
                {
                    yield return(new ValidationResult("Cpf inválido"));
                }
            }
            else
            if (numeros[10] != 11 - resultado)
            {
                yield return(new ValidationResult("Cpf inválido"));
            }
        }
 public bool IsSatisfiedBy(Cliente cliente)
 {
     return(Cpf.Validar(cliente.Cpf));
 }
Esempio n. 15
0
 public bool CpfJaCadastrado(Cpf cpf, int usuarioId)
 {
     return(_usuarioRepository.Get().Any(x => x.Cpf.Codigo == cpf.Codigo &&
                                         x.Id != usuarioId));
 }
Esempio n. 16
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     return(Cpf.Validar(value.ToString()) ? ValidationResult.Success : new ValidationResult("CPF em formato inválido"));
 }
Esempio n. 17
0
        public void ValidateReturnsFalseIfCpfIsOnlyEight()
        {
            var actual = Cpf.Validate("888.888.888-88");

            Assert.False(actual);
        }
Esempio n. 18
0
        public void ValidateReturnsFalseIfCpfIsOnlySeven()
        {
            var actual = Cpf.Validate("777.777.777-77");

            Assert.False(actual);
        }
Esempio n. 19
0
        public void LooseParseReturnsACpfObjectIfCpfIsValid()
        {
            var cpf = Cpf.Parse(CpfTest.looseValidCpf);

            Assert.NotNull(cpf);
        }
Esempio n. 20
0
        public void LooseParseReturnsACpfObjectIfFormattedCpfIsValid()
        {
            var cpf = Cpf.Parse(CpfTest.strictValidCpf);

            Assert.NotNull(cpf);
        }
Esempio n. 21
0
        public void ValidateReturnsFalseIfCpfIsOnlyNine()
        {
            var actual = Cpf.Validate("999.999.999-99");

            Assert.False(actual);
        }
Esempio n. 22
0
        public override string ToString()
        {
            string minhaString = "PARTE CONTRARIA: " + IdParteContraria.ToString() + "|" + Nome.ToString() + "|" + Cpf.ToString() +
                                 "|" + Cnpj.ToString() + "|" + Tipo.ToString();

            return(minhaString);
        }
Esempio n. 23
0
        public void ValidateReturnsFalseIfCpfContainsInvalidChars()
        {
            var actual = Cpf.Validate("714o256s8");

            Assert.False(actual);
        }
Esempio n. 24
0
 public ClientePessoaFisica()
 {
     Cpf  = new Cpf();
     Rg   = new Rg();
     Sexo = new Sexo();
 }
Esempio n. 25
0
        public void ValidateReturnsFalseIfCnpjIsLooseAndGreaterThanElevenCaracters()
        {
            var actual = Cpf.Validate("12345678901234567890");

            Assert.False(actual);
        }
        public void ValidarCpfComFalha(string cpf)
        {
            var validacaoCpf = Cpf.EhValido(cpf);

            Assert.False(validacaoCpf);
        }
Esempio n. 27
0
        public void ToStringReturnsStringWithNoPunctuationIfCpfPunctuationIsStrict()
        {
            var cpf = new Cpf("714.025.658-60", CpfPunctuation.Strict);

            var expected = "71402565860";
            var actual = cpf.ToString();

            Assert.AreEqual<string>(expected, actual);
        }
Esempio n. 28
0
 public void Cpf_New_Cpf_Invalido_0d89502b3454e()
 {
     var cpf = new Cpf("0d89502b3454e");
 }
Esempio n. 29
0
        public void ValidateReturnsFalseIfCpfIsHalfPunctuatedAndValidAndLoose()
        {
            var actual = Cpf.Validate("714.025.65860", CpfPunctuation.Loose);

            Assert.False(actual);
        }
Esempio n. 30
0
        public void ValidateReturnsFalseIfCpfIsValidButNotStrict()
        {
            var actual = Cpf.Validate(looseValidCpf, CpfPunctuation.Strict);

            Assert.False(actual);
        }
Esempio n. 31
0
        public void ValidateReturnsTrueIfCpfIsValidAndStrict()
        {
            var actual = Cpf.Validate(CpfTest.strictValidCpf, CpfPunctuation.Strict);

            Assert.True(actual);
        }