public IEnumerable <Aluno> FiltrarAlunos(AlunoFilter filter, bool paginar = false) { var query = IncludeTabela(); query = query.OrderBy(a => a.Nome); if (!string.IsNullOrEmpty(filter.Nome)) { query = query.Where(x => x.Nome.Contains(filter.Nome)); } if (!string.IsNullOrEmpty(filter.CPF)) { query = query.Where(x => x.CPF.Equals(filter.CPF)); } if (filter.DataMatriculaDe.HasValue) { query = query.Where(x => x.DataMatricula >= filter.DataMatriculaDe.Value); } if (filter.DataMatriculaAte.HasValue) { query = query.Where(x => x.DataMatricula <= filter.DataMatriculaAte.Value); } if (!string.IsNullOrEmpty(filter.CodigoTurma) || filter.CursoId.HasValue || !string.IsNullOrEmpty(filter.Matricula) || (filter.SituacaoId != null && filter.SituacaoId.Any())) { query = query.Where(x => x.TurmasAluno.Any(y => (string.IsNullOrEmpty(filter.CodigoTurma) || y.Turma.Codigo.Contains(filter.CodigoTurma)) && (!filter.CursoId.HasValue || y.Turma.CursoId == filter.CursoId) && (string.IsNullOrEmpty(filter.Matricula) || y.Matricula == filter.Matricula) && (filter.SituacaoId == null || !filter.SituacaoId.Any() || filter.SituacaoId.Contains(y.TipoStatusAlunoId)) )); } if (paginar) { filter.Total = query.Count(); return(PaginarResultado(query, filter).ToList()); } else { return(query.ToList()); } }
public FilterResultDTO <AlunoDTO> FiltrarAlunos(AlunoFilter filter) { try { IEnumerable <Aluno> alunos = alunoRepository.FiltrarAlunos(filter, true); var retorno = new FilterResultDTO <AlunoDTO> { Total = filter.Total, Pagina = filter.Pagina, TamanhoPagina = filter.TamanhoPagina, Lista = alunos.Select(x => new AlunoDTO(x)) }; return(retorno); } catch (Exception e) { log.Error("Erro ao buscar alunos.", e); throw new Exception("Erro ao buscar alunos."); } }
public byte[] ExportarPesquisa(AlunoFilter filter) { List <AlunoDTO> alunos = alunoRepository.FiltrarAlunos(filter).Select(x => new AlunoDTO(x)).ToList(); #region Criação da tabela Workbook conteudoExcel = new Workbook { FileName = "exportação.xlsx" }; conteudoExcel.Worksheets.RemoveAt(0); Worksheet sheet = conteudoExcel.Worksheets.Add("Alunos"); string[] propertyNames = { /* 00 */ "Nome", /* 01 */ "CPF", /* 02 */ "Telefone", /* 03 */ "Celular", /* 04 */ "Matrículas", /* 05 */ "Turmas", /* 06 */ "Matrícula", /* 07 */ "Validade", /* 08 */ "Situação" }; Aspose.Cells.Style styleDia = conteudoExcel.CreateStyle(); styleDia.Custom = "dd/mm/yyyy"; #endregion #region Preenchimento da tabela var contador = 1; alunos.ForEach(a => { try { var row = sheet.Cells.Rows[contador]; GravarValor(row, a.Nome, 0); GravarValor(row, a.CPF, 1); GravarValor(row, a.Telefone, 2); GravarValor(row, a.Celular, 3); GravarValor(row, string.Join(", ", a.TurmasAluno.Select(ta => ta.Matricula)), 4); GravarValor(row, string.Join(", ", a.TurmasAluno.Select(ta => ta.Turma.Codigo)), 5); GravarValor(row, a.DataMatricula, 6, styleDia); GravarValor(row, a.DataValidade, 7, styleDia); GravarValor(row, a.TipoStatusAluno, 8); contador++; } catch (Exception e) { log.Error($"Erro exportar pesquisa.", e); } }); sheet.ListObjects.Add(0, 0, contador - 1, propertyNames.Length - 1, true); var header = sheet.Cells.Rows[0]; for (int i = 0; i < propertyNames.Length; i++) { header[i].PutValue(propertyNames[i]); } sheet.AutoFitColumns(); sheet.AutoFitRows(); #endregion MemoryStream stream = new MemoryStream(); conteudoExcel.Save(stream, Aspose.Cells.SaveFormat.Xlsx); stream.Seek(0, SeekOrigin.Begin); return(stream.ToArray()); void GravarValor(Row row, object dado, int indice, Aspose.Cells.Style style = null) { if (dado == null) { dado = ""; } row[indice].PutValue(dado); if (style != null) { row[indice].SetStyle(style); } } }
public FilterResultDTO <AlunoDTO> FiltrarAlunos(AlunoFilter filter) { return(AlunoService.FiltrarAlunos(filter)); }
public byte[] BaixarPesquisa(AlunoFilter filter) { return(AlunoService.ExportarPesquisa(filter)); }
public FilterResultDTO <AlunoDTO> ListarAlunosPorVencimento(AlunoFilter filter) { return(AlunoService.ListarAlunosPorVencimento(filter)); }