コード例 #1
0
 public void ValidarPesquisa(FiltroClienteDto filtro)
 {
     if (ClienteValidar.ValidarPesquisa(filtro))
     {
         throw new ArgumentException("Filtro de pesquisa inválido.");
     }
 }
コード例 #2
0
        public async Task <List <ClienteDto> > Pesquisar(FiltroClienteDto filtro)
        {
            this.ValidarPesquisa(filtro);

            Expression <Func <Cliente, bool> > where = f => true;
            if (!string.IsNullOrEmpty(filtro.Nome))
            {
                where = Util.ExpressionCombiner.And <Cliente>(where, c => c.NomCliente.Contains(filtro.Nome));
            }
            if (!string.IsNullOrEmpty(filtro.CodTipoPessoa?.ToString()))
            {
                byte codTipo = Convert.ToByte(filtro.CodTipoPessoa);
                where = Util.ExpressionCombiner.And <Cliente>(where, c => c.TipoPessoa == filtro.CodTipoPessoa || filtro.CodTipoPessoa == 0);
            }
            if (!string.IsNullOrEmpty(filtro.NumDocumento))
            {
                filtro.NumDocumento = filtro.NumDocumento.PadLeft(filtro.CodTipoPessoa == 1 ? 11 : 14, '0');
                where = Util.ExpressionCombiner.And <Cliente>(where, c => c.NumDocumento == filtro.NumDocumento);
            }

            List <Cliente> cliente = await _repositorio.Listar(where);

            List <ClienteDto> clienteDto = _map.Map <List <ClienteDto> >(cliente);

            return(clienteDto);
        }
コード例 #3
0
        public static bool ValidarPesquisa(FiltroClienteDto filtro)
        {
            bool _retorno = false;

            _retorno = filtro switch
            {
                _ when string.IsNullOrEmpty(filtro.Nome) && string.IsNullOrEmpty(filtro.NumDocumento) => _retorno = true,
                _ when !string.IsNullOrEmpty(filtro.NumDocumento) && !filtro.NumDocumento.IsNumeric() => _retorno = true,
                _ when filtro.CodTipoPessoa == null || !filtro.CodTipoPessoa.ToString().IsNumeric() => _retorno   = true,

                _ => false
            };

            return(_retorno);
        }
    }
コード例 #4
0
        public async Task <IActionResult> Pesquisar(FiltroClienteDto filtro)
        {
            try
            {
                List <ClienteDto> cliente = await _servico.Pesquisar(filtro);

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