private async Task RetornaPerguntasDoRelatorio(filtrosRelatorioDTO filtro, RelatorioMatematicaPorTurmaDTO relatorio) { relatorio.Perguntas = new List <PerguntasRelatorioDTO>(); using (var contexto = new SMEManagementContextData()) { var perguntasBanco = await contexto.PerguntaAnoEscolar.Include(x => x.Pergunta).Where(perguntaAnoEscolar => perguntaAnoEscolar.AnoEscolar == filtro.AnoEscolar).OrderBy(x => x.Ordenacao).Select(x => MapearPergunta(x)).ToListAsync(); relatorio.Perguntas = perguntasBanco.Select(x => new PerguntasRelatorioDTO { Id = x.Id, Nome = x.Descricao }).ToList(); } }
public async Task <RelatorioMatematicaPorTurmaDTO> ObterRelatorioPorTurma(filtrosRelatorioDTO filtro) { IncluiIdDoComponenteCurricularEhDoPeriodoNoFiltro(filtro); var periodos = await ConsultaTotalDeAlunos.BuscaDatasPeriodoFixoAnual(filtro); if (periodos.Count() == 0) { throw new Exception("Periodo fixo anual nao encontrado"); } var endpoits = new EndpointsAPI(); var alunoApi = new AlunosAPI(endpoits); var alunosEol = await alunoApi.ObterAlunosAtivosPorTurmaEPeriodo(filtro.CodigoTurmaEol, periodos.First().DataFim); var QueryAlunosRespostas = ConsultasRelatorios.QueryRelatorioPorTurmaMatematica(); var listaAlunoRespostas = await RetornaListaRespostasAlunoPorTurma(filtro, QueryAlunosRespostas); var AlunosAgrupados = listaAlunoRespostas.GroupBy(x => x.CodigoAluno); var relatorio = new RelatorioMatematicaPorTurmaDTO(); await RetornaPerguntasDoRelatorio(filtro, relatorio); var ListaAlunos = new List <AlunoPorTurmaRelatorioDTO>(); alunosEol.ForEach(alunoRetorno => { var aluno = new AlunoPorTurmaRelatorioDTO(); aluno.CodigoAluno = alunoRetorno.CodigoAluno; aluno.NomeAluno = alunoRetorno.NomeAlunoRelatorio; aluno.Perguntas = new List <PerguntaRespostaPorAluno>(); var alunoRespostas = AlunosAgrupados.Where(x => x.Key == aluno.CodigoAluno.ToString()).ToList(); foreach (var perguntaBanco in relatorio.Perguntas) { var pergunta = new PerguntaRespostaPorAluno() { Id = perguntaBanco.Id, Valor = string.Empty }; var respostaAluno = listaAlunoRespostas.Where(x => x.PerguntaId == perguntaBanco.Id && x.CodigoAluno == aluno.CodigoAluno.ToString()).FirstOrDefault(); if (respostaAluno != null) { pergunta.Valor = respostaAluno.RespostaDescricao; } aluno.Perguntas.Add(pergunta); } ListaAlunos.Add(aluno); }); relatorio.Alunos = ListaAlunos.OrderBy(aluno => aluno.NomeAluno); relatorio.Graficos = new List <GraficosRelatorioDTO>(); using (var contexto = new SMEManagementContextData()) { var perguntasBanco = await contexto.PerguntaResposta.Include(x => x.Pergunta).Include(y => y.Resposta).Where(pr => relatorio.Perguntas.Any(p => p.Id == pr.Pergunta.Id)).ToListAsync(); foreach (var pergunta in relatorio.Perguntas) { var grafico = new GraficosRelatorioDTO(); grafico.nomeGrafico = pergunta.Nome; grafico.Barras = new List <BarrasGraficoDTO>(); var listaRespostas = perguntasBanco.Where(x => x.Pergunta.Id == pergunta.Id).ToList(); listaRespostas.ForEach(resposta => { var barra = new BarrasGraficoDTO(); barra.label = resposta.Resposta.Descricao; barra.value = relatorio.Alunos.Count(x => x.Perguntas.Any(r => r.Id == pergunta.Id && r.Valor == resposta.Resposta.Descricao)); grafico.Barras.Add(barra); }); var barraAlunosSemPreenchimento = new BarrasGraficoDTO(); barraAlunosSemPreenchimento.label = "Sem Preenchimento"; barraAlunosSemPreenchimento.value = relatorio.Alunos.Count() - grafico.Barras.Sum(x => x.value); grafico.Barras.Add(barraAlunosSemPreenchimento); relatorio.Graficos.Add(grafico); } } return(relatorio); }