Exemple #1
0
        public Models.TbCliente Cadastrar(Models.TbCliente client, string email, string senha)
        {
            if (string.IsNullOrEmpty(client.DsEndereco))
            {
                throw new ArgumentException("Adicione um endereço");
            }

            Models.teste_driveContext ctx = new Models.teste_driveContext();
            if ((DateTime.Now.Year - client.DtNascimeto.Value.Year) < 18)
            {
                throw new ArgumentException("Menor de idade não pode fazer cadastro");
            }

            if (string.IsNullOrEmpty(client.NmCliente))
            {
                throw new ArgumentException("Nome do cliente está nulo");
            }

            Func <string, bool> r = (a) => {
                int cont = 0;
                foreach (char u in a)
                {
                    if (u == ' ')
                    {
                        cont += 1;
                    }
                }
                return(cont < 2);
            };

            foreach (char letra in client.NmCliente.ToLower())
            {
                if (((int)letra < 97 || (int)letra > 122) && (int)letra != 32)
                {
                    throw new ArgumentException("Um nome só pode conter letras");
                }
            }

            if (db.ConsultarTodos().Any(x => x.NmCliente.ToLower() == client.NmCliente.ToLower()))
            {
                throw new ArgumentException("Nome ja existe. Tente outro");
            }

            if (r(client.NmCliente))
            {
                throw new ArgumentException("Colocar nome completo");
            }

            if (db.ConsultarTodos().Any(x => x.DsCpf == client.DsCpf))
            {
                throw new ArgumentException("CPF já existe.");
            }

            if (client.DsTelefone.Replace("-", "").Length != 11)
            {
                throw new ArgumentException("Numero de telefone inválido");
            }

            if (client.DsCelular.Replace("-", "").Length != 11)
            {
                throw new ArgumentException("Numero de celular inválido");
            }

            if (client.NrResidencia == 0)
            {
                throw new ArgumentException("Numero de residencia invalido");
            }

            if (client.DsCpf.Replace("-", "").Length != 11)
            {
                throw new ArgumentException("CPF invalido");
            }

            if (client.DsCnh.Replace("-", "").Length != 11)
            {
                throw new ArgumentException("CNH invalido");
            }

            Console.WriteLine("Validar senha");
            this.Seem(senha, email);

            Console.WriteLine("Validado");

            return(db.Cadastrar(client, senha, email));
        }