diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs | 621 |
1 files changed, 621 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs new file mode 100644 index 0000000..f7daced --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/SeguradoraViewModel.cs @@ -0,0 +1,621 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+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.Threading.Tasks;
+using System.Windows;
+
+namespace Gestor.Application.ViewModels.Ferramentas
+{
+ public class SeguradoraViewModel : BaseSegurosViewModel
+ {
+ private readonly SeguradoraServico _servico;
+
+ private bool _apelido;
+
+ private Seguradora _selectedSeguradora;
+
+ private SeguradoraEndereco _selectedEndereco = new SeguradoraEndereco();
+
+ private ObservableCollection<SeguradoraContato> _contatos = new ObservableCollection<SeguradoraContato>();
+
+ private ObservableCollection<SeguradoraEndereco> _enderecos = new ObservableCollection<SeguradoraEndereco>();
+
+ private SeguradoraContato _selectedTelefone = new SeguradoraContato();
+
+ private Visibility _tipoTelefone;
+
+ private Visibility _telefone;
+
+ private Visibility _prefixo;
+
+ private ObservableCollection<ConfigExtratoImport> _configFiltrados = new ObservableCollection<ConfigExtratoImport>();
+
+ public Seguradora CancelSeguradora;
+
+ public ObservableCollection<SeguradoraEndereco> CancelEnderecos;
+
+ public ObservableCollection<SeguradoraContato> CancelContatos;
+
+ private ObservableCollection<Seguradora> _seguradorasFiltradas = new ObservableCollection<Seguradora>();
+
+ private bool _isExpanded;
+
+ public bool Apelido
+ {
+ get
+ {
+ return this._apelido;
+ }
+ set
+ {
+ this._apelido = value;
+ base.OnPropertyChanged("Apelido");
+ }
+ }
+
+ public List<ConfigExtratoImport> Config
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<ConfigExtratoImport> ConfigFiltrados
+ {
+ get
+ {
+ return this._configFiltrados;
+ }
+ set
+ {
+ this._configFiltrados = value;
+ base.OnPropertyChanged("ConfigFiltrados");
+ }
+ }
+
+ public ObservableCollection<SeguradoraContato> Contatos
+ {
+ get
+ {
+ return this._contatos;
+ }
+ set
+ {
+ this._contatos = value;
+ base.OnPropertyChanged("Contatos");
+ }
+ }
+
+ public ObservableCollection<SeguradoraEndereco> Enderecos
+ {
+ get
+ {
+ return this._enderecos;
+ }
+ set
+ {
+ this._enderecos = value;
+ base.OnPropertyChanged("Enderecos");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public string Pesquisa
+ {
+ get;
+ set;
+ }
+
+ public Visibility PrefixoVisibility
+ {
+ get
+ {
+ return this._prefixo;
+ }
+ set
+ {
+ if (this.SelectedTelefone.get_TipoContato() != 2)
+ {
+ this._prefixo = Visibility.Visible;
+ }
+ else
+ {
+ this._prefixo = Visibility.Collapsed;
+ }
+ base.OnPropertyChanged("PrefixoVisibility");
+ }
+ }
+
+ public List<Seguradora> Seguradoras
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Seguradora> SeguradorasFiltradas
+ {
+ get
+ {
+ return this._seguradorasFiltradas;
+ }
+ set
+ {
+ this._seguradorasFiltradas = value;
+ this.IsExpanded = (value != null ? value.Count > 0 : false);
+ base.OnPropertyChanged("SeguradorasFiltradas");
+ }
+ }
+
+ public SeguradoraEndereco SelectedEndereco
+ {
+ get
+ {
+ return this._selectedEndereco;
+ }
+ set
+ {
+ this._selectedEndereco = value;
+ base.OnPropertyChanged("SelectedEndereco");
+ }
+ }
+
+ public Seguradora SelectedSeguradora
+ {
+ get
+ {
+ return this._selectedSeguradora;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedSeguradora = value;
+ this.WorkOnSelectedSeguradora(value, true);
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ base.OnPropertyChanged("SelectedSeguradora");
+ }
+ }
+
+ public SeguradoraContato SelectedTelefone
+ {
+ get
+ {
+ return this._selectedTelefone;
+ }
+ set
+ {
+ this._selectedTelefone = value;
+ base.OnPropertyChanged("SelectedTelefone");
+ }
+ }
+
+ public Visibility TelefoneVisibility
+ {
+ get
+ {
+ return this._telefone;
+ }
+ set
+ {
+ if (this.SelectedTelefone.get_TipoContato() != 2)
+ {
+ this._telefone = Visibility.Visible;
+ }
+ else
+ {
+ this._telefone = Visibility.Collapsed;
+ }
+ base.OnPropertyChanged("TelefoneVisibility");
+ }
+ }
+
+ public Visibility TipoTelefoneVisibility
+ {
+ get
+ {
+ return this._tipoTelefone;
+ }
+ set
+ {
+ if (this.SelectedTelefone.get_TipoContato() != 2)
+ {
+ this._tipoTelefone = Visibility.Visible;
+ }
+ else
+ {
+ this._tipoTelefone = Visibility.Collapsed;
+ }
+ base.OnPropertyChanged("TipoTelefoneVisibility");
+ }
+ }
+
+ public decimal Tolerancia
+ {
+ get;
+ set;
+ }
+
+ public SeguradoraViewModel()
+ {
+ this._servico = new SeguradoraServico();
+ this.Apelido = Recursos.Configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 6);
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public void CancelarAlteracao()
+ {
+ if (this.CancelSeguradora != null && this.Seguradoras.Any<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()))
+ {
+ DomainBase.Copy<Seguradora, Seguradora>(this.Seguradoras.First<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora);
+ if (this.SeguradorasFiltradas.Count <= 0 || !this.SeguradorasFiltradas.Any<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()))
+ {
+ this.SeguradorasFiltradas.Add(this.CancelSeguradora);
+ }
+ else
+ {
+ DomainBase.Copy<Seguradora, Seguradora>(this.SeguradorasFiltradas.First<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id()), this.CancelSeguradora);
+ }
+ this.SeguradorasFiltradas = new ObservableCollection<Seguradora>(this.SeguradorasFiltradas);
+ this.ConfigFiltrados = new ObservableCollection<ConfigExtratoImport>(this.ConfigFiltrados);
+ this.SelectedSeguradora = this.SeguradorasFiltradas.First<Seguradora>((Seguradora x) => x.get_Id() == this.CancelSeguradora.get_Id());
+ this.Enderecos = this.CancelEnderecos;
+ this.Contatos = this.CancelContatos;
+ }
+ base.Alterar(false);
+ }
+
+ public void Clonar()
+ {
+ this.CancelSeguradora = (Seguradora)this.SelectedSeguradora.Clone();
+ this.CancelEnderecos = new ObservableCollection<SeguradoraEndereco>(this.Enderecos);
+ this.CancelContatos = new ObservableCollection<SeguradoraContato>(this.Contatos);
+ }
+
+ public void ExcluirEndereco(SeguradoraEndereco endereco)
+ {
+ this.Enderecos.Remove(endereco);
+ }
+
+ public void ExcluirTelefone(SeguradoraContato contato)
+ {
+ this.Contatos.Remove(contato);
+ }
+
+ internal async Task<List<Seguradora>> Filtrar(string value)
+ {
+ List<Seguradora> seguradoras = await Task.Run<List<Seguradora>>(() => this.FiltrarSeguradora(value));
+ return seguradoras;
+ }
+
+ internal async Task<List<ConfigExtratoImport>> FiltrarConfig(string value)
+ {
+ List<ConfigExtratoImport> configExtratoImports = await Task.Run<List<ConfigExtratoImport>>(() => this.FiltrarDescricao(value));
+ return configExtratoImports;
+ }
+
+ public List<ConfigExtratoImport> FiltrarDescricao(string filter)
+ {
+ this.ConfigFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<ConfigExtratoImport>(this.Config) : new ObservableCollection<ConfigExtratoImport>(
+ from x in this.Config
+ where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ orderby x.get_Descricao()
+ select x));
+ return this.ConfigFiltrados.ToList<ConfigExtratoImport>();
+ }
+
+ public List<Seguradora> FiltrarSeguradora(string filter)
+ {
+ this.Pesquisa = filter;
+ this.SeguradorasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Seguradora>(this.Seguradoras) : new ObservableCollection<Seguradora>(this.Seguradoras.Where<Seguradora>((Seguradora x) => {
+ if (ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)))
+ {
+ return true;
+ }
+ return ValidationHelper.RemoveDiacritics(x.get_NomeSocial()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter));
+ }).OrderByDescending<Seguradora, bool>((Seguradora x) => x.get_Ativo()).ThenBy<Seguradora, string>((Seguradora x) => x.get_Nome())));
+ return this.SeguradorasFiltradas.ToList<Seguradora>();
+ }
+
+ public async void Incluir(Seguradora seguradora)
+ {
+ seguradora.set_Tolerancia(new decimal?(2));
+ seguradora.set_ToleranciaPremio(new decimal?(2));
+ seguradora.set_Ativo(true);
+ await this._servico.Insert(seguradora);
+ if (this._servico.Sucesso)
+ {
+ await this.SelecionaSeguradoras(seguradora);
+ }
+ }
+
+ public void IncluirEndereco()
+ {
+ if (this.SelectedSeguradora == null)
+ {
+ return;
+ }
+ if (this.Enderecos == null)
+ {
+ this.Enderecos = new ObservableCollection<SeguradoraEndereco>();
+ }
+ SeguradoraEndereco seguradoraEndereco = new SeguradoraEndereco();
+ seguradoraEndereco.set_Empresa(Recursos.Empresa);
+ seguradoraEndereco.set_Seguradora(this.SelectedSeguradora);
+ seguradoraEndereco.set_Tipo(4);
+ SeguradoraEndereco seguradoraEndereco1 = seguradoraEndereco;
+ this.Enderecos.Add(seguradoraEndereco1);
+ this.SelectedEndereco = seguradoraEndereco1;
+ }
+
+ public void IncluirTelefone()
+ {
+ if (this.SelectedSeguradora == null)
+ {
+ return;
+ }
+ if (this.Contatos == null)
+ {
+ this.Contatos = new ObservableCollection<SeguradoraContato>();
+ }
+ SeguradoraContato seguradoraContato = new SeguradoraContato();
+ seguradoraContato.set_Empresa(Recursos.Empresa);
+ seguradoraContato.set_Seguradora(this.SelectedSeguradora);
+ seguradoraContato.set_Tipo(new TipoTelefone?(2));
+ SeguradoraContato seguradoraContato1 = seguradoraContato;
+ this.Contatos.Add(seguradoraContato1);
+ this.SelectedTelefone = seguradoraContato1;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedSeguradora.Validate();
+ keyValuePairs1.AddRange(this.Validate(this.Contatos.ToList<SeguradoraContato>()));
+ keyValuePairs1.AddRange(this.Validate(this.Enderecos.ToList<SeguradoraEndereco>()));
+ if (keyValuePairs1.Count <= 0)
+ {
+ Seguradora selectedSeguradora = this.SelectedSeguradora;
+ ObservableCollection<SeguradoraContato> contatos = this.Contatos;
+ selectedSeguradora.set_Contatos(contatos.Where<SeguradoraContato>((SeguradoraContato x) => {
+ if (!string.IsNullOrEmpty(x.get_NomeContato()))
+ {
+ return true;
+ }
+ return x.get_TipoContato() == 1;
+ }).ToList<SeguradoraContato>());
+ Seguradora seguradora = this.SelectedSeguradora;
+ ObservableCollection<SeguradoraEndereco> enderecos = this.Enderecos;
+ seguradora.set_Enderecos((
+ from x in enderecos
+ where !string.IsNullOrEmpty(x.get_Bairro())
+ select x).ToList<SeguradoraEndereco>());
+ Seguradora seguradora1 = await this._servico.Save(this.SelectedSeguradora, this.Config, false);
+ Seguradora seguradora2 = seguradora1;
+ str = (this.SelectedSeguradora.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ string str1 = str;
+ if (this._servico.Sucesso)
+ {
+ base.RegistrarAcao(string.Concat(str1, " SEGURADORA \"", seguradora2.get_Nome(), "\""), seguradora2.get_Id(), new TipoTela?(13), string.Format("SEGURADORA \"{0}\", ID: {1}", seguradora2.get_Nome(), seguradora2.get_Id()));
+ await this.SelecionaSeguradoras(null);
+ this.FiltrarSeguradora(this.Pesquisa);
+ SeguradoraViewModel seguradoraViewModel = this;
+ Seguradora seguradora3 = this.SeguradorasFiltradas.FirstOrDefault<Seguradora>((Seguradora x) => x.get_Id() == seguradora2.get_Id());
+ if (seguradora3 == null)
+ {
+ seguradora3 = this.SeguradorasFiltradas.FirstOrDefault<Seguradora>();
+ }
+ seguradoraViewModel.SelectedSeguradora = seguradora3;
+ base.Alterar(false);
+ base.ToggleSnackBar("SEGURADORA SALVA COM SUCESSO", true);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ return keyValuePairs;
+ }
+
+ private async void Seleciona()
+ {
+ base.Loading(true);
+ await base.PermissaoTela(13);
+ await this.SelecionaSeguradoras(null);
+ base.Loading(false);
+ }
+
+ public async void SelecionaSeguradora(Seguradora seguradora)
+ {
+ base.Loading(true);
+ this.SelectedSeguradora = seguradora;
+ this.Contatos = await this._servico.BuscarContatos(this.SelectedSeguradora.get_Id());
+ this.Enderecos = await this._servico.BuscarEnderecos(this.SelectedSeguradora.get_Id());
+ this.Config = await this._servico.BuscarConfig(this.SelectedSeguradora.get_Id());
+ this.ConfigFiltrados = new ObservableCollection<ConfigExtratoImport>(this.Config);
+ base.Loading(false);
+ }
+
+ private async Task SelecionaSeguradoras(Seguradora seguradora = null)
+ {
+ base.Loading(true);
+ List<Seguradora> seguradoras = await (new BaseServico()).BuscarSeguradorasAsync();
+ SeguradoraViewModel list = this;
+ List<Seguradora> seguradoras1 = seguradoras;
+ IOrderedEnumerable<Seguradora> ativo =
+ from x in seguradoras1
+ orderby x.get_Ativo() descending
+ select x;
+ list.Seguradoras = ativo.ThenBy<Seguradora, string>((Seguradora x) => x.get_Nome()).ToList<Seguradora>();
+ this.SeguradorasFiltradas = new ObservableCollection<Seguradora>(this.Seguradoras);
+ if (seguradora != null)
+ {
+ this.SelecionaSeguradora(this.SeguradorasFiltradas.FirstOrDefault<Seguradora>((Seguradora x) => x.get_Id() == seguradora.get_Id()));
+ }
+ else if (this.SeguradorasFiltradas.Count <= 0)
+ {
+ this.SelectedSeguradora = new Seguradora();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelecionaSeguradora(this.SeguradorasFiltradas.First<Seguradora>());
+ }
+ Recursos.Seguradoras = seguradoras;
+ base.Loading(false);
+ }
+
+ public List<KeyValuePair<string, string>> Validate(List<SeguradoraEndereco> endereco)
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (endereco != null)
+ {
+ endereco.ForEach((SeguradoraEndereco x) => keyValuePairs.AddRange(x.Validate()));
+ }
+ return keyValuePairs.Distinct<KeyValuePair<string, string>>().ToList<KeyValuePair<string, string>>();
+ }
+
+ public List<KeyValuePair<string, string>> Validate(List<SeguradoraContato> contatos)
+ {
+ List<SeguradoraContato> list;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (contatos != null)
+ {
+ contatos.ForEach((SeguradoraContato x) => keyValuePairs.AddRange(x.Validate()));
+ }
+ if (contatos != null)
+ {
+ list = (
+ from x in contatos
+ where x.get_TipoContato() == 1
+ select x).ToList<SeguradoraContato>();
+ }
+ else
+ {
+ list = null;
+ }
+ List<SeguradoraContato> seguradoraContatos = list;
+ if (seguradoraContatos == null)
+ {
+ return keyValuePairs;
+ }
+ if (seguradoraContatos.Count > 4)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("ASSISTÊNCIAS 24 HORAS", "NÃO É POSSÍVEL ADICIONAR MAIS QUE 4 NUMEROS DE ASSISTÊNCIA 24 HORAS"));
+ }
+ return keyValuePairs.Distinct<KeyValuePair<string, string>>().ToList<KeyValuePair<string, string>>();
+ }
+
+ private void WorkOnSelectedSeguradora(Seguradora value, bool registrar = true)
+ {
+ decimal? nullable;
+ bool contatos;
+ bool enderecos;
+ long? nullable1;
+ decimal? tolerancia;
+ this.CancelSeguradora = (value == null || value.get_Id() == 0 ? this.CancelSeguradora : (Seguradora)value.Clone());
+ this.CancelEnderecos = new ObservableCollection<SeguradoraEndereco>(this.Enderecos);
+ this.CancelContatos = new ObservableCollection<SeguradoraContato>(this.Contatos);
+ if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 13)
+ {
+ return;
+ }
+ Seguradora selectedSeguradora = this.SelectedSeguradora;
+ if (selectedSeguradora != null)
+ {
+ contatos = selectedSeguradora.get_Contatos();
+ }
+ else
+ {
+ contatos = false;
+ }
+ if (contatos)
+ {
+ this.Contatos = new ObservableCollection<SeguradoraContato>(this.SelectedSeguradora.get_Contatos());
+ }
+ Seguradora seguradora = this.SelectedSeguradora;
+ if (seguradora != null)
+ {
+ enderecos = seguradora.get_Enderecos();
+ }
+ else
+ {
+ enderecos = false;
+ }
+ if (enderecos)
+ {
+ this.Enderecos = new ObservableCollection<SeguradoraEndereco>(this.SelectedSeguradora.get_Enderecos());
+ }
+ if (registrar)
+ {
+ base.RegistrarAcao(string.Concat("ACESSOU SEGURADORA \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(13), string.Format("ID SEGURADORA: {0}", value.get_Id()));
+ }
+ this.LastAccessId = value.get_Id();
+ this.LastAccessTela = 13;
+ Seguradora selectedSeguradora1 = this.SelectedSeguradora;
+ if (selectedSeguradora1 != null)
+ {
+ nullable1 = new long?(selectedSeguradora1.get_Id());
+ }
+ else
+ {
+ nullable1 = null;
+ }
+ long? nullable2 = nullable1;
+ long id = value.get_Id();
+ if (nullable2.GetValueOrDefault() != id | !nullable2.HasValue)
+ {
+ this.SelectedSeguradora = this.SeguradorasFiltradas.FirstOrDefault<Seguradora>((Seguradora x) => x.get_Id() == value.get_Id());
+ }
+ Seguradora seguradora1 = this.SelectedSeguradora;
+ if (seguradora1 != null)
+ {
+ tolerancia = seguradora1.get_Tolerancia();
+ }
+ else
+ {
+ nullable = null;
+ tolerancia = nullable;
+ }
+ nullable = tolerancia;
+ this.Tolerancia = nullable.GetValueOrDefault();
+ }
+ }
+}
\ No newline at end of file |