public void Excluir(int IDAgendamento)
 {
     try
     {
         TAgendamentoBLL.Excluir(IDAgendamento);
     }
     catch (CABTECException)
     {
         throw new CABTECException("Erro ao Excluir Agendamento.");
     }
     catch (Exception)
     {
         throw new CABTECException("Erro ao Excluir Coletor.");
     }
 }
        public Int32 SalvarVendedor(TAgendamentoVO tagendamentovo)
        {
            try
            {
                int IDBairro      = 0;
                int IDCidade      = 0;
                int IDFilial      = 0;
                int IDAtendimento = 0;

                TUsuarioVO vendedor = new TUsuarioVO();
                vendedor = TUsuarioBLL.Obter(tagendamentovo.IDUsuarioVendedor.Value);

                IDBairro      = TBairroBLL.ObterIDBairro(tagendamentovo.Bairro);
                IDCidade      = TCidadeBLL.ObterIDCidade(tagendamentovo.Cidade);
                IDFilial      = TFilialBLL.ObterIDFilial(vendedor.Unidade);
                IDAtendimento = TAtendimentoBLL.ObterAtendimento(IDFilial, IDCidade, IDBairro);

                if (IDAtendimento == 0)
                {
                    IDAtendimento = TAtendimentoBLL.ObterAtendimentoFilial(IDFilial);
                }

                if (tagendamentovo.IDAgendamento > 0)
                {
                    TAgendamentoBLL.Alterar(tagendamentovo);
                }
                else
                {
                    TAgendamentoBLL.Inserir(tagendamentovo);
                }

                return(tagendamentovo.IDAgendamento);
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
            catch (Exception)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
        }
        public Int32 SalvarCallCenter(TAgendamentoVO tagendamentovo)
        {
            try
            {
                int IDBairro      = 0;
                int IDCidade      = 0;
                int IDAtendimento = 0;

                tagendamentovo.IDUsuarioVendedor = null;

                IDBairro      = TBairroBLL.ObterIDBairro(tagendamentovo.Bairro);
                IDCidade      = TCidadeBLL.ObterIDCidade(tagendamentovo.Cidade);
                IDAtendimento = TAtendimentoBLL.ObterAtendimentoCallCenter(IDCidade, IDBairro);

                if (IDAtendimento == 0)
                {
                    IDAtendimento = TAtendimentoBLL.ObterAtendimentoFilial(TFilialBLL.ObterIDFilial(WebConfigurationManager.AppSettings["WebMATRIZ"]));
                }

                tagendamentovo.IDAtendimento = IDAtendimento;

                if (tagendamentovo.IDAgendamento > 0)
                {
                    TAgendamentoBLL.Alterar(tagendamentovo);
                }
                else
                {
                    TAgendamentoBLL.Inserir(tagendamentovo);
                }

                return(tagendamentovo.IDAgendamento);
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
            catch (Exception)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
        }
 public void SalvarConsultaVendedor(List <int> idsAgendamentos, List <int> idsVendedores)
 {
     try
     {
         for (int i = 0; i < idsAgendamentos.Count; i++)
         {
             TAgendamentoVO agendamentoVO = new TAgendamentoVO();
             agendamentoVO = TAgendamentoBLL.Obter(idsAgendamentos[i]);
             agendamentoVO.IDUsuarioVendedor = idsVendedores[i];
             TAgendamentoBLL.Alterar(agendamentoVO);
         }
     }
     catch (CABTECException)
     {
         throw new CABTECException("Erro ao Salvar Agendamento/Vendedor.");
     }
     catch (Exception)
     {
         throw new CABTECException("Erro ao Salvar Agendamento/Vendedor.");
     }
 }
        public Int32 SalvarAdministrador(TAgendamentoVO tagendamentovo)
        {
            try
            {
                if (tagendamentovo.IDAgendamento > 0)
                {
                    TAgendamentoBLL.Alterar(tagendamentovo);
                }
                else
                {
                    TAgendamentoBLL.Inserir(tagendamentovo);
                }

                return(tagendamentovo.IDAgendamento);
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
            catch (Exception)
            {
                throw new CABTECException("Erro ao Salvar Agendamento.");
            }
        }
        public List <TAgendamentoVO> Listar(TAgendamentoVO filtro)
        {
            try
            {
                if (filtro.IDAgendamento > 0)
                {
                    List <TAgendamentoVO> listaRetorno = new List <TAgendamentoVO>();
                    TAgendamentoVO        retornoVO    = TAgendamentoBLL.Obter(filtro.IDAgendamento);

                    if (retornoVO.IDUsuarioAgendamento > 0)
                    {
                        retornoVO.NomeUsuarioAgendamento = TUsuarioBLL.Obter(retornoVO.IDUsuarioAgendamento).Nome;
                    }

                    if (retornoVO.IDUsuarioVendedor.HasValue)
                    {
                        if (retornoVO.IDUsuarioVendedor.Value > 0)
                        {
                            retornoVO.NomeUsuarioVendedor = TUsuarioBLL.Obter(retornoVO.IDUsuarioVendedor.Value).Nome;
                        }
                    }


                    listaRetorno.Add(retornoVO);
                    return(listaRetorno);
                }
                else
                {
                    List <int> usuarioAtendente = new List <int>();

                    List <int> usuarioVendedor = new List <int>();

                    List <int> usuarioUnidade = new List <int>();

                    if (!string.IsNullOrEmpty(filtro.NomeUsuarioAgendamento))
                    {
                        usuarioAtendente = TUsuarioBLL.ListarUsuarioAgendamento(filtro.NomeUsuarioAgendamento).ToList();
                        if (usuarioAtendente.Count == 0)
                        {
                            usuarioAtendente.Add(0);
                        }
                    }

                    if (!string.IsNullOrEmpty(filtro.NomeUsuarioVendedor))
                    {
                        usuarioVendedor = TUsuarioBLL.ListarUsuarioAgendamento(filtro.NomeUsuarioVendedor).ToList();
                        if (usuarioVendedor.Count == 0)
                        {
                            usuarioVendedor.Add(0);
                        }
                    }

                    if (!string.IsNullOrEmpty(filtro.Unidade))
                    {
                        usuarioUnidade = TAtendimentoBLL.ListarAtendimentoFilial(filtro.Unidade);
                        if (usuarioUnidade.Count == 0)
                        {
                            usuarioUnidade.Add(0);
                        }
                    }

                    return(TAgendamentoBLL.ListarGridConsulta(usuarioUnidade, usuarioAtendente, usuarioVendedor).ToList());
                }
            }
            catch (CABTECException)
            {
                throw new CABTECException("Erro ao Listar Agendamento.");
            }
            catch (Exception ex)
            {
                throw new CABTECException("Erro ao Listar Agendamento." + ex.Message);
            }
        }