Exemple #1
0
        public ActionResult <List <CidadaoFamiliaViewModel> > GetIndividuosToFamilia([FromHeader] string ibge, int page, int pagesize, string search, string fields)
        {
            try
            {
                ibge = _config.GetConnectionString(Connection.GetConnection(ibge));
                string filtro = string.Empty;

                if (!string.IsNullOrWhiteSpace(search))
                {
                    if (fields != null && fields.Split(",").Length > 0 && fields.Split(",")[0] != null)
                    {
                        filtro += Helper.GetFiltroInicial(fields, search);
                    }
                    else
                    {
                        var stringcod = string.Empty;
                        if (Helper.soContemNumeros(search))
                        {
                            stringcod = $" csi_codpac = {search} OR ";
                        }

                        filtro += $@" WHERE ( {stringcod}
                                             (SELECT UPPER(RETORNO) FROM TIRA_ACENTOS(C.CSI_NOMPAC)) LIKE '%{Helper.RemoveAcentos(search.ToUpper())}%')";
                    }
                }

                int count = _cidadaoRepository.GetCountIndividuosToFamilia(ibge, filtro);
                if (count == 1)
                {
                    page = 0;
                }
                else
                {
                    page = page * pagesize;
                }

                Response.Headers.Add("X-Total-Count", count.ToString());
                List <CidadaoFamiliaViewModel> lista = _cidadaoRepository.GetIndividuosToFamilia(ibge, page, pagesize, filtro);

                return(Ok(lista));
            }
            catch (Exception ex)
            {
                var response = TrataErro.GetResponse(ex.Message, true);
                return(StatusCode((int)HttpStatusCode.InternalServerError, response));
            }
        }