public async Task <GridResult> ObterDadosGrid(GridRequest request = null) { var result = new GridResult(); if (request == null) { result.Total = await _alunoRepository.CountAsync(); result.Data = (await _alunoRepository.GetAllAsync()) .Select(x => new { x.Id, x.Matricula, x.Usuario.Nome, x.Usuario.SobreNome, x.Usuario.Telefone, x.Usuario.Email }); return(result); } var data = string.IsNullOrWhiteSpace(request.Search) ? await _alunoRepository.GetAllAsync() : await _alunoRepository.SearchAsync(x => x.Matricula.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 || x.Usuario.Nome.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 || x.Usuario.SobreNome.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 || x.Usuario.Email.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0 || x.Usuario.Telefone.IndexOf(request.Search, StringComparison.OrdinalIgnoreCase) >= 0); result.Total = data.Count(); if (!string.IsNullOrWhiteSpace(request.OrderBy)) { if (request.Direction == Direction.Descendent) { data = request.OrderBy == "matricula" ? data.OrderByDescending(x => x.Matricula) : request.OrderBy == "nome" ? data.OrderByDescending(x => x.Usuario.Nome) : request.OrderBy == "email" ? data.OrderByDescending(x => x.Usuario.Email) : request.OrderBy == "telefone" ? data.OrderByDescending(x => x.Usuario.Telefone) : request.OrderBy == "sobreNome" ? data.OrderByDescending(x => x.Usuario.SobreNome) : data; } else { data = request.OrderBy == "matricula" ? data.OrderBy(x => x.Matricula) : request.OrderBy == "nome" ? data.OrderBy(x => x.Usuario.Nome) : request.OrderBy == "email" ? data.OrderBy(x => x.Usuario.Email) : request.OrderBy == "telefone" ? data.OrderBy(x => x.Usuario.Telefone) : request.OrderBy == "sobreNome" ? data.OrderBy(x => x.Usuario.SobreNome) : data; } } if (request.PageSize > 0 && request.Page > 0) { data = data.Skip((request.Page - 1) * request.PageSize).Take(request.Page * request.PageSize); } result.Data = data.Select(x => new { x.Id, x.Matricula, x.Usuario.Nome, x.Usuario.SobreNome, x.Usuario.Telefone, x.Usuario.Email }); return(result); }
public async Task <ActionResult <List <Aluno> > > GetTodosAlunos() { return(Ok(_alunoViewModel .ConverterListModelParaViewModel(await _alunoRepository.GetAllAsync()))); }