Пример #1
0
 public static bool Cadastrar(HistoricoAluno historicoaluno)
 {
     if (BuscarHistoricoAluno(historicoaluno) == null)
     {
         _context.HistoricoAlunos.Add(historicoaluno);
         _context.SaveChanges();
         return(true);
     }
     return(false);
 }
Пример #2
0
        public ActionResult Editar(long id)
        {
            HistoricoAluno historicoaluno = _banco.HistoricoAlunos.Find(id);

            ViewBag.DataHistoricoAluno = historicoaluno.DataHistoricoAluno.ToShortDateString();

            ViewBag.AlunoId = new SelectList(_banco.Alunos, "Id", "Nome", historicoaluno.AlunoId);

            return(View(historicoaluno));
        }
Пример #3
0
        private void btnAdicionar_Click(object sender, RoutedEventArgs e)
        {
            //if (cboNiveis.SelectedValue ?? null && cboAlunos.SelectedValue ?? null)
            //{
            //int idmentor = (int)cboNiveis.SelectedValue;
            //int iddisciplina = (int)cboAlunos.SelectedValue;
            //MessageBox.Show($"ID mentor: {id} - ID disciplina: {iddisc}");


            historicoaluno = new HistoricoAluno();
            Nivel n = new Nivel();
            Aluno a = new Aluno();

            //colocar throw exception aqui para quando nao vir informado dados na combobox
            n.Id = (int)cboNiveis.SelectedValue;
            a.Id = (int)cboAlunos.SelectedValue;

            n = NivelDAO.BuscarNivelPorId(n.Id);
            if (n != null)
            {
                historicoaluno.Nivel = n;
                a = AlunoDAO.BuscarAlunoPorId(a.Id);

                if (a != null)
                {
                    historicoaluno.Aluno = a;
                    if (HistoricoAlunoDAO.Cadastrar(historicoaluno))
                    {
                        MessageBox.Show("Atrelamento realizado com sucesso!", "Matricula WPF",
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                        LimparFormulario();
                    }
                    else
                    {
                        MessageBox.Show("Atrelamento já existente!", "Matricula WPF",
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                        LimparFormulario();
                    }
                }
                else
                {
                    MessageBox.Show("Aluno não localizado", "Matricula WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    LimparFormulario();
                }
            }
            else
            {
                MessageBox.Show("Nivel não localizado!", "Matricula WPF",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                LimparFormulario();
            }
        }
Пример #4
0
        public ActionResult Adicionar(HistoricoAluno novoHistoricoAluno)
        {
            if (ModelState.IsValid)
            {
                _banco.HistoricoAlunos.Add(novoHistoricoAluno);
                _banco.SaveChanges();
                return(RedirectToAction("ListaHistoricoAluno", new { Id = novoHistoricoAluno.AlunoId }));
            }
            ViewBag.AlunoId = new SelectList(_banco.Alunos, "Id", "Nome", novoHistoricoAluno.AlunoId);

            return(View(novoHistoricoAluno));
        }//fim adicionar
Пример #5
0
        public ActionResult Editar(HistoricoAluno historicoAluno)
        {
            if (ModelState.IsValid)
            {
                _banco.Entry(historicoAluno).State = EntityState.Modified;
                _banco.SaveChanges();
                return(RedirectToAction("ListaHistoricoAluno", new { Id = historicoAluno.AlunoId }));
            }
            ViewBag.AlunoId = new SelectList(_banco.Alunos, "Id", "Nome", historicoAluno.AlunoId);

            return(View(historicoAluno));
        }
Пример #6
0
 public static HistoricoAluno BuscarHistoricoAluno(HistoricoAluno historicoaluno) => _context.HistoricoAlunos.Where(ha => ha.Nivel == historicoaluno.Nivel && ha.Aluno == historicoaluno.Aluno)
 .FirstOrDefault();
Пример #7
0
        public ActionResult GerarHistoricoAluno(long id)
        {
            var aluno = _banco.Matriculas.FirstOrDefault(x => x.Aluno.Id == id);

            HistoricoAluno historico = new HistoricoAluno();

            if (aluno != null)
            {
                historico.AlunoId              = aluno.AlunoId;
                historico.DataHistoricoAluno   = DateTime.Now.Date;
                historico.AnoHistoricoAluno    = Convert.ToInt32(aluno.AnoLetivo.Ano);
                historico.ChCurricularBasica   = Convert.ToString(aluno.AnoLetivo.ChCurrBas, CultureInfo.InvariantCulture);
                historico.ChCurricularArtes    = Convert.ToString(aluno.AnoLetivo.ChCurrArt, CultureInfo.InvariantCulture);
                historico.TurmaAnoHistorico    = aluno.Turma.Serie;
                historico.EscolaAnoAluno       = aluno.Turma.Escola.NomeEscola;
                historico.CidadeEscolaAnoAluno = aluno.Turma.Escola.EndEscola;
                historico.UfEscolaAnoAluno     = aluno.Turma.Escola.UfEscola;
            }
            historico.DiasLetivos = 200;


            var conceitos = (from con in _banco.Conceitos
                             where con.Matricula.AlunoId == id
                             select con).ToArray();

            foreach (var con in conceitos)
            {
                switch (con.Disciplina.Id)
                {
                case 1:
                    historico.AprovMatematica = con.Conceito4Bim;
                    break;

                case 2:
                    historico.AprovPortugues = con.Conceito4Bim;
                    break;

                case 3:
                    historico.AprovArte = con.Conceito4Bim;
                    break;

                case 4:
                    historico.AprovEduFisica = con.Conceito4Bim;
                    break;

                case 5:
                    historico.AprovHistoria = con.Conceito4Bim;
                    break;

                case 6:
                    historico.AprovGeografia = con.Conceito4Bim;
                    break;

                case 7:
                    historico.AprovEnsReligioso = con.Conceito4Bim;
                    break;

                case 8:
                    historico.AprovCiencia = con.Conceito4Bim;
                    break;

                case 9:
                    historico.AprovInformatica = con.Conceito4Bim;
                    break;

                case 10:
                    historico.AprovLitInfantilJuvenil = con.Conceito4Bim;
                    break;
                }
            }
            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges
                if (ModelState.IsValid)
                {
                    _banco.HistoricoAlunos.Add(historico);
                    _banco.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }

            //if (ModelState.IsValid)
            //{
            //    _banco.HistoricoAlunos.Add(historico);
            //    _banco.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            return(RedirectToAction("Index"));
        }