Esempio n. 1
0
        /// <summary>
        /// Obtem dados de um usuario
        /// </summary>
        /// <param name="usuarioModel"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public async Task <Result <UsuarioTipoModel> > ObterUsuario(UsuarioModel usuarioModel, CancellationToken ctx)
        {
            var usuario = _mapper.Map <UsuarioModel, Usuario>(usuarioModel);
            var output  = new UsuarioTipoModel();

            if (usuario.Invalid)
            {
                return(Result <UsuarioTipoModel> .Error(usuario.Notifications));
            }

            var usuarioExistente = await _usuarioRepository.ObterPorLogin(usuario.Login, ctx);

            if (usuarioExistente == null)
            {
                usuario.AddNotification(nameof(Usuario), MensagensInfo.Usuario_NaoExiste);
                return(Result <UsuarioTipoModel> .Error(usuario.Notifications));
            }

            if (usuario.Senha != usuarioExistente.Senha)
            {
                usuario.AddNotification(nameof(Usuario), MensagensInfo.Usuario_SenhaInvalida);
                return(Result <UsuarioTipoModel> .Error(usuario.Notifications));
            }

            var cpf = new CPF(usuario.Login);

            if (cpf.Valid)
            {
                var cliente = await _clienteRepository.ObterPorCpf(usuarioModel.Login, ctx);

                if (cliente == null)
                {
                    usuario.AddNotification(nameof(Usuario), MensagensInfo.Usuario_ClienteNaoExiste);
                    return(Result <UsuarioTipoModel> .Error(usuario.Notifications));
                }

                output.Cliente = _mapper.Map <Cliente, ClienteModel>(cliente);
            }
            else
            {
                var operador = await _operadorRepository.ObterPorMatricula(usuarioModel.Login, ctx);

                if (operador == null)
                {
                    usuario.AddNotification(nameof(Usuario), MensagensInfo.Usuario_OperadorNaoExiste);
                    return(Result <UsuarioTipoModel> .Error(usuario.Notifications));
                }

                output.Operador = _mapper.Map <Operador, OperadorModel>(operador);
            }

            return(Result <UsuarioTipoModel> .Ok(output));
        }
        public int CadastrarCliente(ClientesDTO dto)
        {
            if (dto.ds_Bairro == string.Empty)
            {
                throw new ArgumentException("Bairro não pode estar vazio.");
            }

            if (dto.ds_Logradouro == string.Empty)
            {
                throw new ArgumentException("Logradouro não pode estar vazio.");
            }

            if (dto.ds_UF == string.Empty)
            {
                throw new ArgumentException("UF não pode estar vazio.");
            }

            if (dto.ds_CEP == string.Empty)
            {
                throw new ArgumentException("CEP não pode estar vazio.");
            }

            ValidarNumero regexNum = new ValidarNumero();
            ValidarTexto  regexTxt = new ValidarTexto();

            regexTxt.ValidarEmail(dto.ds_Email);
            regexTxt.ValidarNome(dto.nm_Nome);
            regexNum.ValidarTelefoneFixo(dto.num_Telefone);
            regexNum.ValidarTelefoneCelular(dto.num_Celular);

            CPF validar = new CPF();

            validar.ValidarCPF(dto.ds_CPF);

            DESCripto cripto = new DESCripto();

            dto.nm_Nome      = cripto.Criptografar(Program.chave, dto.nm_Nome);
            dto.ds_CPF       = cripto.Criptografar(Program.chave, dto.ds_CPF);
            dto.num_Celular  = cripto.Criptografar(Program.chave, dto.num_Celular);
            dto.num_Telefone = cripto.Criptografar(Program.chave, dto.num_Telefone);
            dto.ds_Email     = cripto.Criptografar(Program.chave, dto.ds_Email);

            ClientesDatabase db = new ClientesDatabase();
            int idCliente       = db.CadastrarCliente(dto);

            if (idCliente == 0)
            {
                throw new ArgumentException("O cliente não foi cadastrado com sucesso!");
            }

            return(idCliente);
        }
Esempio n. 3
0
        public static Usuario UsuarioFake()
        {
            var nome             = new NomeCompleto("Fake", "Sobrenome");
            var email            = new Email("*****@*****.**");
            var sexo             = Sexo.Masculino;
            var cpf              = new CPF("332.447.920-73");
            var dataDeNascimento = new DataDeNascimento(new DateTime(2002, 7, 22));
            var usuario          = new Usuario(nome, sexo, email, cpf, dataDeNascimento);

            usuario.DefinirSenha(Senha.GerarSenha("123456"));

            return(usuario);
        }
Esempio n. 4
0
        public void deve_retornarFalse_paraCpfNoFormatoInvalido()
        {
            //arrage
            var cpfStr  = "string";
            var cpfStr2 = "1700037";
            //act
            var cpf  = CPF.ValidarCPFPatterns(cpfStr);
            var cpf2 = CPF.ValidarCPFPatterns(cpfStr2);

            //assert
            cpf.Should().BeFalse();
            cpf.Should().BeFalse();
        }
Esempio n. 5
0
        public void deve_retornar_cpf_com_formatacao()
        {
            //arrage
            var cpfStr  = "01794200037";
            var cpfStr2 = "1794200037";
            //act
            var cpfComMascara  = CPF.ObterCPFComFormatacao(cpfStr);
            var cpfComMascara2 = CPF.ObterCPFComFormatacao(cpfStr2);

            //assert
            cpfComMascara.Digitos.Should().Be("017.942.000-37");
            cpfComMascara2.Digitos.Should().Be("017.942.000-37");
        }
Esempio n. 6
0
 void RbtFisicaClick(object sender, EventArgs e)
 {
     dtpNascimento.Enabled = true;
     lblDescricao.Text     = "Nome";
     lblCNPJ.Text          = "CPF";
     edtCNPJ.MaxLength     = 11;
     edtCNPJ.Width         = 104;
     if (edtCNPJ.Text.Length == 18)
     {
         edtCNPJ.Text = CNPJ.TiraEdicao(edtCNPJ.Text).Substring(0, 11);
         edtCNPJ.Text = CPF.PoeEdicao(edtCNPJ.Text);
     }
 }
Esempio n. 7
0
 void RbtJuridicaClick(object sender, EventArgs e)
 {
     dtpNascimento.Enabled = false;
     lblDescricao.Text     = "Razão Social";
     lblCNPJ.Text          = "CNPJ";
     edtCNPJ.MaxLength     = 14;
     edtCNPJ.Width         = 132;
     if (edtCNPJ.Text.Length == 14)
     {
         edtCNPJ.Text = CPF.TiraEdicao(edtCNPJ.Text) + "000";
         edtCNPJ.Text = CNPJ.PoeEdicao(edtCNPJ.Text);
     }
 }
Esempio n. 8
0
        public bool EhValido()
        {
            AddNotifications(new ValidationContract()
                             .HasMaxLen(Nome.ToString(), 14, "Nome", "Nome do Usuário maior que o esperado")

                             .HasMaxLen(CPF.ToString(), 14, "CPF", "CPF do Usuário maior que o esperado")

                             .HasMaxLen(CEP.ToString(), 9, "CEP", "CEP do Usuário maior que o esperado")

                             .HasMaxLen(Estado.ToString(), 2, "Estado", "Estado do Usuário maior que o esperado")
                             );
            return(Valid);
        }
Esempio n. 9
0
        protected override void SetNewAccountId()
        {
            try
            {
                string cpf     = CPF.Substring(0, 4);
                string guid    = new Random().Next(1, 999999999).ToString("D9");
                string checker = new Random().Next(10, 99).ToString();

                AccountId = $"{DateTimeOffset.Now.ToString("yyyyMMdd")}{cpf}{guid}-{checker}";
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 10
0
        public static string CPFMascara(string cpf, bool mascara = true)
        {
            CPF cpfBR = cpf;

            if (mascara)
            {
                return(cpfBR.ComMascara());
            }
            else
            {
                return(cpfBR.SemMascara());
            }
        }
Esempio n. 11
0
        public void Quando_ObterCpf_Retorna_CpfFormatado(string val)
        {
            //arrange
            var cpf = new CPF(val);

            //act
            var result = cpf.Formatado;

            //assert
            Assert.AreEqual('.', result[3]);
            Assert.AreEqual('.', result[7]);
            Assert.AreEqual('-', result[11]);
        }
Esempio n. 12
0
        public void AtualizaDados(string NOME, CPF CPF, RG RG, DateTime DT_NASCIMENTO)
        {
            this.InicializaVariaveis();

            this.NOME          = NOME;
            this.CPF           = CPF;
            this.CPF           = CPF;
            this.RG            = RG;
            this.DT_NASCIMENTO = DT_NASCIMENTO;

            this.DT_ALTERACAO = DateTime.Now;
            this.APROVADO     = false;
        }
Esempio n. 13
0
        public static Cliente Criar(CPF cpf, DataNascimento dataNascimento)
        {
            if (cpf is null)
            {
                throw new System.ArgumentNullException(nameof(cpf));
            }

            if (dataNascimento is null)
            {
                throw new System.ArgumentNullException(nameof(dataNascimento));
            }

            return(new Cliente(cpf, dataNascimento));
        }
Esempio n. 14
0
 public Person(
     User user,
     Name name,
     CPF cpf,
     Email email,
     string phone)
 {
     User       = user;
     Name       = name;
     CPF        = CPF;
     Email      = email;
     Phone      = phone;
     _addresses = new List <Address>();
 }
Esempio n. 15
0
        protected override void Validate()
        {
            if (!Email.IsValid)
            {
                Notify(Email.GetNotifications());
            }

            if (!CPF.IsValid)
            {
                Notify(CPF.GetNotifications());
            }

            Notify(AssertionConcern.AssertTrue(!RegistradoSPC, "Registrado no SPC"));
        }
Esempio n. 16
0
        /// <summary>
        /// Retorna
        /// </summary>
        /// <param name="passageiro"></param>
        /// <returns></returns>
        public StringBuilder RetornarDadosPassageiro()
        {
            StringBuilder texto = new StringBuilder();

            texto.AppendLine("\n-----> Dados do passageiro\n");

            texto.AppendFormat("\tNome: {0} {1}\n", Nome, Sobrenome);
            texto.AppendFormat("\tCPF: {0}\n", CPF.ToString().PadLeft(11, '0'));
            texto.AppendFormat("\tEndereço: {0}\n", Endereco);
            texto.AppendFormat("\tNúmero da passagem: {0}\n", NumeroPassagem);
            texto.AppendFormat("\tNúmero da poltrona: {0}\n", NumeroPoltrona);

            return(texto);
        }
Esempio n. 17
0
        public Hospede(CPF cpf, Idade idade, AgendaTelefonica agenda,
                       Endereco endereco, Email email)
        {
            if (idade.Valor < 18)
            {
                throw new InvalidOperationException();
            }

            Cpf              = cpf;
            Idade            = idade;
            AgendaTelefonica = agenda;
            Endereco         = endereco;
            Email            = email;
        }
Esempio n. 18
0
        public void deve_garantir_que_dois_cpfs_com_os_mesmos_digitos_sejam_o_mesmo_objeto()
        {
            //arrage
            var cpf1 = new CPF("1794200037");
            var cpf2 = new CPF("1794200037");

            //arrange
            var cpf1Mask = CPF.ObterCPFComFormatacao(cpf1.Digitos);
            var cpf2Mask = CPF.ObterCPFComFormatacao(cpf2.Digitos);

            //assert
            cpf1.Should().Be(cpf2);
            cpf1Mask.Should().Be(cpf1Mask);
        }
        public MensagemRecebida(Guid codigoEscritorio,
                                string nomeCliente,
                                string contatoCliente,
                                CPF cpfCliente,
                                Descricao mensagem)
        {
            CodigoEscritorio = codigoEscritorio;
            NomeCliente      = nomeCliente;
            ContatoCliente   = contatoCliente;
            CpfCliente       = cpfCliente;
            Mensagem         = mensagem;

            Validar();
        }
Esempio n. 20
0
 public Funcionario
 (
     string nome, string email, string cpf,
     Usuario usuario, Guid cargoId, DateTime dataNascimento
 )
 {
     Nome           = nome;
     Email          = new Core.ValueTypes.Email(email);
     CPF            = new CPF(cpf);
     CargoId        = cargoId;
     DataNascimento = dataNascimento;
     Usuario        = usuario;
     Ativo          = false;
 }
Esempio n. 21
0
 public Cliente
 (
     Usuario usuario,
     string nome,
     DateTime dataNascimento,
     string cpf,
     string email
 )
 {
     Usuario        = usuario;
     Nome           = nome;
     DataNascimento = dataNascimento;
     CPF            = new CPF(cpf);
     Email          = new Core.ValueTypes.Email(email);
 }
        public MensagemPublica(Guid codigoEscritorio,
                               string nomeCliente,
                               Email contatoCliente,
                               CPF cpfCliente,
                               Descricao mensagem)
        {
            CodigoEscritorio = codigoEscritorio;
            NomeCliente      = nomeCliente;
            ContatoCliente   = contatoCliente;
            CpfCliente       = cpfCliente;
            Mensagem         = mensagem;
            Status           = EStatusMensagemPublica.Publica;

            Validar();
        }
        public ClienteEstaConsistenteValidation()
        {
            //var CPFCliente = new ClienteDeveTerCpfValidoSpecification();
            var clienteEmail      = new ClienteDeveTerEmailValidoSpecification();
            var clienteMaioridade = new ClienteDeveSerMaiorDeIdadeSpecification();
            var clienteNomeCurto  = new GenericSpecification <Cliente>(c => c.Nome.Length >= 2);
            var clienteEmailVazio = new GenericSpecification <Cliente>(c => !string.IsNullOrWhiteSpace(c.Email));
            var CPFCliente        = new GenericSpecification <Cliente>(c => CPF.Validar(c.CPF));

            Add("CPFCliente", new Rule <Cliente>(CPFCliente, "Cliente informou um CPF inválido."));
            Add("clienteEmail", new Rule <Cliente>(clienteEmail, "Cliente informou um e-mail inválido."));
            Add("clienteMaioridade", new Rule <Cliente>(clienteMaioridade, "Cliente não tem maioridade para cadastro."));
            Add("clienteNomeCurto", new Rule <Cliente>(clienteNomeCurto, "O nome do cliente precisa ter mais de 2 caracteres."));
            Add("clienteEmailVazio", new Rule <Cliente>(clienteEmailVazio, "O e-mail não pode estar em branco."));
        }
Esempio n. 24
0
        protected void ValidatePrivateIndividual(Expression <Func <T, string> > cpfcnpjFiled,
                                                 Expression <Func <T, string> > rgFiled,
                                                 Expression <Func <T, DateTimeOffset?> > birthDateFiled)
        {
            When(supplier => CPF.IsCpf(cpfcnpjFiled.Compile().Invoke(supplier)), () =>
            {
                RuleFor(rgFiled).Cascade(CascadeMode.StopOnFirstFailure)
                .NotNull().WithMessage("RG was not provided for private individual.")
                .NotEmpty().WithMessage("RG was not provided for private individual.");

                RuleFor(birthDateFiled).Cascade(CascadeMode.StopOnFirstFailure)
                .NotNull().WithMessage("Birth date was not provided for private individual.")
                .NotEmpty().WithMessage("Birth date was not provided for private individual.");
            });
        }
Esempio n. 25
0
 public Cliente(
     Nome nome,
     Email email,
     CPF cpf,
     Endereco endereco,
     string telefone,
     DateTime dataNascimento)
 {
     Nome           = nome;
     Email          = email;
     CPF            = cpf;
     Endereco       = endereco;
     Telefone       = telefone;
     DataNascimento = dataNascimento;
 }
Esempio n. 26
0
        /// <summary>
        /// Construtor de cliente
        /// </summary>
        /// <param name="nome"></param>
        /// <param name="cpf"></param>
        /// <param name="aniversario"></param>
        /// <param name="endereco"></param>
        public Cliente(string nome, CPF cpf, DateTime aniversario, EnderecoCompleto endereco)
        {
            Nome        = nome;
            Cpf         = cpf;
            Aniversario = aniversario;
            Endereco    = endereco;
            DataCriacao = DateTime.UtcNow;

            AddNotifications(new Contract()
                             .Requires()
                             .IsNotNull(Nome, nameof(Nome), "Nome não pode ser nulo")
                             .IsNotNull(Cpf, nameof(Cpf), "Cpf não pode ser nulo")
                             .IsNotNull(Aniversario, nameof(Aniversario), "Data de aniversário não pode ser nula")
                             .IsNotNull(Endereco, nameof(Endereco), "Endereço não pode ser nulo"));
        }
        public void Deve_Adicionar_Notificacao_Quando_Nome_Nao_Informado()
        {
            var cpf            = new CPF("89071787044");
            var dataNascimento = new DateTime(1990, 10, 20);
            var sut            = new PessoaFisica("", "3330909", dataNascimento, cpf);
            var esperado       = new List <string>()
            {
                "Nome é obrigatório"
            };

            Assert.Equal(esperado, sut.Notificacoes);

            sut = new PessoaFisica(null, "3330909", dataNascimento, cpf);

            Assert.Equal(esperado, sut.Notificacoes);
        }
Esempio n. 28
0
        public void DadasTodasAsInformacoesValidasOConstrutorDeveraCriarUmCandidatoValido()
        {
            Email    email    = new Email("*****@*****.**");
            Nome     nome     = new Nome("Joaquim José da Silva Xavier");
            Telefone telefone = new Telefone("3133441678");
            CPF      cpf      = new CPF("86267524582");

            Candidato candidato = new Candidato(email, nome, telefone, cpf, "98765123", "98765123");

            Assert.IsTrue(candidato.IsValid());

            Assert.AreEqual(email, candidato.Email);
            Assert.AreEqual(nome, candidato.Nome);
            Assert.AreEqual(telefone, candidato.Telefone);
            Assert.AreEqual(cpf, candidato.CPF);
        }
Esempio n. 29
0
        public Patient(string name, DateTime birthDate, Genre genre, string cpf, string rg, string information, Address address, Phone phone, string photo,
                       Guid insuranceHealthId)
        {
            Name              = name;
            BirthDate         = birthDate;
            Genre             = genre;
            CPF               = new CPF(cpf);
            RG                = rg;
            Information       = information;
            Address           = address;
            Phone             = phone;
            Photo             = photo;
            InsuranceHealthId = insuranceHealthId;

            Validate();
        }
Esempio n. 30
0
        public override dynamic ToObject()
        {
            dynamic customer = new ExpandoObject();

            customer.name         = Name;
            customer.cpf          = CPF.ToDigitsOnly();
            customer.phone_number = PhoneNumber.ToDigitsOnly();
            customer.birth        = Birth.ToStringDate();
            customer.address      = Address.ToObject();
            customer.email        = Email;
            if (JuridicalPerson != null)
            {
                customer.juridical_person = JuridicalPerson.ToObject();
            }
            return(customer);
        }