// GET: Questao_Avaliacao/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var viewModel = new QuestaoIndexData();

            viewModel.Questao_Avaliacao = await _context.Questao_Avaliacao
                                          .Include(a => a.Avaliacao)
                                          .ThenInclude(a => a.Disci_Turma)
                                          .ThenInclude(a => a.Disciplina)
                                          .Include(a => a.Avaliacao)
                                          .ThenInclude(a => a.Disci_Turma)
                                          .ThenInclude(a => a.Professor)
                                          .Include(a => a.Questionario)
                                          .Where(a => a.Codigo == id).FirstOrDefaultAsync();

            var questionario = await _context.Questionario.ToListAsync();

            TempData["TotalQuestao"] = questionario.Count();

            if (viewModel.Questao_Avaliacao == null)
            {
                return(NotFound());
            }
            return(View(viewModel));
        }
        // GET: Questao_Avaliacao
        public async Task <IActionResult> Questao(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var viewModel = new QuestaoIndexData();

            viewModel.Avaliacao = await _context.Avaliacao
                                  .Include(a => a.Disci_Turma)
                                  .ThenInclude(m => m.Professor)
                                  .Include(a => a.Disci_Turma)
                                  .ThenInclude(m => m.Disciplina)
                                  .Where(a => a.Codigo == id).FirstAsync();

            var questionario = await _context.Questionario.ToListAsync();

            TempData["TotalQuestao"] = questionario.Count();
            foreach (var item in questionario)
            {
                var questao = _context.Questao_Avaliacao
                              .Where(a => a.AvaliacaoId == id)
                              .Where(a => a.QuestionarioId == item.Codigo);
                if (questao.Any())
                {
                    continue;
                }
                viewModel.Questionario = item;
                return(View(viewModel));
            }
            var avaliacao = viewModel.Avaliacao;

            avaliacao.Finalizado = true;
            if (avaliacao.Codigo > 0)
            {
                try
                {
                    _context.Update(avaliacao);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_context.Avaliacao.Any(a => a.Codigo == avaliacao.Codigo))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction(nameof(Finalizado), new { id = viewModel.Avaliacao.Codigo }));
        }