using Gestor.Application.Helpers; using Gestor.Application.Servicos.Generic; using Gestor.Application.Servicos.Seguros; using Gestor.Application.Servicos.Seguros.Itens; using Gestor.Application.ViewModels.Generic; using Gestor.Common.Validation; using Gestor.Model.Common; using Gestor.Model.Domain.Configuracoes; 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.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; namespace Gestor.Application.ViewModels.Seguros { public class CriticaApoliceViewModel : BaseApoliceViewModel { private readonly CriticaApoliceServico _criticaServico; private readonly ClienteServico _clienteServico; private readonly ItemServico _itemServico; private List Vinculos; private ObservableCollection _usuarios = new ObservableCollection(); private ObservableCollection _seguradorasFiltro = new ObservableCollection(); private string _fieldNascimento = "NASCIMENTO"; private bool _isExpanded = true; private DateTime _inicio = Funcoes.GetNetworkTime().Date.AddDays(-7); private DateTime _fim = Funcoes.GetNetworkTime().Date; private Usuario _selectedUsuario; private Seguradora _selectedSeguradora; private bool _criticado; private ObservableCollection _criticas = new ObservableCollection(); private ObservableCollection _criticaFiltrada = new ObservableCollection(); private bool _isCriticaSelected; private CriticaApolice _selectedCritica; private bool _hasChange; private bool _isParcela; private DateTime? _emissaoCritica; private DateTime? _transmissaoCritica; private DateTime? _nascimentoCritica; private TipoSeguro? _situacao; private Cliente _selectedCliente; private string _documentoPrincipal; private Visibility _visibilityFisica = Visibility.Collapsed; private ObservableCollection _telefones = new ObservableCollection(); private ObservableCollection _emails = new ObservableCollection(); private ObservableCollection _itens = new ObservableCollection(); private bool _enableGrid = true; private string _pesquisa = ""; private ObservableCollection _pesquisaCritica = new ObservableCollection(); private string _profissaoText; private string _atividadeText; private Visibility _visibilityJuridica = Visibility.Collapsed; private string _fieldDocumento = "CPF"; private Visibility _valorComissao; public string AtividadeText { get { return this._atividadeText; } set { this._atividadeText = value; base.OnPropertyChanged("AtividadeText"); } } public bool BuscaInicial { get; set; } = true; public bool Criticado { get { return this._criticado; } set { this._criticado = value; base.OnPropertyChanged("Criticado"); } } public ObservableCollection CriticaFiltrada { get { return this._criticaFiltrada; } set { this._criticaFiltrada = value; base.OnPropertyChanged("CriticaFiltrada"); } } public ObservableCollection Criticas { get { return this._criticas; } set { this._criticas = value; base.OnPropertyChanged("Criticas"); } } public string DocumentoPrincipal { get { return this._documentoPrincipal; } set { if (value == null || ValidationHelper.OnlyNumber(value).Length > 11) { this.VisibilityFisica = Visibility.Collapsed; this.FieldNascimento = "FUNDAÇÃO"; } else { this.VisibilityFisica = Visibility.Visible; this.FieldNascimento = "NASCIMENTO"; } this._documentoPrincipal = value; if (this.SelectedCliente != null) { TipoDocumento? documentoPrincipal = this.SelectedCliente.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); if (valueOrDefault == 1) { this.SelectedCliente.set_Rne(value); base.OnPropertyChanged("DocumentoPrincipal"); return; } else { if (valueOrDefault != 2) { goto Label1; } this.SelectedCliente.set_Cei(value); base.OnPropertyChanged("DocumentoPrincipal"); return; } } Label1: this.SelectedCliente.set_Documento(value); } base.OnPropertyChanged("DocumentoPrincipal"); } } public ObservableCollection Emails { get { return this._emails; } set { this._emails = value; base.OnPropertyChanged("Emails"); } } public DateTime? EmissaoCritica { get { return this._emissaoCritica; } set { this._emissaoCritica = value; base.OnPropertyChanged("EmissaoCritica"); } } public bool EnableGrid { get { return this._enableGrid; } set { this._enableGrid = value; base.OnPropertyChanged("EnableGrid"); } } public string FieldDocumento { get { return this._fieldDocumento; } set { this._fieldDocumento = value; base.OnPropertyChanged("FieldDocumento"); } } public string FieldNascimento { get { return this._fieldNascimento; } set { this._fieldNascimento = value; base.OnPropertyChanged("FieldNascimento"); } } public DateTime Fim { get { return this._fim; } set { this._fim = value; base.OnPropertyChanged("Fim"); } } public bool HasChange { get { return this._hasChange; } set { this._hasChange = value; base.OnPropertyChanged("HasChange"); } } public int Index { get; set; } = -1; public DateTime Inicio { get { return this._inicio; } set { this._inicio = value; base.OnPropertyChanged("Inicio"); } } public bool IsCriticaSelected { get { return this._isCriticaSelected; } set { this._isCriticaSelected = value; base.OnPropertyChanged("IsCriticaSelected"); } } public bool IsExpanded { get { return this._isExpanded; } set { this._isExpanded = value; base.OnPropertyChanged("IsExpanded"); } } public bool IsLoading { get; set; } public bool IsParcela { get { return this._isParcela; } set { this._isParcela = value; base.OnPropertyChanged("IsParcela"); } } public ObservableCollection Itens { get { return this._itens; } set { this._itens = value; base.OnPropertyChanged("Itens"); } } public DateTime? NascimentoCritica { get { return this._nascimentoCritica; } set { this._nascimentoCritica = value; base.OnPropertyChanged("NascimentoCritica"); } } public string Pesquisa { get { return this._pesquisa; } set { this._pesquisa = value; base.OnPropertyChanged("Pesquisa"); } } public ObservableCollection PesquisaCritica { get { return this._pesquisaCritica; } set { this._pesquisaCritica = value; base.OnPropertyChanged("PesquisaCritica"); } } public string ProfissaoText { get { return this._profissaoText; } set { this._profissaoText = value; base.OnPropertyChanged("ProfissaoText"); } } public ObservableCollection SeguradorasFiltro { get { return this._seguradorasFiltro; } set { this._seguradorasFiltro = value; this.SelectedSeguradora = this.SelectedSeguradora ?? value.FirstOrDefault(); base.OnPropertyChanged("SeguradorasFiltro"); } } public bool SeguroCombinado { get; set; } public Cliente SelectedCliente { get { return this._selectedCliente; } set { this._selectedCliente = value; base.OnPropertyChanged("SelectedCliente"); } } public CriticaApolice SelectedCritica { get { return this._selectedCritica; } set { this._selectedCritica = value; this.IsCriticaSelected = value != null; base.OnPropertyChanged("SelectedCritica"); } } public Seguradora SelectedSeguradora { get { return this._selectedSeguradora; } set { this._selectedSeguradora = value; base.OnPropertyChanged("SelectedSeguradora"); } } public Usuario SelectedUsuario { get { return this._selectedUsuario; } set { this._selectedUsuario = value; base.OnPropertyChanged("SelectedUsuario"); } } public TipoSeguro? StatusDocumento { get { return this._situacao; } set { this._situacao = value; base.OnPropertyChanged("StatusDocumento"); } } public ObservableCollection Telefones { get { return this._telefones; } set { this._telefones = value; base.OnPropertyChanged("Telefones"); } } public DateTime? TransmissaoCritica { get { return this._transmissaoCritica; } set { this._transmissaoCritica = value; base.OnPropertyChanged("TransmissaoCritica"); } } public ObservableCollection Usuarios { get { return this._usuarios; } set { this._usuarios = value; this.SelectedUsuario = this.SelectedUsuario ?? value.FirstOrDefault(); base.OnPropertyChanged("Usuarios"); } } public Visibility ValorComissao { get { return this._valorComissao; } set { this._valorComissao = value; base.OnPropertyChanged("ValorComissao"); } } public Visibility VisibilityFisica { get { return this._visibilityFisica; } set { this._visibilityFisica = value; base.OnPropertyChanged("VisibilityFisica"); } } public Visibility VisibilityJuridica { get { return this._visibilityJuridica; } set { this._visibilityJuridica = value; base.OnPropertyChanged("VisibilityJuridica"); } } public CriticaApoliceViewModel() { base.Invoke = false; this._criticaServico = new CriticaApoliceServico(); this._clienteServico = new ClienteServico(); this._itemServico = new ItemServico(); } public void AdcionarFiltro() { if (string.IsNullOrEmpty(this.Pesquisa)) { return; } if (string.IsNullOrWhiteSpace(this.Pesquisa.Replace("+", ""))) { return; } if (this.PesquisaCritica == null) { this.PesquisaCritica = new ObservableCollection(); } this.PesquisaCritica.Add(this.Pesquisa); this.Pesquisa = string.Empty; this.Pesquisar(); } public void AlteraDocumentoPrincipal() { if (this.SelectedCliente == null) { return; } TipoDocumento? documentoPrincipal = this.SelectedCliente.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); if (valueOrDefault == 1) { this.DocumentoPrincipal = this.SelectedCliente.get_Rne(); return; } if (valueOrDefault == 2) { this.DocumentoPrincipal = this.SelectedCliente.get_Cei(); return; } } this.DocumentoPrincipal = this.SelectedCliente.get_Documento(); this.SelectedCliente.set_DocumentoPrincipal(new TipoDocumento?(0)); } public async Task CarregaCritica(long usuario, long seguradora, bool criticado = false) { bool count; Usuario usuario1; Seguradora seguradora1; object nome; long num; object obj; long num1; object obj1; object obj2; object nome1; long num2; object nome2; long num3; object obj3; if (!this.IsLoading || this.BuscaInicial) { this.BuscaInicial = false; this.EnableGrid = false; base.Loading(true); this.Criticado = criticado; await this.CarregarUsuarios(usuario, this.Criticado); List criticaApolices = await this._criticaServico.BuscarCritica(usuario, this.Inicio, this.Fim, (long)0, this.Criticado, this.Vinculos); CriticaApoliceViewModel observableCollection = this; IEnumerable criticaApolices1 = criticaApolices.Where((CriticaApolice x) => { if (usuario != 0 && x.get_UsuarioImportacao().get_Id() != usuario) { return false; } if (seguradora == 0) { return true; } return x.get_Documento().get_Controle().get_Seguradora().get_Id() == seguradora; }); IOrderedEnumerable dataImportacao = from x in criticaApolices1 orderby x.get_DataImportacao() select x; observableCollection.Criticas = new ObservableCollection(dataImportacao.ThenByDescending((CriticaApolice x) => x.get_Documento().get_Controle().get_Cliente().get_Nome())); this.CriticaFiltrada = this.Criticas; if (this.CriticaFiltrada == null || this.CriticaFiltrada.Count <= 0) { this.IsCriticaSelected = false; } else { await this.SelecionaCritica(this.CriticaFiltrada.First()); } CriticaApoliceViewModel criticaApoliceViewModel = this; ObservableCollection criticaFiltrada = this.CriticaFiltrada; if (criticaFiltrada != null) { count = criticaFiltrada.Count > 0; } else { count = false; } criticaApoliceViewModel.IsExpanded = count; base.Loading(false); ObservableCollection usuarios = this.Usuarios; if (usuarios != null) { usuario1 = usuarios.FirstOrDefault((Usuario x) => x.get_Id() == usuario); } else { usuario1 = null; } Usuario usuario2 = usuario1; List seguradoras = base.Seguradoras; if (seguradoras != null) { seguradora1 = seguradoras.FirstOrDefault((Seguradora x) => x.get_Id() == seguradora); } else { seguradora1 = null; } Seguradora seguradora2 = seguradora1; CriticaApoliceViewModel criticaApoliceViewModel1 = this; string str = string.Format("CONSULTOU CRÍTICAS NO PERÍODO ENTRE {0:d} E {1:d}", this.Inicio, this.Fim); long num4 = (long)0; TipoTela? nullable = new TipoTela?(20); if (this.PesquisaCritica == null || this.PesquisaCritica.Count <= 0) { object[] objArray = new object[5]; if (usuario2 != null) { nome = usuario2.get_Nome(); } else { nome = null; } if (nome == null) { nome = "TODOS USUÁRIOS"; } objArray[0] = nome; num = (usuario2 != null ? usuario2.get_Id() : (long)0); objArray[1] = num; if (seguradora2 != null) { obj = seguradora2.get_Nome(); } else { obj = null; } if (obj == null) { obj = "TODAS AS SEGURADORAS"; } objArray[2] = obj; num1 = (seguradora2 != null ? seguradora2.get_Id() : (long)0); objArray[3] = num1; obj1 = (this.Criticado ? "SIM" : "NÃO"); objArray[4] = obj1; obj2 = string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nCRITICADOS: {4}", objArray); } else { object[] objArray1 = new object[6]; if (usuario2 != null) { nome1 = usuario2.get_Nome(); } else { nome1 = null; } if (nome1 == null) { nome1 = "TODOS USUÁRIOS"; } objArray1[0] = nome1; num2 = (usuario2 != null ? usuario2.get_Id() : (long)0); objArray1[1] = num2; if (seguradora2 != null) { nome2 = seguradora2.get_Nome(); } else { nome2 = null; } if (nome2 == null) { nome2 = "TODAS AS SEGURADORAS"; } objArray1[2] = nome2; num3 = (seguradora2 != null ? seguradora2.get_Id() : (long)0); objArray1[3] = num3; obj3 = (this.Criticado ? "SIM" : "NÃO"); objArray1[4] = obj3; objArray1[5] = ValidationHelper.Join(this.PesquisaCritica, ", "); obj2 = string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nCRITICADOS: {4}\nPESQUISA PERSONALIZADA: \"{5}\"", objArray1); } criticaApoliceViewModel1.RegistrarAcao(str, num4, nullable, obj2); this.EnableGrid = true; } } public async Task CarregarSeguradoras() { this.IsLoading = true; List list = await this._criticaServico.BuscarSeguradorasAsync(); List seguradoras = list; list = ( from x in seguradoras orderby x.get_Nome() select x).ToList(); Seguradora seguradora = new Seguradora(); seguradora.set_Id((long)0); seguradora.set_Nome("TODAS AS SEGURADORAS"); seguradora.set_Ativo(true); list.Insert(0, seguradora); CriticaApoliceViewModel observableCollection = this; List seguradoras1 = list; observableCollection.SeguradorasFiltro = new ObservableCollection( from x in seguradoras1 where x.get_Ativo() select x); this.SelectedSeguradora = this.SeguradorasFiltro.FirstOrDefault(); this.IsLoading = false; } public async Task CarregarUsuarios(long selected = 0L, bool criticado = false) { bool count; this.IsLoading = true; this.Criticado = criticado; List usuarios = new List(); List vinculos = this.Vinculos; if (vinculos != null) { count = vinculos.Count > 0; } else { count = false; } if (!count) { usuarios = await this._criticaServico.BuscarUsuarioCritica(this.Inicio, this.Fim, this.Criticado); Usuario usuario = new Usuario(); usuario.set_Id((long)0); usuario.set_Nome("TODOS OS USUÁRIOS"); usuarios.Insert(0, usuario); } else { Usuario usuario1 = new Usuario(); usuario1.set_Id(Recursos.Usuario.get_Id()); usuario1.set_Nome(Recursos.Usuario.get_Nome()); usuarios.Insert(0, usuario1); } this.Usuarios = new ObservableCollection(usuarios); CriticaApoliceViewModel criticaApoliceViewModel = this; Usuario usuario2 = this.Usuarios.FirstOrDefault((Usuario x) => x.get_Id() == selected); if (usuario2 == null) { usuario2 = this.Usuarios.FirstOrDefault(); } criticaApoliceViewModel.SelectedUsuario = usuario2; this.IsLoading = false; } public async Task ConcluirCritica() { List criticaApolices; string str; string descricao; DateTime networkTime = Funcoes.GetNetworkTime(); this.SelectedCritica.set_Critica(new bool?(true)); this.SelectedCritica.set_DataCritica(new DateTime?(networkTime)); this.SelectedCritica.set_UsuarioCritica(new long?(Recursos.Usuario.get_Id())); foreach (CriticaApolice criticaApolouse in await this._criticaServico.BuscarCritica(this.SelectedCritica.get_Documento().get_Id())) { criticaApolouse.set_Critica(new bool?(true)); criticaApolouse.set_DataCritica(new DateTime?(networkTime)); criticaApolouse.set_UsuarioCritica(new long?(Recursos.Usuario.get_Id())); await this._criticaServico.Save(criticaApolouse); } if (this.SeguroCombinado) { List list = ((IEnumerable)await this._criticaServico.BuscarSeguroCombinado(this.SelectedCritica.get_Documento().get_Controle().get_Cliente().get_Id(), this.SelectedCritica.get_Documento().get_Vigencia1())).Where((CriticaApolice duo) => { if (duo.get_Documento().get_Controle().get_Seguradora().get_Id() == this.SelectedCritica.get_Documento().get_Controle().get_Seguradora().get_Id() && duo.get_Documento().get_Controle().get_Cliente().get_Id() == this.SelectedCritica.get_Documento().get_Controle().get_Cliente().get_Id() && duo.get_Documento().get_Vigencia1() == this.SelectedCritica.get_Documento().get_Vigencia1()) { DateTime? vigencia2 = duo.get_Documento().get_Vigencia2(); DateTime? nullable = this.SelectedCritica.get_Documento().get_Vigencia2(); if ((vigencia2.HasValue == nullable.HasValue ? (vigencia2.HasValue ? vigencia2.GetValueOrDefault() == nullable.GetValueOrDefault() : true) : false) && duo.get_Documento().get_Id() != this.SelectedCritica.get_Documento().get_Id() && duo.get_Documento().get_Apolice() == this.SelectedCritica.get_Documento().get_Apolice() && duo.get_Documento().get_Proposta() == null) { return true; } } return Regex.Replace(duo.get_Documento().get_Proposta(), "[^.'-,/]", "") == Regex.Replace(this.SelectedCritica.get_Documento().get_Proposta(), "[^.'-,/]", ""); }).ToList(); if (list == null || list.Count() <= 0) { criticaApolices = null; } else { criticaApolices = await this._criticaServico.BuscarCritica(list.FirstOrDefault().get_Documento().get_Id()); } list = criticaApolices; if (list != null && list.Any()) { foreach (CriticaApolice criticaApolouse1 in list) { criticaApolouse1.set_Critica(new bool?(true)); criticaApolouse1.set_DataCritica(new DateTime?(networkTime)); criticaApolouse1.get_Documento().set_PremioLiquido(new decimal(1, 0, 0, false, 2)); criticaApolouse1.get_Documento().set_PremioTotal(new decimal(1, 0, 0, false, 2)); criticaApolouse1.get_Documento().set_Comissao(new decimal(1, 0, 0, false, 2)); criticaApolouse1.set_UsuarioCritica(new long?(Recursos.Usuario.get_Id())); await this._criticaServico.Save(criticaApolouse1); await this.Servico.Save(criticaApolouse1.get_Documento(), false, false); } } } if (this.SelectedCritica.get_Tipo() == "0") { str = string.Concat("A PROPOSTA \"", this.CancelDocumento.get_Proposta(), "\""); } else { str = (this.SelectedCritica.get_Tipo() == "1" ? string.Concat("A APÓLICE \"", this.CancelDocumento.get_Apolice(), "\"") : string.Concat("O ENDOSSO \"", this.CancelDocumento.get_Endosso(), "\"")); } string str1 = str; base.RegistrarAcao(string.Concat("CONCLUIU A CRÍTICA D", str1), this.SelectedCritica.get_Id(), new TipoTela?(20), null); if (this.Itens == null) { descricao = ""; } else if (this.Itens.Count > 1) { descricao = "APÓLICE COLETIVA"; } else { Item item = this.Itens.FirstOrDefault(); if (item != null) { descricao = item.get_Descricao(); } else { descricao = null; } } string str2 = descricao; try { if (string.IsNullOrEmpty(base.SelectedDocumento.get_Controle().get_AssistenciaId())) { await base.CreateLinkAssistencia(base.SelectedDocumento, str2, false); } } catch (Exception exception) { } base.SelectedDocumento = null; this.SelectedCliente = null; this.Telefones = null; this.Emails = null; this.Itens = null; await this.CarregaCritica(this.SelectedUsuario.get_Id(), this.SelectedSeguradora.get_Id(), this.Criticado); } public async void ExcluirEmail(ClienteEmail email) { if (this.Emails.Count >= 2) { this.HasChange = true; int? nullable = email.get_Ordem(); int count = this.Emails.Count; int count1 = this.Emails.Count; this.Emails.Remove(email); if (!(nullable.GetValueOrDefault() == count & nullable.HasValue)) { if (this.Emails.FirstOrDefault((ClienteEmail x) => { int? ordem = x.get_Ordem(); int num = count1; return ordem.GetValueOrDefault() == num & ordem.HasValue; }) != null) { this.Emails.First((ClienteEmail x) => { int? ordem = x.get_Ordem(); int num = count1; return ordem.GetValueOrDefault() == num & ordem.HasValue; }).set_Ordem(email.get_Ordem()); CriticaApoliceViewModel observableCollection = this; ObservableCollection emails = this.Emails; observableCollection.Emails = new ObservableCollection( from x in emails orderby x.get_Ordem() select x); } } } else { await base.ShowMessage("É NECESSÁRIO TER AO MENOS UM CONTATO DE E-MAIL CADASTRADO.", "OK", "", false); } } public async void ExcluirTelefone(ClienteTelefone telefone) { if (this.Telefones.Count >= 2) { this.HasChange = true; int? nullable = telefone.get_Ordem(); int count = this.Telefones.Count; int count1 = this.Telefones.Count; this.Telefones.Remove(telefone); if (!(nullable.GetValueOrDefault() == count & nullable.HasValue)) { if (this.Telefones.FirstOrDefault((ClienteTelefone x) => { int? ordem = x.get_Ordem(); int num = count1; return ordem.GetValueOrDefault() == num & ordem.HasValue; }) != null) { this.Telefones.First((ClienteTelefone x) => { int? ordem = x.get_Ordem(); int num = count1; return ordem.GetValueOrDefault() == num & ordem.HasValue; }).set_Ordem(telefone.get_Ordem()); CriticaApoliceViewModel observableCollection = this; ObservableCollection telefones = this.Telefones; observableCollection.Telefones = new ObservableCollection( from x in telefones orderby x.get_Ordem() select x); } } } else { await base.ShowMessage("É NECESSÁRIO TER AO MENOS UM TELEFONE CADASTRADO.", "OK", "", false); } } public async Task InitialLoad() { long id; this.IsLoading = true; base.Loading(true); await base.PermissaoTela(2); await this.SelecionaUsuario(); await this.CarregarUsuarios((long)0, false); await this.CarregarSeguradoras(); CriticaApoliceViewModel criticaApoliceViewModel = this; Usuario selectedUsuario = this.SelectedUsuario; if (selectedUsuario != null) { id = selectedUsuario.get_Id(); } else { id = (long)0; } await criticaApoliceViewModel.CarregaCritica(id, (long)0, false); base.Loading(false); this.IsLoading = false; } public void JuridicaouFisica(string documento) { if (this.SelectedCliente == null) { return; } this.ProfissaoText = ""; this.AtividadeText = ""; if (documento != null && ValidationHelper.OnlyNumber(documento).Length <= 11) { this.VisibilityJuridica = Visibility.Collapsed; this.VisibilityFisica = Visibility.Visible; this.FieldNascimento = "NASCIMENTO"; this.FieldDocumento = "CPF"; this.SelectedCliente.set_Atividade(null); return; } this.VisibilityJuridica = Visibility.Visible; this.VisibilityFisica = Visibility.Collapsed; this.FieldNascimento = "FUNDAÇÃO"; this.FieldDocumento = "CNPJ"; this.SelectedCliente.set_Profissao(null); } public async void Pesquisar() { this.EnableGrid = false; if (this.PesquisaCritica == null || this.PesquisaCritica.Count == 0) { this.CriticaFiltrada = new ObservableCollection(this.Criticas); } else { CriticaApoliceViewModel observableCollection = this; IEnumerable criticaApolices = this.Criticas.Where((CriticaApolice x) => { Func func2 = null; return this.PesquisaCritica.All((string s) => { List list = s.Split(new char[] { '+' }).ToList(); Func u003cu003e9_1484 = CriticaApoliceViewModel.u003cu003ec.u003cu003e9__148_4; if (u003cu003e9_1484 == null) { u003cu003e9_1484 = (string f) => !string.IsNullOrWhiteSpace(f); CriticaApoliceViewModel.u003cu003ec.u003cu003e9__148_4 = u003cu003e9_1484; } IEnumerable strs = list.Where(u003cu003e9_1484); Func u003cu003e9_5 = func2; if (u003cu003e9_5 == null) { Func func = (string f) => { if (ValidationHelper.RemoveDiacritics(x.get_Documento().get_Controle().get_Cliente().get_Nome()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || x.get_Documento().get_Controle().get_Cliente().get_Documento() != null && x.get_Documento().get_Controle().get_Cliente().get_Documento().Contains(f) || x.get_Documento().get_Controle().get_Cliente().get_Cei() != null && x.get_Documento().get_Controle().get_Cliente().get_Cei().Contains(f) || x.get_Documento().get_Controle().get_Cliente().get_Rne() != null && x.get_Documento().get_Controle().get_Cliente().get_Rne().Contains(f) || x.get_UsuarioImportacao() != null && x.get_UsuarioImportacao().get_Nome().Contains(f) || x.get_DataImportacao().HasValue && x.get_DataImportacao().ToString().Contains(f) || x.get_Documento().get_Apolice() != null && x.get_Documento().get_Apolice().ToUpper().Contains(f.ToUpper())) { return true; } if (x.get_Documento().get_Proposta() == null) { return false; } return x.get_Documento().get_Proposta().ToUpper().Contains(f.ToUpper()); }; Func func1 = func; func2 = func; u003cu003e9_5 = func1; } return strs.Any(u003cu003e9_5); }); }); IOrderedEnumerable dataImportacao = from x in criticaApolices orderby x.get_DataImportacao() select x; observableCollection.CriticaFiltrada = new ObservableCollection(dataImportacao.ThenByDescending((CriticaApolice x) => x.get_Documento().get_Controle().get_Cliente().get_Nome())); } await this.SelecionaCritica(this.CriticaFiltrada.FirstOrDefault()); this.EnableGrid = true; } public async Task>> SalvarCliente() { List> keyValuePairs; List> keyValuePairs1; Cliente cliente; CriticaApoliceViewModel.u003cu003ec__DisplayClass132_0 variable; List> keyValuePairs2; List> keyValuePairs3; if (!this.HasChange && !this.SelectedCliente.HasChange()) { ObservableCollection telefones = this.Telefones; if (telefones.All((ClienteTelefone x) => !x.HasChange())) { ObservableCollection emails = this.Emails; if (emails.All((ClienteEmail x) => !x.HasChange())) { keyValuePairs = null; variable = null; return keyValuePairs; } } } ObservableCollection observableCollection = this.Telefones; List list = ( from x in observableCollection where !string.IsNullOrEmpty(x.get_Numero()) select x).ToList(); ObservableCollection emails1 = this.Emails; List clienteEmails = ( from x in emails1 where !string.IsNullOrEmpty(x.get_Email()) select x).ToList(); this.SelectedCliente.set_Telefones(new ObservableCollection(list)); this.SelectedCliente.set_Emails(new ObservableCollection(clienteEmails)); TipoDocumento? documentoPrincipal = this.SelectedCliente.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); if (valueOrDefault == 1) { this.SelectedCliente.set_Rne(this.DocumentoPrincipal); keyValuePairs3 = this.SelectedCliente.Validate(); list.ForEach((ClienteTelefone x) => keyValuePairs3.AddRange(x.Validate())); clienteEmails.ForEach((ClienteEmail x) => keyValuePairs3.AddRange(x.Validate())); keyValuePairs2 = keyValuePairs3; keyValuePairs1 = await this.Validate(); keyValuePairs2.AddRange(keyValuePairs1); keyValuePairs2 = null; if (keyValuePairs3.Count <= 0) { cliente = await this._clienteServico.Save(this.SelectedCliente, false); keyValuePairs = null; } else { keyValuePairs = keyValuePairs3; } variable = null; return keyValuePairs; } else { if (valueOrDefault != 2) { goto Label2; } this.SelectedCliente.set_Cei(this.DocumentoPrincipal); keyValuePairs3 = this.SelectedCliente.Validate(); list.ForEach((ClienteTelefone x) => keyValuePairs3.AddRange(x.Validate())); clienteEmails.ForEach((ClienteEmail x) => keyValuePairs3.AddRange(x.Validate())); keyValuePairs2 = keyValuePairs3; keyValuePairs1 = await this.Validate(); keyValuePairs2.AddRange(keyValuePairs1); keyValuePairs2 = null; if (keyValuePairs3.Count <= 0) { cliente = await this._clienteServico.Save(this.SelectedCliente, false); keyValuePairs = null; } else { keyValuePairs = keyValuePairs3; } variable = null; return keyValuePairs; } } Label2: this.SelectedCliente.set_Documento(this.DocumentoPrincipal); keyValuePairs3 = this.SelectedCliente.Validate(); list.ForEach((ClienteTelefone x) => keyValuePairs3.AddRange(x.Validate())); clienteEmails.ForEach((ClienteEmail x) => keyValuePairs3.AddRange(x.Validate())); keyValuePairs2 = keyValuePairs3; keyValuePairs1 = await this.Validate(); keyValuePairs2.AddRange(keyValuePairs1); keyValuePairs2 = null; if (keyValuePairs3.Count <= 0) { cliente = await this._clienteServico.Save(this.SelectedCliente, false); keyValuePairs = null; } else { keyValuePairs = keyValuePairs3; } variable = null; return keyValuePairs; } public async Task SelecionaCliente(Cliente cliente) { DateTime? nullable; TipoDocumento? documentoPrincipal = cliente.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { TipoDocumento valueOrDefault = documentoPrincipal.GetValueOrDefault(); if (valueOrDefault == 1) { this.DocumentoPrincipal = cliente.get_Rne(); goto Label0; } else { if (valueOrDefault != 2) { goto Label1; } this.DocumentoPrincipal = cliente.get_Cei(); goto Label0; } } Label1: this.DocumentoPrincipal = cliente.get_Documento(); cliente.set_DocumentoPrincipal(new TipoDocumento?(0)); Label0: CriticaApoliceViewModel criticaApoliceViewModel = this; nullable = (cliente == null || !cliente.get_Nascimento().HasValue ? new DateTime?(Funcoes.GetNetworkTime().Date) : cliente.get_Nascimento()); criticaApoliceViewModel.NascimentoCritica = nullable; this.SelectedCliente = cliente; this.SelectedCliente.Initialize(); this.Telefones = await this._clienteServico.BuscarTelefonesAsync(this.SelectedCliente.get_Id()); if (this.Telefones.Count == 0) { ObservableCollection telefones = this.Telefones; ClienteTelefone clienteTelefone = new ClienteTelefone(); clienteTelefone.set_Cliente(this.SelectedCliente); telefones.Add(clienteTelefone); } List list = this.Telefones.ToList(); list.ForEach((ClienteTelefone x) => x.Initialize()); this.Emails = await this._clienteServico.BuscarEmailsAsync(this.SelectedCliente.get_Id()); if (this.Emails.Count == 0) { ObservableCollection emails = this.Emails; ClienteEmail clienteEmail = new ClienteEmail(); clienteEmail.set_Cliente(this.SelectedCliente); emails.Add(clienteEmail); } List clienteEmails = this.Emails.ToList(); clienteEmails.ForEach((ClienteEmail x) => x.Initialize()); } public async Task SelecionaCritica(CriticaApolice critica) { DateTime networkTime; DateTime? nullable; DateTime? remessa; TipoSeguro? nullable1; if (critica != null && !this.IsLoading) { this.IsLoading = true; base.Loading(true); CriticaApolice criticaApolouse = critica; Documento documento = await this.Servico.BuscarApoliceAsync(critica.get_Documento().get_Id(), false, false); criticaApolouse.set_Documento(documento); criticaApolouse = null; base.SelectedDocumento = null; base.Repasses = null; base.Parcelas = null; base.Pagamentos = null; base.SelectedParcela = null; base.SelectedPagamento = null; this.SelectedCritica = critica; await base.SelecionaDocumento(critica.get_Documento()); CriticaApoliceViewModel criticaApoliceViewModel = this; if (critica.get_Documento() == null || !critica.get_Documento().get_Emissao().HasValue) { networkTime = Funcoes.GetNetworkTime(); nullable = new DateTime?(networkTime.Date); } else { nullable = critica.get_Documento().get_Emissao(); } criticaApoliceViewModel.EmissaoCritica = nullable; CriticaApoliceViewModel criticaApoliceViewModel1 = this; if (critica.get_Documento() == null || !critica.get_Documento().get_Remessa().HasValue) { networkTime = Funcoes.GetNetworkTime(); remessa = new DateTime?(networkTime.Date); } else { remessa = critica.get_Documento().get_Remessa(); } criticaApoliceViewModel1.TransmissaoCritica = remessa; CriticaApoliceViewModel criticaApoliceViewModel2 = this; List configuracoes = Recursos.Configuracoes; if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 3)) { nullable1 = new TipoSeguro?(base.SelectedDocumento.get_Situacao()); } else { nullable1 = null; } criticaApoliceViewModel2.StatusDocumento = nullable1; if (base.SelectedDocumento != null) { TipoRecebimento? tipoRecebimento = base.SelectedDocumento.get_TipoRecebimento(); this.IsParcela = tipoRecebimento.GetValueOrDefault() == 1; await this.SelecionaCliente(base.SelectedDocumento.get_Controle().get_Cliente()); await this.SelecionaItens(base.SelectedDocumento.get_Controle().get_Id()); this.HasChange = false; base.Loading(false); this.IsLoading = false; } else { this.IsParcela = true; this.HasChange = false; base.Loading(false); } } } public async Task SelecionaItens(long id) { this.Itens = await this._itemServico.BuscarItens(id, 0); } public async Task SelecionaUsuario() { this.IsLoading = true; List configuracoes = Recursos.Configuracoes; if (configuracoes.Any((ConfiguracaoSistema x) => { if (x.get_Configuracao() == 38) { return true; } return x.get_Configuracao() == 43; }) && Recursos.Usuario.get_Id() != 0) { this.Vinculos = await base.VerificaVinculoVendedor(Recursos.Usuario); } this.IsLoading = false; } private async Task>> Validate() { List clientes; List> keyValuePairs = new List>(); bool flag = !string.IsNullOrEmpty(this.SelectedCliente.get_Nome()); TipoDocumento? documentoPrincipal = this.SelectedCliente.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { switch (documentoPrincipal.GetValueOrDefault()) { case 0: { if (ValidationHelper.ValidateDocument(this.SelectedCliente.get_Documento())) { break; } flag = false; break; } case 1: { if (ValidationHelper.ValidateRne(this.SelectedCliente.get_Rne())) { break; } flag = false; break; } case 2: { if (ValidationHelper.ValidateCei(this.SelectedCliente.get_Cei())) { break; } flag = false; break; } } } if (!ValidationHelper.ValidateDocument(this.SelectedCliente.get_Documento())) { clientes = new List(); } else { clientes = await (new ClienteServico()).BuscarClientePorDocumento(this.SelectedCliente.get_Documento()); } List clientes1 = clientes; string nome = ""; if (clientes1.Count > 0) { clientes1.ForEach((Cliente x) => { if (x.get_Id() == this.SelectedCliente.get_Id()) { return; } if (this.SelectedCliente.get_IdEmpresa() != x.get_IdEmpresa()) { return; } if (!string.IsNullOrEmpty(this.SelectedCliente.get_Documento()) && x.get_Documento() == this.SelectedCliente.get_Documento()) { flag = false; nome = x.get_Nome(); } }); } if (!flag) { keyValuePairs.Add(new KeyValuePair("Documento", string.Concat("O DOCUMENTO JÁ ESTÁ CADASTRADO PARA O CLIENTE ", nome, "."))); } if (this.SelectedCliente.get_Telefones() == null || this.SelectedCliente.get_Telefones().Count == 0) { keyValuePairs.Add(new KeyValuePair("Telefones", "NECESSITA-SE AO MENOS UM TELEFONE VÁLIDO.")); } List configuracoes = Recursos.Configuracoes; if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 29) && (this.SelectedCliente.get_Emails() == null || this.SelectedCliente.get_Emails().Count == 0)) { keyValuePairs.Add(new KeyValuePair("Emails", "NECESSITA-SE AO MENOS UM E-MAIL VÁLIDO.")); } List> keyValuePairs1 = keyValuePairs; keyValuePairs = null; return keyValuePairs1; } } }