コード例 #1
0
        static void Main(string[] args)
        {
            #region Cadastrando primeiro aluno
            AlunoModel aluno = new AlunoModel();     // Instanciando objeto
            aluno.cadastrarAluno();
            aluno.exibirALuno();
            #endregion

            #region Cadastrando segundo aluno
            AlunoModel aluno2 = new AlunoModel();     // Instanciando objeto
            aluno2.cadastrarAluno();
            aluno2.exibirALuno();

            #endregion
        }
コード例 #2
0
        // Busca aluno por cpf
        public AlunoModel readAlunoByCPF(string cpf)
        {
            String     consulta = "select cpf as 'CPF', nome as 'Nome', datanasc as 'DataNasc' from aluno where cpf like '%" + cpf + "%'";
            DataTable  dt       = db.ExecuteQuery(consulta);
            AlunoModel aluno    = null;

            foreach (DataRow dr in dt.Rows)
            {
                aluno          = new AlunoModel();
                aluno.Cpf      = dr["cpf"].ToString();
                aluno.Nome     = dr["nome"].ToString();
                aluno.Datanasc = DateTime.Parse(dr["datanasc"].ToString());
            }
            return(aluno);
        }
コード例 #3
0
        public bool CadastrarAluno(AlunoModel model)
        {
            if (ModelState.IsValid)
            {
                var aluno = new AlunoMOD()
                {
                    Nome = model.Nome,
                    RM   = model.RM
                };

                return(_alunoBLL.CadastrarAluno(aluno));
            }

            return(false);
        }
コード例 #4
0
        private void ListarGrid()
        {
            try
            {
                List <AlunoEnt> Lista = new List <AlunoEnt>();
                Lista = new AlunoModel().Lista();
                GridAluno.AutoGenerateColumns = false;
                GridAluno.DataSource          = Lista;
            }

            catch (Exception ex) //Caso ocorra erro ao listar grid
            {
                MessageBox.Show("Erro ao listar dados" + ex.Message);
            }
        }
コード例 #5
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                AlunoModel _aluno = new AlunoModel();

                _aluno.Deletar(id);

                return(Ok("Deletado com sucesso"));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #6
0
        public IHttpActionResult Put(int id, [FromBody] AlunoDTO aluno)
        {
            try
            {
                AlunoModel _aluno = new AlunoModel();
                aluno.id = id;
                _aluno.Atualizar(aluno);

                return(Ok(_aluno.listarAlunos(id).FirstOrDefault()));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: andre-mit/POO-CSHARP
        private void txbBusca_OnTextChange(object sender, EventArgs e)
        {
            //condição para caso o texto esteja nulo, apresentar o padrão
            if (txbBusca.text == "")
            {
                AlunoController alunoController = new AlunoController();

                dgvAlunos.DataSource = alunoController.Listar();
            }
            else
            {
                AlunoModel alunoModel = new AlunoModel();
                BuscarAluno(alunoModel);
            }
        }
コード例 #8
0
        // GET: Aluno/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AlunoModel alunoModel = db.Alunos.Find(id);

            if (alunoModel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CursoID = new SelectList(db.Cursos, "Id", "Nome", alunoModel.CursoID);
            return(View(alunoModel));
        }
コード例 #9
0
        public DataTable PesquisarNome(AlunoModel aluno)
        {
            try
            {
                AlunoDao  alunoDao = new AlunoDao();
                DataTable dt       = new DataTable();
                dt = alunoDao.BuscarNome(aluno);

                return(dt);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #10
0
        public void TestDeleteAlunoERROR()
        {
            var alunoRepository = new AlunoRepository();

            var alunoModel = new AlunoModel()
            {
                AlunoCPF        = 2,
                AlunoNome       = "Logan",
                AlunoSobrenome  = "Da Silva",
                AlunoCurso      = "Geografia",
                AlunoNascimento = Convert.ToDateTime("10/02/1998"),
            };

            Assert.AreEqual(alunoRepository.DeleteAluno(alunoModel), false);
        }
コード例 #11
0
        async void btnSalvar_Clicked(object sender, EventArgs e)
        {
            AlunoModel objAluno = new AlunoModel();

            objAluno.Nome     = EntryNome.Text;
            objAluno.Idade    = Convert.ToInt32(EntryIdade.Text);
            objAluno.Sexo     = picSexo.SelectedItem.ToString();
            objAluno.Telefone = EntryFone.Text;
            objAluno.Email    = EntryEmail.Text;
            // objAluno.DtNasc = dpDataNascimento.ToString();



            await Navigation.PushAsync(new ResultPage(objAluno));
        }
コード例 #12
0
        // [Authorize]
        public IHttpActionResult Recuperar()
        {
            try
            {
                var aluno = new AlunoModel();

                var alunos = aluno.ListarAluno();

                return(Ok(alunos));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #13
0
        private async void BtnSalvar_Clicked(object sender, EventArgs e)
        {
            await DisplayAlert("Atenção", "Cadastro realizado com sucesso!", "OK");

            AlunoModel objAluno = new AlunoModel();

            objAluno.Nome     = EntryNome.Text;
            objAluno.Idade    = Convert.ToInt32(EntryIdade.Text);
            objAluno.Sexo     = picSexo.SelectedItem.ToString();
            objAluno.Telefone = EntryFone.Text;
            objAluno.Email    = EntryEmail.Text;
            objAluno.DtNasc   = dpDataNascimento.Date.ToString("dd/MM/yyyy");

            await Navigation.PushAsync(new App1.Views.Report.FichaAluno(objAluno));
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: angelabronetti/Senai
        static void Main(string[] args)
        {
            AlunoModel aluno1 = new AlunoModel();

            Console.Clear(); // Limpa a tela

            aluno1.CadastrarAlunos();
            aluno1.ListarAluno();
            aluno1.IrAoBanheiro();

            /// // Exibindo as informações
            System.Console.WriteLine("Nome: " + aluno1.Nome);
            System.Console.WriteLine("Curso: " + aluno1.Curso);
            System.Console.WriteLine("RG: " + aluno1.Rg);
            System.Console.WriteLine("Idade: " + aluno1.Idade);
        }
コード例 #15
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AlunoModel alunoModel = db.alunos.Include(c => c.Curso).First(a => a.Id == id);

            if (alunoModel == null)
            {
                HttpNotFound();
            }

            return(View(alunoModel));
        }
コード例 #16
0
        public ActionResult EditaAluno(AlunoModel model)
        {
            if (ModelState.IsValid)
            {
                var alunoAtt = aluno.listaAlunos.Where(x => x.Matricula == model.Matricula).FirstOrDefault();
                if (alunoAtt == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                alunoAtt.Matricula = model.Matricula;
                alunoAtt.Nome      = model.Nome;

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #17
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AlunoModel aluno = db.alunos.Where(a => a.Id == id).FirstOrDefault();

            ViewBag.CursoId = new SelectList(db.cursos, "Id", "Curso");
            if (aluno == null)
            {
                return(HttpNotFound());
            }
            return(View(aluno));
        }
コード例 #18
0
        public void TestCreateAlunoOK()
        {
            var alunoRepository = new AlunoRepository();

            var alunoModel = new AlunoModel()
            {
                AlunoCPF        = 99689899082,
                AlunoNome       = "Logan",
                AlunoSobrenome  = "Da Silva",
                AlunoCurso      = "Geografia",
                AlunoNascimento = Convert.ToDateTime("10/02/1998"),
            };

            Assert.AreEqual(alunoRepository.CreateAluno(alunoModel), true);
            alunoRepository.DeleteAluno(alunoModel);
        }
コード例 #19
0
        static void Main(string[] args)
        {
            //Declarando Objeto
            AlunoModel aluno1 = new AlunoModel(); // Declarando uma nova instância

            // Limpa a tela
            Console.Clear();

            // Cadastra um aluno.
            aluno1.CadastrarAluno();

            // Exibindo as informações
            aluno1.ExibirAluno();

            // Chamando método do objeto 'aluno1'
            aluno1.IrNoBanheiro();
        }
コード例 #20
0
 public IHttpActionResult Post([FromBody] AlunoDTO alunoDTO)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         AlunoModel aluno = new AlunoModel();
         aluno.Inserir(alunoDTO);
         return(Ok(aluno.ListarAlunos()));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
コード例 #21
0
 public IHttpActionResult Post(AlunoDTO aluno)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         AlunoModel _alunosIns = new AlunoModel();
         _alunosIns.Inserir(aluno);
         return(Ok(_alunosIns.ListarAluno(null)));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
コード例 #22
0
        public ActionResult Save(AlunoModel model)
        {
            ActionResult result = null;
            AlunoModel   aluno  = new AlunoModel();

            try
            {
                if (model.ID > 0)
                {
                    result                 = RedirectToAction(ActionAlterar, new { id = model.ID });
                    aluno                  = this.alunoBusiness.GetById(model.ID);
                    aluno.Nome             = model.Nome;
                    aluno.DataNascimento   = model.DataNascimento;
                    aluno.TurmaID          = model.TurmaID;
                    aluno.LastModifiedDate = DateTime.Now;
                    aluno.Status           = "UPDATED";
                    aluno.UserID           = 1;
                    aluno.FotoID           = 1;

                    this.alunoBusiness.Update(aluno);
                }
                else
                {
                    result                 = RedirectToAction(ActionNovo);
                    aluno.Nome             = model.Nome;
                    aluno.DataNascimento   = model.DataNascimento;
                    aluno.TurmaID          = model.TurmaID;
                    aluno.LastModifiedDate = DateTime.Now;
                    aluno.Status           = "ADDED";
                    aluno.UserID           = 1;
                    aluno.FotoID           = 1;

                    this.alunoBusiness.Add(aluno);
                }

                TempData[Constants.KEY_SUCCESS_MESSAGE] = Constants.GENERIC_MSG_FORM_SUCCESS_SAVE;
                result = RedirectToAction(ActionLista);
            }
            catch (Exception ex)
            {
                TempData[Constants.KEY_ERROR_MESSAGE] = ex.ToStringAll();
            }

            return(result);
        }
コード例 #23
0
        public bool Delete(AlunoModel entity)
        {
            try
            {
                if (entity.ID > 0)
                {
                    this.UOW.Alunos.Delete(entity.ID);
                    this.UOW.Commit();
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #24
0
        public IHttpActionResult Recuperar(string data, string nome)
        {
            try
            {
                AlunoModel             aluno  = new AlunoModel();
                IEnumerable <AlunoDTO> alunos = aluno.ListarAluno().Where(x => x.data == data || x.nome == nome);

                if (!alunos.Any())
                {
                    return(NotFound());
                }

                return(Ok(alunos));
            }
            catch (Exception ex) {
                return(InternalServerError(ex));
            }
        }
コード例 #25
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AlunoModel alunoModel = db.alunos.Find(id);

            if (alunoModel == null)
            {
                return(HttpNotFound());
            }

            db.alunos.Remove(alunoModel);
            db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
コード例 #26
0
        public IActionResult SalvarAluno([FromForm] AlunoModel alunoModel)
        {
            try
            {
                var alunoEntity = _mapper.Map <AlunoModel, Aluno>(alunoModel);
                alunoEntity = _alunoService.Insert <AlunoValidator>(alunoEntity);
            }
            catch (ArgumentException argEx)
            {
                ViewBag.Erro = argEx.Message;
                return(View("AdicionarAluno", alunoModel));
            }
            catch (Exception ex)
            {
                ViewBag.Erro = ex.Message;
            }

            return(RedirectToAction("Index"));
        }
コード例 #27
0
        public void TestDeleteNotaOK()
        {
            var notaRepository    = new NotaRepository();
            var alunoRepository   = new AlunoRepository();
            var materiaRepository = new MateriaRepository();

            var alunoModel = new AlunoModel()
            {
                AlunoCPF        = 99689899082,
                AlunoNome       = "Logan",
                AlunoSobrenome  = "Da Silva",
                AlunoCurso      = "Geografia",
                AlunoNascimento = Convert.ToDateTime("10/02/1998"),
            };

            alunoRepository.CreateAluno(alunoModel);
            alunoRepository.VerificaCPFAluno(alunoModel.AlunoCPF.ToString(), out int?idAluno);

            var materiaModel = new MateriaModel()
            {
                MateriaDesc    = "Matemática",
                MateriaDataCad = DateTime.Parse("10/10/2000"),
                materiaSitacao = "A"
            };

            materiaRepository.CreateMateria(materiaModel);
            materiaRepository.VerificaMateriaCadastrada(materiaModel.MateriaDesc, out int?idMateria);

            var notaModel = new NotasAlunoModel()
            {
                AlunoID     = Convert.ToInt32(idAluno),
                MateriaID   = Convert.ToInt32(idMateria),
                notaMateria = 100
            };

            notaRepository.SalvaNotaMateriaAluno(notaModel);

            Assert.AreEqual(notaRepository.DeletaNotaMateriaAluno(notaModel), true);

            notaRepository.DeletaNotaMateriaAluno(notaModel);
            alunoRepository.DeleteAluno(alunoModel);
            materiaRepository.DeleteMateria(materiaModel);
        }
コード例 #28
0
        public AlunoModel ObterPeloID(int id)
        {
            AlunoModel aluno   = null;
            SqlCommand comando = new BancoDadosConexao().ObterConexao();

            comando.CommandText = "SELECT IDAluno,NomeAluno,DataNascimento,IDProfessorResponsavel FROM dbo.Aluno WHERE IDAluno = @IDALUNO";
            comando.Parameters.AddWithValue("@IDALUNO", id);
            DataTable tabela = new DataTable();

            tabela.Load(comando.ExecuteReader());
            if (tabela.Rows.Count == 1)
            {
                aluno                       = new AlunoModel();
                aluno.ID                    = id;
                aluno.NomeAluno             = tabela.Rows[0][0].ToString();
                aluno.DataNascimento        = Convert.ToDateTime(tabela.Rows[0][1].ToString());
                aluno.IDProfessorResposavel = Convert.ToInt32(tabela.Rows[0][2].ToString());
            }
            return(aluno);
        }
コード例 #29
0
        public IHttpActionResult RecuperarPorDataNome(string data, string nome)
        {
            try
            {
                AlunoModel             aluno         = new AlunoModel();
                IEnumerable <AlunoDTO> alunosRetorno = aluno.listarAlunos()
                                                       .Where(a => a.Data == data || a.Nome == nome);

                if (!alunosRetorno.Any())
                {
                    return(NotFound());
                }

                return(Ok(alunosRetorno));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #30
0
ファイル: AlunoDao.cs プロジェクト: andre-mit/POO-CSHARP
        public DataTable BuscarNome(AlunoModel aluno)
        {
            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter();
                DataTable        dt = new DataTable();
                connection = new MySqlConnection(con);
                cmd        = new MySqlCommand("SELECT RM, Nome, Email, NEmprestimo as 'Empréstimo ativo' from aluno where Nome LIKE '%' @Nome '%' ORDER BY Nome;", connection);
                cmd.Parameters.AddWithValue("@Nome", aluno.Nome);

                da.SelectCommand = cmd;
                da.Fill(dt);

                return(dt);
            }
            catch (Exception)
            {
                throw;
            }
        }