public List <UsuarioDTO> FindUsuarios <KProperty>(string texto, Expression <Func <Usuario, KProperty> > orderByExpression, bool ascending = true) { try { var spec = UsuarioSpecifications.ConsultaTexto(texto); List <Usuario> usuarios = _usuarioRepository.AllMatching <KProperty>(spec, orderByExpression, ascending).ToList(); var adapter = TypeAdapterFactory.CreateAdapter(); return(adapter.Adapt <List <Usuario>, List <UsuarioDTO> >(usuarios)); } catch (ApplicationValidationErrorsException ex) { throw ex; } catch (Exception ex) { LoggerFactory.CreateLog().LogError(ex); throw new Exception("O servidor não respondeu."); } }
public UsuarioDTO FindUsuario(string nomeUsuario) { try { if (string.IsNullOrWhiteSpace(nomeUsuario)) { throw new AppException("Informe o nome de usuário."); } var spec = UsuarioSpecifications.ConsultaNomeUsuario(nomeUsuario); var usuario = _usuarioRepository.AllMatching(spec).SingleOrDefault(); if (usuario == null) { throw new AppException("Usuário não encontrado."); } var adapter = TypeAdapterFactory.CreateAdapter(); return(adapter.Adapt <Usuario, UsuarioDTO>(usuario)); } catch (Exception ex) { throw ManipuladorDeExcecao.TrateExcecao(ex); } }