Exemplo n.º 1
0
        public ModelCountViewModel <AmigoViewModel> GetByFilter(FilterPaginacaoViewModel filter, Guid usuarioId)
        {
            if (!_repositoryUsuario.ExistsWithId(usuarioId))
            {
                throw new ApiException(ApiErrorCodes.INVUSU);
            }

            Expression <Func <Amigo, bool> > _where = wh => wh.CreatorId == usuarioId;
            List <AmigoViewModel>            _amigos;

            if (!string.IsNullOrEmpty(filter.Nome))
            {
                _where = _where.And(wh => wh.Nome.Contains(filter.Nome));
            }

            _amigos = _mapper.Map <List <AmigoViewModel> >(
                _repository.AdvancedFilter(_where,
                                           $"{ filter.SortBy} {filter.Descending()}",
                                           filter.Page,
                                           filter.ItemsPerPage))
                      .ToList();

            return(new ModelCountViewModel <AmigoViewModel>
            {
                Items = _amigos,
                Count = _repository.Query(_where)
                        .Select(sel => sel.Id)
                        .Count()
            });
        }
Exemplo n.º 2
0
        public IActionResult GetByFilter([FromBody] FilterPaginacaoViewModel filter)
        {
            if (!Request.Headers.TryGetValue(ControllersConstants.UsuarioId, out StringValues uId) ||
                !Guid.TryParse(uId, out Guid usuarioId))
            {
                throw new ApiException(ApiErrorCodes.INVUSU);
            }

            ModelCountViewModel <JogoViewModel> _result = _service.GetByFilter(filter, usuarioId);

            return(Ok(_result));
        }