Esempio n. 1
0
        public async Task <List <CatalogoDto> > Pesquisar(FiltroCatalogoDto filtro)
        {
            this.ValidarPesquisa(filtro);

            Expression <Func <Catalogo, bool> > where = f => true;
            if (!string.IsNullOrEmpty(filtro.Titulo))
            {
                where = Util.ExpressionCombiner.And <Catalogo>(where, c => c.DesTitulo.Contains(filtro.Titulo));
            }
            if (!string.IsNullOrEmpty(filtro.IdGenero) && filtro.IdGenero != "0")
            {
                int idGenero = Convert.ToInt32(filtro.IdGenero);
                where = Util.ExpressionCombiner.And <Catalogo>(where, c => c.IdGenero == idGenero || idGenero == 0);
            }
            if (!string.IsNullOrEmpty(filtro.NomeAutor))
            {
                where = Util.ExpressionCombiner.And <Catalogo>(where, c => c.NomAutor.Contains(filtro.NomeAutor));
            }

            List <Catalogo> catalogo = await _repositorio.Listar(where);

            List <CatalogoDto> catalogoDto = _map.Map <List <CatalogoDto> >(catalogo);

            buscarGenero(catalogoDto);
            return(catalogoDto);
        }
Esempio n. 2
0
 public void ValidarPesquisa(FiltroCatalogoDto filtro)
 {
     if (CatalogoValidar.ValidarPesquisa(filtro))
     {
         throw new ArgumentException("Filtro de pesquisa inválido.");
     }
 }
Esempio n. 3
0
        public static bool ValidarPesquisa(FiltroCatalogoDto filtro)
        {
            bool _retorno = false;

            _retorno = filtro switch
            {
                _ when string.IsNullOrEmpty(filtro.NomeAutor) && string.IsNullOrEmpty(filtro.Titulo) &&
                !filtro.IdGenero.IsNumeric() => _retorno = true,
                _ when !string.IsNullOrEmpty(filtro.IdGenero) && !filtro.IdGenero.IsNumeric() => _retorno = true,
                _ => false
            };

            return(_retorno);
        }
    }
Esempio n. 4
0
        public async Task <IActionResult> Pesquisar(FiltroCatalogoDto filtro)
        {
            try
            {
                List <CatalogoDto> catalogo = await _servico.Pesquisar(filtro);

                if (catalogo.Count == 0)
                {
                    MessageResultData _resultado = MessageResult.Message(Constantes.Constantes.ALERTA, "Catalogos não encontrados.", MessageTypeEnum.warning);
                    return(Ok(_resultado));
                }
                return(Json(catalogo));
            }
            catch (Exception ex)
            {
                return(BadRequest(MessageResult.Mensagem(ex)));
            }
        }