public ModelCountViewModel <JogoViewModel> GetByFilter(FilterPaginacaoViewModel filter, Guid usuarioId) { if (!_repositoryUsuario.ExistsWithId(usuarioId)) { throw new ApiException(ApiErrorCodes.INVUSU); } Expression <Func <Jogo, bool> > _where = wh => wh.CreatorId == usuarioId; List <JogoViewModel> _jogos; if (!string.IsNullOrEmpty(filter.Nome)) { _where = _where.And(wh => wh.Nome.Contains(filter.Nome)); } _jogos = _mapper.Map <List <JogoViewModel> >( _repository.AdvancedFilter(_where, $"{ filter.SortBy} {filter.Descending()}", filter.Page, filter.ItemsPerPage)) .ToList(); return(new ModelCountViewModel <JogoViewModel> { Items = _jogos, Count = _repository.Query(_where) .Select(sel => sel.Id) .Count() }); }