Example #1
0
        public void ValidarModelo(InUsuario pUsuario, ref Usuarios usuario, Util.TipoAcao tipoAcao)
        {
            var dspUsuario = new DispatcherUsuarios();

            if (string.IsNullOrEmpty(pUsuario.Nome))
            {
                throw new Exception("Favor preencher o campo de nome.");
            }

            if (pUsuario.Nome.Length < 3)
            {
                throw new Exception("Nome inválido.");
            }

            if (string.IsNullOrEmpty(pUsuario.Sobrenome))
            {
                throw new Exception("Favor preencher o campo de sobrenome.");
            }

            if (pUsuario.Sobrenome.Length < 3)
            {
                throw new Exception("Sobrenome inválido.");
            }

            if (pUsuario.DataNascimento == DateTime.MinValue)
            {
                throw new Exception("Data de nascimento inválida");
            }

            if (pUsuario.DataNascimento >= DateTime.Now.Date)
            {
                throw new Exception("Data de nascimento não pode ser depois que a data atual");
            }

            if (string.IsNullOrEmpty(pUsuario.Email))
            {
                throw new Exception("Favor preencher o campo de email.");
            }

            if (dspUsuario.ValidarEmail(pUsuario.Email, tipoAcao, pUsuario.Id))
            {
                throw new Exception("Email já cadastrado na base de dados.");
            }

            if (pUsuario.Escolaridade == Util.Escolaridade.Indefinido)
            {
                throw new Exception("Favor selecionar uma das opções de escolaridade.");
            }

            usuario.DataNascimento = pUsuario.DataNascimento;
            usuario.Email          = pUsuario.Email;
            usuario.Escolaridade   = pUsuario.Escolaridade;
            usuario.Id             = pUsuario.Id;
            usuario.Nome           = pUsuario.Nome;
            usuario.Sobrenome      = pUsuario.Sobrenome;
        }
Example #2
0
        public bool ValidarEmail(string email, Util.TipoAcao tipoAcao, int id)
        {
            if (tipoAcao == Util.TipoAcao.Adicionar)
            {
                return(dbContext.Usuarios.Where(a => a.Email == email).ToList().Count > 0);
            }

            if (tipoAcao == Util.TipoAcao.Editar)
            {
                return(dbContext.Usuarios.Where(a => a.Email == email && a.Id != id).ToList().Count > 0);
            }

            return(true);
        }