public ActionResult <List <ProfissionalViewModel> > GetFiltroAvancado([FromHeader] string ibge, [FromQuery] ParametersProfissional model) { try { ibge = _config.GetConnectionString(Connection.GetConnection(ibge)); string filtro = string.Empty; if (model.codigo != null) { filtro += $@" MED.CSI_CODMED = {model.codigo}"; } if (!string.IsNullOrWhiteSpace(model.nome) && !string.IsNullOrWhiteSpace(filtro)) { filtro += $@" AND MED.CSI_NOMMED CONTAINING '{model.nome}'"; } else if (!string.IsNullOrWhiteSpace(model.nome) && string.IsNullOrWhiteSpace(filtro)) { filtro += $@" MED.CSI_NOMMED CONTAINING '{model.nome}'"; } if (!string.IsNullOrWhiteSpace(model.cbo) && !string.IsNullOrWhiteSpace(filtro)) { filtro += $@" AND MED.CSI_CBO CONTAINING '{model.cbo}'"; } else if (!string.IsNullOrWhiteSpace(model.cbo) && string.IsNullOrWhiteSpace(filtro)) { filtro += $@" MED.CSI_CBO CONTAINING '{model.cbo}'"; } if (model.unidade != null && !string.IsNullOrWhiteSpace(filtro)) { filtro += $@" AND MED_UNI.CSI_CODUNI = {model.unidade}"; } else if (model.unidade != null && string.IsNullOrWhiteSpace(filtro)) { filtro += $@" MED_UNI.CSI_CODUNI = {model.unidade}"; } if (model.cpf != null && !string.IsNullOrWhiteSpace(filtro)) { filtro += $@" AND MED.CSI_CPF CONTAINING '{model.cpf}'"; } else if (model.cpf != null && string.IsNullOrWhiteSpace(filtro)) { filtro += $@" MED.CSI_CPF CONTAINING '{model.cpf}'"; } if (!string.IsNullOrWhiteSpace(filtro)) { filtro = $@" WHERE {filtro}"; } int count = _profissionalRepository.GetCountAll(ibge, filtro); if (count == 1) { model.page = 0; } else { model.page = model.page * model.pagesize; } Response.Headers.Add("X-Total-Count", count.ToString()); List <ProfissionalViewModel> lista = _profissionalRepository.GetAllPagination(ibge, (int)model.page, (int)model.pagesize, filtro); return(Ok(lista)); } catch (Exception ex) { var response = TrataErro.GetResponse(ex.Message, true); return(StatusCode((int)HttpStatusCode.InternalServerError, response)); } }