Пример #1
0
        public async Task <IActionResult> Renew(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var professorToUpdate = await _context.Professores.FirstOrDefaultAsync(s => s.Id == id);

            professorToUpdate.Faixa = _context.FaixasProfessores.Where(o => o.IdProfessor == id).Distinct().ToList();

            if (professorToUpdate != null)
            {
                professorToUpdate.DataVencimentoCBJ = DateTime.Now.AddYears(1);
                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                return(NotFound());
            }

            return(View(professorToUpdate));
        }
Пример #2
0
        // GET: Alunos/Promote/5
        public async Task <IActionResult> Promote(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Aluno aluno = await _context.Alunos
                          .Include(s => s.Faixa)
                          .Include(d => d.Faixa)
                          .AsNoTracking()
                          .FirstOrDefaultAsync(m => m.Id == id);


            aluno.Faixa = _context.FaixasAlunos.Where(o => o.IdAluno == id).Distinct().ToList();

            Professor professor;

            if (aluno == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                // Replicando professor
                professor = new Professor
                {
                    Nome              = aluno.Nome,
                    CPF               = aluno.CPF,
                    Email             = aluno.Email,
                    DataNascimento    = aluno.DataNascimento,
                    Observacoes       = aluno.Observacoes,
                    Telefone1         = aluno.Telefone1,
                    Telefone2         = aluno.Telefone2,
                    RegistroCbj       = aluno.RegistroCbj,
                    DataVencimentoCBJ = aluno.DataVencimentoCBJ,
                    Numero            = aluno.Numero,
                    OrgaoExpedidor    = aluno.OrgaoExpedidor,
                    Bairro            = aluno.Bairro,
                    CEP               = aluno.CEP,
                    Cidade            = aluno.Cidade,
                    Estado            = aluno.Estado,
                    Rua               = aluno.Rua,
                    NumeroResidencia  = aluno.NumeroResidencia
                };
                _context.Professores.Add(professor);
                _context.SaveChanges();

                // Replicando faixas
                List <Models.Professor.Faixa> listaFaixas = new List <Models.Professor.Faixa>();
                if (aluno.Faixa != null)
                {
                    foreach (var faixa in aluno.Faixa)
                    {
                        listaFaixas.Add(new Models.Professor.Faixa
                        {
                            IdProfessor = _context.Professores.Single(s => s.Nome == aluno.Nome).Id,
                            Cor         = (Models.Professor.Faixa.Cores)faixa.Cor,
                            DataEntrega = faixa.DataEntrega,
                            Descricao   = faixa.Descricao
                        }
                                        );
                    }
                    foreach (var e in listaFaixas)
                    {
                        var faixaInDatabase = _context.FaixasProfessores.Where(
                            s => s.Professor.Id == e.IdProfessor).SingleOrDefault();
                        if (faixaInDatabase == null)
                        {
                            _context.FaixasProfessores.Add(e);
                        }
                    }
                }
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
            return(View(aluno));
        }