Esempio n. 1
0
        public ActionResult <List <ProfissionalViewModel> > GetAllPaginationProfissionalWithCBO([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.GetFiltro(fields, search);
                    }
                    else
                    {
                        string filtronum = string.Empty;
                        if (Helper.soContemNumeros(search))
                        {
                            filtronum = $@" CAST(MED.CSI_CODMED AS VARCHAR(20)) CONTAINING '{search}' OR";
                        }

                        filtro += $@" AND( {filtronum}
                                          MED.CSI_NOMMED CONTAINING '{search}')";
                    }
                }

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

                List <ProfissionalViewModel> lista = _profissionalRepository.GetAllPaginationProfissionalWithCBO(ibge, page, pagesize, filtro);
                Response.Headers.Add("X-Total-Count", count.ToString());
                return(Ok(lista));
            }
            catch (Exception ex)
            {
                var response = TrataErro.GetResponse(ex.Message, true);
                return(StatusCode((int)HttpStatusCode.InternalServerError, response));
            }
        }