public List <TUsuarioVO> Listar(TUsuarioVO filtro) { try { if (filtro.IDUsuario > 0) { List <TUsuarioVO> listaRetorno = new List <TUsuarioVO>(); listaRetorno.Add(TUsuarioBLL.Obter(filtro.IDUsuario)); return(listaRetorno); } else { return(TUsuarioBLL.Listar(filtro).ToList()); } } catch (CABTECException) { throw new CABTECException("Erro ao Listar Usuário."); } catch (Exception) { throw new CABTECException("Erro ao Listar Usuário."); } }
public string AssociarColetorVendedor(string idColetorEscolhido, string idVendedorEscolhido) { try { string mensagem = string.Empty; //Dois IDs Nulos if (string.IsNullOrEmpty(idColetorEscolhido) && string.IsNullOrEmpty(idVendedorEscolhido)) { mensagem = "Não foi realizado a associação."; } if (!string.IsNullOrEmpty(idColetorEscolhido)) { TColetorVO coletorEscolhido = TColetorBLL.Obter(Convert.ToInt32(idColetorEscolhido)); //Limpar Associação if (string.IsNullOrEmpty(idVendedorEscolhido)) { coletorEscolhido.IDUsuarioResponsavel = 0; TColetorBLL.Alterar(coletorEscolhido); mensagem = "O Coletor: " + coletorEscolhido.NumeroSerie + " não está mais associado a nenhum Vendedor!"; } else { //Associar Coletor if (coletorEscolhido != null) { //Limpar Associação Antiga TColetorVO vendedorAntigo = TColetorBLL.ObterPorVendedor(coletorEscolhido.IDUsuarioResponsavel.GetValueOrDefault(0)); if (vendedorAntigo != null) { TUsuarioVO usuarioAntigo = TUsuarioBLL.Obter(vendedorAntigo.IDUsuarioResponsavel.Value); vendedorAntigo.IDUsuarioResponsavel = 0; TColetorBLL.Alterar(vendedorAntigo); mensagem = "O Vendedor: " + usuarioAntigo.Nome + " não está mais associado a nenhum Coletor!<br/>"; } //Limpar Associação Antiga TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido)); if (coletorAntigo != null) { TUsuarioVO usuarioAntigo = TUsuarioBLL.Obter(coletorAntigo.IDUsuarioResponsavel.Value); coletorAntigo.IDUsuarioResponsavel = 0; TColetorBLL.Alterar(coletorAntigo); mensagem = "O Coletor: " + coletorAntigo.NumeroSerie + " não está mais associado a nenhum Vendedor!<br/>"; } coletorEscolhido.IDUsuarioResponsavel = Convert.ToInt32(idVendedorEscolhido); TColetorBLL.Alterar(coletorEscolhido); TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido)); if (usuarioAtual != null) { mensagem += "O Coletor: " + coletorEscolhido.NumeroSerie + " e o Vendedor: " + usuarioAtual.Nome + " foram associados com sucesso!"; } } else { TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido)); if (usuarioAtual != null) { TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido)); if (coletorAntigo != null) { coletorAntigo.IDUsuarioResponsavel = 0; TColetorBLL.Alterar(coletorAntigo); } mensagem = "O Vendedor: " + usuarioAtual.Nome + " não está mais associado a nenhum Coletor!"; } } } } else { TColetorVO coletorAntigo = TColetorBLL.ObterPorVendedor(Convert.ToInt32(idVendedorEscolhido)); if (coletorAntigo != null) { coletorAntigo.IDUsuarioResponsavel = 0; TColetorBLL.Alterar(coletorAntigo); TUsuarioVO usuarioAtual = TUsuarioBLL.Obter(Convert.ToInt32(idVendedorEscolhido)); if (usuarioAtual != null) { mensagem = "O Vendedor: " + usuarioAtual.Nome + " não está mais associado a nenhum Coletor!"; } } } return(mensagem); } catch (CABTECException) { throw new CABTECException("Erro ao Associar Coletor e Vendedor."); } catch (Exception) { throw new CABTECException("Erro ao Associar Coletor e Vendedor."); } }