Exemple #1
0
        public AddAlunoViewModel()
        {
            _AlunoValidator  = new AlunoValidator();
            _Aluno           = new Aluno();
            _AlunoRepository = new AlunoRepository();

            AddAlunoCommand      = new Command(async() => await AddAluno());
            ViewAllAlunosCommand = new Command(async() => await ExibirAlunoLista());
        }
Exemple #2
0
        public DetailsViewModel(int selectedAlunoID)
        {
            _AlunoValidator  = new AlunoValidator();
            _Aluno           = new Aluno();
            _Aluno.Id        = selectedAlunoID;
            _AlunoRepository = new AlunoRepository();

            UpdateAlunoCommand = new Command(async() => await UpdateAluno());
            DeleteAlunoCommand = new Command(async() => await DeleteAluno());

            EncontrarDetalhesDoAluno();
        }
        public void ValidaDataNascimento_Nulo_False()
        {
            Aluno aluno = new Aluno()
            {
                Nome           = "teste",
                Sobrenome      = "teste",
                DataNascimento = DateTime.Parse("0001 - 01 - 01T00:00:00"),
                Cpf            = "11111111111"
            };
            var result = new AlunoValidator().Valida(aluno);

            Assert.IsFalse(result.IsValid);
        }
        public void ValidaDataNascimento_True()
        {
            Aluno aluno = new Aluno()
            {
                Nome           = "teste",
                Sobrenome      = "teste",
                DataNascimento = DateTime.Parse("1980 - 10 - 27T00:00:00"),
                Cpf            = "11111111111"
            };
            var result = new AlunoValidator().Valida(aluno);

            Assert.IsTrue(result.IsValid);
        }
        public void ValidaTamanhoePadraoCpfInformado_True()
        {
            Aluno aluno = new Aluno()
            {
                Nome           = "teste",
                Sobrenome      = "teste",
                DataNascimento = DateTime.Parse("2000 - 01 - 01T00:00:00"),
                Cpf            = "11111111111"
            };
            var result = new AlunoValidator().Valida(aluno);

            Assert.IsTrue(result.IsValid);
        }
        public void ValidaCpfFormatado_false()
        {
            Aluno aluno = new Aluno()
            {
                Nome           = "teste",
                Sobrenome      = "teste",
                DataNascimento = DateTime.Parse("2000 - 01 - 01T00:00:00"),
                Cpf            = "007348499a4"
            };
            var cpfFormatado = new AlunoValidator().FormataCPF(aluno);

            bool match = Regex.IsMatch(cpfFormatado, @"^\d{3}\.\d{3}\.\d{3}\-\d{2}$");

            Assert.IsFalse(match);
        }
        public PadraoResult <Aluno> CadastrarAluno(Aluno aluno)
        {
            var validator = new AlunoValidator();
            var valida    = validator.Valida(aluno);
            var result    = new PadraoResult <Aluno>();

            if (!valida.IsValid)
            {
                result.Error   = true;
                result.Message = valida.Erros;
                result.Status  = HttpStatusCode.BadRequest;
                return(result);
            }
            aluno.Cpf = validator.FormataCPF(aluno);
            validator.SenhaLoginInicial(aluno);
            aluno.TipoUsuario = MODELS.Enum.TipoUsuarioEnum.ALUNO;
            try
            {
                using (db)
                {
                    foreach (var item in db.Alunos)
                    {
                        if (item.Cpf == aluno.Cpf)
                        {
                            result.Error = true;
                            result.Message.Add($"O nome {aluno.Nome} com CPF {aluno.Cpf} já esta cadastrado");
                            result.Status = HttpStatusCode.BadRequest;
                            return(result);
                        }
                    }

                    db.Alunos.Add(aluno);
                    db.SaveChanges();
                    result.Error  = false;
                    result.Status = HttpStatusCode.OK;
                    result.Data.Add(aluno);
                    return(result);
                }
            }
            catch (Exception e)
            {
                result.Error = true;
                result.Message.Add(e.Message);
                return(result);
            }
        }
Exemple #8
0
        private Retorno dadosAlunoValido(Aluno aluno)
        {
            AlunoValidator validacaoAluno = new AlunoValidator();

            ValidationResult resultadoValidacao = validacaoAluno.Validate(aluno);

            Retorno retorno = new Retorno();

            if (!resultadoValidacao.IsValid)
            {
                foreach (var item in resultadoValidacao.Errors)
                {
                    retorno.sucesso = false;
                    retorno.mensagens.Add(item.ErrorMessage);
                }
                return(retorno);
            }

            retorno.sucesso = true;
            return(retorno);
        }
        public void Validate()
        {
            var alunoValidator = new AlunoValidator();

            alunoValidator.ValidateAndThrow(this);
        }