public ActionResult <List <Visita> > GetAllPagination([FromHeader] string ibge, int page, int pagesize, string search, string fields, DateTime?datainicial, DateTime?datafinal, string num_ciclo) { try { ibge = _config.GetConnectionString(Connection.GetConnection(ibge)); string filtro = string.Empty; if (datainicial != null) { filtro += $@" AND CAST(DATA_HORA_ENTRADA AS DATE) >= '{datainicial?.ToString("dd.MM.yyyy")}'"; } if (datafinal != null) { filtro += $@" AND CAST(DATA_HORA_ENTRADA AS DATE) <= '{datafinal?.ToString("dd.MM.yyyy")}'"; } if (!string.IsNullOrWhiteSpace(num_ciclo)) { filtro += $@" AND EC.NUM_CICLO = '{num_ciclo}'"; } if (!string.IsNullOrWhiteSpace(search)) { if (fields != null && fields.Split(",").Length > 0 && fields.Split(",")[0] != null) { filtro += Helper.GetFiltro(fields, search); } else { filtro += $@" AND (I.QUARTEIRAO_LOGRADOURO = '{search}' OR B.CSI_NOMBAI CONTAINING '{search}' OR I.NOME_FANTASIA_APELIDO CONTAINING '{search}' OR I.RAZAO_SOCIAL_NOME CONTAINING '{search}')"; } } int count = _repository.GetCountAll(ibge, filtro); if (count == 1) { page = 0; } else { page = page * pagesize; } Response.Headers.Add("X-Total-Count", count.ToString()); List <Visita> lista = _repository.GetAllPagination(ibge, page, pagesize, filtro).ToList(); return(Ok(lista)); } catch (Exception ex) { var response = TrataErro.GetResponse(ex.Message, true); return(StatusCode((int)HttpStatusCode.InternalServerError, response)); } }