diff options
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Generic/DialogProspeccaoViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/Generic/DialogProspeccaoViewModel.cs | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Generic/DialogProspeccaoViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Generic/DialogProspeccaoViewModel.cs new file mode 100644 index 0000000..f95e6d6 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Generic/DialogProspeccaoViewModel.cs @@ -0,0 +1,352 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Gestor.Application.ViewModels.Generic
+{
+ public class DialogProspeccaoViewModel : BaseSegurosViewModel
+ {
+ private readonly ClienteServico _servico;
+
+ private Prospeccao _selectedProspeccao;
+
+ private bool _isVisibleAnexos;
+
+ private ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> _arquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>();
+
+ private Gestor.Model.Domain.Common.ArquivoDigital _selectedAnexado = new Gestor.Model.Domain.Common.ArquivoDigital();
+
+ private ObservableCollection<IndiceArquivoDigital> _arquivos = new ObservableCollection<IndiceArquivoDigital>();
+
+ private Visibility _visibilityStatusPersonalizado;
+
+ private ObservableCollection<Usuario> _usuarios;
+
+ private ObservableCollection<Vendedor> _vendedores;
+
+ private DateTime _dataAgendamento;
+
+ private DateTime _horaAgendamento;
+
+ private List<Produto> _produtos = Recursos.Produtos;
+
+ private ObservableCollection<StatusDeProspeccao> _statusProspeccao;
+
+ private List<Ramo> _ramos = Recursos.Ramos;
+
+ public ObservableCollection<IndiceArquivoDigital> Arquivos
+ {
+ get
+ {
+ return this._arquivos;
+ }
+ set
+ {
+ this._arquivos = value;
+ base.OnPropertyChanged("Arquivos");
+ }
+ }
+
+ public ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> ArquivosAnexados
+ {
+ get
+ {
+ return this._arquivosAnexados;
+ }
+ set
+ {
+ List<Gestor.Model.Domain.Common.ArquivoDigital> list;
+ this._arquivosAnexados = value;
+ base.OnPropertyChanged("ArquivosAnexados");
+ this.IsVisibleAnexos = (value != null ? value.Count > 0 : false);
+ Prospeccao selectedProspeccao = this.SelectedProspeccao;
+ if (value != null)
+ {
+ list = value.ToList<Gestor.Model.Domain.Common.ArquivoDigital>();
+ }
+ else
+ {
+ list = null;
+ }
+ selectedProspeccao.set_Anexos(list);
+ }
+ }
+
+ public DateTime DataAgendamento
+ {
+ get
+ {
+ return this._dataAgendamento;
+ }
+ set
+ {
+ this._dataAgendamento = value;
+ if (this.SelectedProspeccao.get_Tarefa() != null)
+ {
+ this.SelectedProspeccao.get_Tarefa().set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", value, this.SelectedProspeccao.get_Tarefa().get_Agendamento())));
+ }
+ base.OnPropertyChanged("DataAgendamento");
+ }
+ }
+
+ public DateTime HoraAgendamento
+ {
+ get
+ {
+ return this._horaAgendamento;
+ }
+ set
+ {
+ this._horaAgendamento = value;
+ if (this.SelectedProspeccao.get_Tarefa() != null)
+ {
+ this.SelectedProspeccao.get_Tarefa().set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", this.SelectedProspeccao.get_Tarefa().get_Agendamento(), value)));
+ }
+ base.OnPropertyChanged("HoraAgendamento");
+ }
+ }
+
+ public bool IsVisibleAnexos
+ {
+ get
+ {
+ return this._isVisibleAnexos;
+ }
+ set
+ {
+ this._isVisibleAnexos = value;
+ base.OnPropertyChanged("IsVisibleAnexos");
+ }
+ }
+
+ public List<Produto> Produtos
+ {
+ get
+ {
+ return this._produtos;
+ }
+ set
+ {
+ this._produtos = value;
+ base.OnPropertyChanged("Produtos");
+ }
+ }
+
+ public List<Ramo> Ramos
+ {
+ get
+ {
+ return this._ramos;
+ }
+ set
+ {
+ this._ramos = value;
+ base.OnPropertyChanged("Ramos");
+ }
+ }
+
+ public Gestor.Model.Domain.Common.ArquivoDigital SelectedAnexado
+ {
+ get
+ {
+ return this._selectedAnexado;
+ }
+ set
+ {
+ this._selectedAnexado = value;
+ base.OnPropertyChanged("SelectedAnexado");
+ }
+ }
+
+ public Prospeccao SelectedProspeccao
+ {
+ get
+ {
+ return this._selectedProspeccao;
+ }
+ set
+ {
+ this._selectedProspeccao = value;
+ base.OnPropertyChanged("SelectedProspeccao");
+ }
+ }
+
+ public ObservableCollection<StatusDeProspeccao> StatusProspeccao
+ {
+ get
+ {
+ return this._statusProspeccao;
+ }
+ set
+ {
+ this._statusProspeccao = value;
+ base.OnPropertyChanged("StatusProspeccao");
+ }
+ }
+
+ public ObservableCollection<Usuario> Usuarios
+ {
+ get
+ {
+ return this._usuarios;
+ }
+ set
+ {
+ this._usuarios = value;
+ base.OnPropertyChanged("Usuarios");
+ }
+ }
+
+ public ObservableCollection<Vendedor> Vendedores
+ {
+ get
+ {
+ return this._vendedores;
+ }
+ set
+ {
+ this._vendedores = value;
+ base.OnPropertyChanged("Vendedores");
+ }
+ }
+
+ public Visibility VisibilityStatusPersonalizado
+ {
+ get
+ {
+ return this._visibilityStatusPersonalizado;
+ }
+ set
+ {
+ this._visibilityStatusPersonalizado = value;
+ base.OnPropertyChanged("VisibilityStatusPersonalizado");
+ }
+ }
+
+ public DialogProspeccaoViewModel(Prospeccao prospeccao)
+ {
+ DateTime? vigenciaFinal;
+ DateTime? nullable;
+ DateTime? nullable1;
+ this._servico = new ClienteServico();
+ this.Usuarios = new ObservableCollection<Usuario>(Recursos.Usuarios.Where<Usuario>((Usuario x) => {
+ if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa())
+ {
+ return false;
+ }
+ return !x.get_Excluido();
+ }).OrderBy<Usuario, string>((Usuario x) => x.get_Nome()).ToList<Usuario>());
+ this.Vendedores = new ObservableCollection<Vendedor>(Recursos.Vendedores.Where<Vendedor>((Vendedor x) => {
+ if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa())
+ {
+ return false;
+ }
+ return x.get_Ativo();
+ }).OrderBy<Vendedor, string>((Vendedor x) => x.get_Nome()).ToList<Vendedor>());
+ this.StatusProspeccao = new ObservableCollection<StatusDeProspeccao>((
+ from x in Recursos.StatusProspeccao
+ where x.get_Ativo()
+ orderby x.get_Nome()
+ select x).ToList<StatusDeProspeccao>());
+ if (this.StatusProspeccao == null || this.StatusProspeccao.Count == 0)
+ {
+ this.VisibilityStatusPersonalizado = Visibility.Collapsed;
+ }
+ if (prospeccao.get_Vendedor() == null)
+ {
+ prospeccao.set_Vendedor(this.Vendedores.First<Vendedor>((Vendedor x) => x.get_Corretora()));
+ }
+ if (prospeccao.get_Tarefa() == null)
+ {
+ Prospeccao prospeccao1 = prospeccao;
+ Tarefa tarefa = new Tarefa();
+ tarefa.set_Titulo("PROSPECÇÃO");
+ tarefa.set_Entidade(5);
+ tarefa.set_IdEntidade(prospeccao.get_Id());
+ tarefa.set_Usuario(Recursos.Usuario);
+ vigenciaFinal = prospeccao.get_VigenciaFinal();
+ tarefa.set_Agendamento((vigenciaFinal.HasValue ? vigenciaFinal.GetValueOrDefault() : Funcoes.GetNetworkTime()));
+ tarefa.set_Cliente(prospeccao.get_Nome());
+ prospeccao1.set_Tarefa(tarefa);
+ }
+ this.SelectedProspeccao = prospeccao;
+ Tarefa tarefa1 = prospeccao.get_Tarefa();
+ if (tarefa1 != null)
+ {
+ nullable = new DateTime?(tarefa1.get_Agendamento());
+ }
+ else
+ {
+ vigenciaFinal = null;
+ nullable = vigenciaFinal;
+ }
+ vigenciaFinal = nullable;
+ this.DataAgendamento = vigenciaFinal.Value;
+ Tarefa tarefa2 = prospeccao.get_Tarefa();
+ if (tarefa2 != null)
+ {
+ nullable1 = new DateTime?(tarefa2.get_Agendamento());
+ }
+ else
+ {
+ vigenciaFinal = null;
+ nullable1 = vigenciaFinal;
+ }
+ vigenciaFinal = nullable1;
+ this.HoraAgendamento = vigenciaFinal.Value;
+ }
+
+ public async void Anexar()
+ {
+ ObservableCollection<IndiceArquivoDigital> arquivos = this.Arquivos;
+ List<Gestor.Model.Domain.Common.ArquivoDigital> list = arquivos.Select<IndiceArquivoDigital, Gestor.Model.Domain.Common.ArquivoDigital>((IndiceArquivoDigital x) => {
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = new Gestor.Model.Domain.Common.ArquivoDigital();
+ arquivoDigital.set_Descricao(x.get_Descricao());
+ arquivoDigital.set_Extensao(x.get_Extensao());
+ return arquivoDigital;
+ }).ToList<Gestor.Model.Domain.Common.ArquivoDigital>();
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals = await base.AddAttachments(this.ArquivosAnexados.ToList<Gestor.Model.Domain.Common.ArquivoDigital>(), list);
+ if (arquivoDigitals != null)
+ {
+ arquivoDigitals.AddRange(this.ArquivosAnexados);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(arquivoDigitals);
+ }
+ }
+
+ public async Task<Cliente> BuscarInfoCliente(Cliente cliente)
+ {
+ cliente = await this._servico.BuscarCliente(cliente.get_Id());
+ Cliente cliente1 = cliente;
+ ObservableCollection<ClienteTelefone> observableCollection = await this._servico.BuscarTelefonesAsync(cliente.get_Id());
+ cliente1.set_Telefones(observableCollection);
+ cliente1 = null;
+ cliente1 = cliente;
+ ObservableCollection<ClienteEmail> observableCollection1 = await this._servico.BuscarEmailsAsync(cliente.get_Id());
+ cliente1.set_Emails(observableCollection1);
+ cliente1 = null;
+ return cliente;
+ }
+
+ public void Delete(Gestor.Model.Domain.Common.ArquivoDigital arquivo)
+ {
+ if (this.SelectedAnexado == null)
+ {
+ return;
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = this.ArquivosAnexados.First<Gestor.Model.Domain.Common.ArquivoDigital>((Gestor.Model.Domain.Common.ArquivoDigital x) => x.get_Descricao() == arquivo.get_Descricao());
+ this.ArquivosAnexados.Remove(arquivoDigital);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(this.ArquivosAnexados);
+ }
+ }
+}
\ No newline at end of file |