diff options
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Ferramentas/SeguradoraViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Ferramentas/SeguradoraViewModel.cs | 535 |
1 files changed, 535 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Ferramentas/SeguradoraViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Ferramentas/SeguradoraViewModel.cs new file mode 100644 index 0000000..bae9af6 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Ferramentas/SeguradoraViewModel.cs @@ -0,0 +1,535 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +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; + +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 _apelido; + } + set + { + _apelido = value; + OnPropertyChanged("Apelido"); + } + } + + public Seguradora SelectedSeguradora + { + get + { + return _selectedSeguradora; + } + set + { + _selectedSeguradora = value; + WorkOnSelectedSeguradora(value); + VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); + OnPropertyChanged("SelectedSeguradora"); + } + } + + public SeguradoraEndereco SelectedEndereco + { + get + { + return _selectedEndereco; + } + set + { + _selectedEndereco = value; + OnPropertyChanged("SelectedEndereco"); + } + } + + public ObservableCollection<SeguradoraContato> Contatos + { + get + { + return _contatos; + } + set + { + _contatos = value; + OnPropertyChanged("Contatos"); + } + } + + public ObservableCollection<SeguradoraEndereco> Enderecos + { + get + { + return _enderecos; + } + set + { + _enderecos = value; + OnPropertyChanged("Enderecos"); + } + } + + public SeguradoraContato SelectedTelefone + { + get + { + return _selectedTelefone; + } + set + { + _selectedTelefone = value; + OnPropertyChanged("SelectedTelefone"); + } + } + + public Visibility TipoTelefoneVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _tipoTelefone; + } + set + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: Invalid comparison between Unknown and I4 + //IL_0019: Unknown result type (might be due to invalid IL or missing references) + //IL_0010: Unknown result type (might be due to invalid IL or missing references) + if ((int)SelectedTelefone.TipoContato == 2) + { + _tipoTelefone = (Visibility)2; + } + else + { + _tipoTelefone = (Visibility)0; + } + OnPropertyChanged("TipoTelefoneVisibility"); + } + } + + public Visibility TelefoneVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _telefone; + } + set + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: Invalid comparison between Unknown and I4 + //IL_0019: Unknown result type (might be due to invalid IL or missing references) + //IL_0010: Unknown result type (might be due to invalid IL or missing references) + if ((int)SelectedTelefone.TipoContato == 2) + { + _telefone = (Visibility)2; + } + else + { + _telefone = (Visibility)0; + } + OnPropertyChanged("TelefoneVisibility"); + } + } + + public Visibility PrefixoVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _prefixo; + } + set + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: Invalid comparison between Unknown and I4 + //IL_0019: Unknown result type (might be due to invalid IL or missing references) + //IL_0010: Unknown result type (might be due to invalid IL or missing references) + if ((int)SelectedTelefone.TipoContato == 2) + { + _prefixo = (Visibility)2; + } + else + { + _prefixo = (Visibility)0; + } + OnPropertyChanged("PrefixoVisibility"); + } + } + + public ObservableCollection<ConfigExtratoImport> ConfigFiltrados + { + get + { + return _configFiltrados; + } + set + { + _configFiltrados = value; + OnPropertyChanged("ConfigFiltrados"); + } + } + + public string Pesquisa { get; set; } + + public decimal Tolerancia { get; set; } + + public ObservableCollection<Seguradora> SeguradorasFiltradas + { + get + { + return _seguradorasFiltradas; + } + set + { + _seguradorasFiltradas = value; + IsExpanded = value != null && value.Count > 0; + OnPropertyChanged("SeguradorasFiltradas"); + } + } + + public bool IsExpanded + { + get + { + return _isExpanded; + } + set + { + _isExpanded = value; + OnPropertyChanged("IsExpanded"); + } + } + + public List<Seguradora> Seguradoras { get; set; } + + public List<ConfigExtratoImport> Config { get; set; } + + public SeguradoraViewModel() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + //IL_0022: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Expected O, but got Unknown + _servico = new SeguradoraServico(); + Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 6); + base.EnableMenu = true; + Seleciona(); + } + + private async void Seleciona() + { + Loading(isLoading: true); + await PermissaoTela((TipoTela)13); + await SelecionaSeguradoras(); + Loading(isLoading: false); + } + + private async Task SelecionaSeguradoras(Seguradora seguradora = null) + { + Loading(isLoading: true); + List<Seguradora> list = await new BaseServico().BuscarSeguradorasAsync(); + Seguradoras = (from x in list + orderby x.Ativo descending, x.Nome + select x).ToList(); + SeguradorasFiltradas = new ObservableCollection<Seguradora>(Seguradoras); + if (seguradora != null) + { + SelecionaSeguradora(((IEnumerable<Seguradora>)SeguradorasFiltradas).FirstOrDefault((Func<Seguradora, bool>)((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)seguradora).Id))); + } + else if (SeguradorasFiltradas.Count > 0) + { + SelecionaSeguradora(SeguradorasFiltradas.First()); + } + else + { + SelectedSeguradora = new Seguradora(); + Alterar(alterar: false); + base.EnableMenu = false; + } + Recursos.Seguradoras = list; + Loading(isLoading: false); + } + + public List<KeyValuePair<string, string>> Validate(List<SeguradoraEndereco> endereco) + { + List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>(); + endereco?.ForEach(delegate(SeguradoraEndereco x) + { + errors.AddRange(x.Validate()); + }); + return errors.Distinct().ToList(); + } + + public List<KeyValuePair<string, string>> Validate(List<SeguradoraContato> contatos) + { + List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>(); + contatos?.ForEach(delegate(SeguradoraContato x) + { + errors.AddRange(x.Validate()); + }); + List<SeguradoraContato> list = contatos?.Where((SeguradoraContato x) => (int)x.TipoContato == 1).ToList(); + if (list == null) + { + return errors; + } + if (list.Count > 4) + { + errors.Add(new KeyValuePair<string, string>("ASSISTÊNCIAS 24 HORAS", "NÃO É POSSÍVEL ADICIONAR MAIS QUE 4 NUMEROS DE ASSISTÊNCIA 24 HORAS")); + } + return errors.Distinct().ToList(); + } + + public void IncluirTelefone() + { + //IL_001c: Unknown result type (might be due to invalid IL or missing references) + //IL_0021: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Unknown result type (might be due to invalid IL or missing references) + //IL_0038: Unknown result type (might be due to invalid IL or missing references) + //IL_0045: Expected O, but got Unknown + if (SelectedSeguradora != null) + { + if (Contatos == null) + { + Contatos = new ObservableCollection<SeguradoraContato>(); + } + SeguradoraContato val = new SeguradoraContato + { + Empresa = Recursos.Empresa, + Seguradora = SelectedSeguradora, + Tipo = (TipoTelefone)2 + }; + Contatos.Add(val); + SelectedTelefone = val; + } + } + + public void ExcluirTelefone(SeguradoraContato contato) + { + Contatos.Remove(contato); + } + + public void IncluirEndereco() + { + //IL_001c: Unknown result type (might be due to invalid IL or missing references) + //IL_0021: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Unknown result type (might be due to invalid IL or missing references) + //IL_0038: Unknown result type (might be due to invalid IL or missing references) + //IL_0040: Expected O, but got Unknown + if (SelectedSeguradora != null) + { + if (Enderecos == null) + { + Enderecos = new ObservableCollection<SeguradoraEndereco>(); + } + SeguradoraEndereco val = new SeguradoraEndereco + { + Empresa = Recursos.Empresa, + Seguradora = SelectedSeguradora, + Tipo = (TipoEndereco)4 + }; + Enderecos.Add(val); + SelectedEndereco = val; + } + } + + public void ExcluirEndereco(SeguradoraEndereco endereco) + { + Enderecos.Remove(endereco); + } + + public async Task<List<KeyValuePair<string, string>>> Salvar() + { + List<KeyValuePair<string, string>> list = SelectedSeguradora.Validate(); + list.AddRange(Validate(Contatos.ToList())); + list.AddRange(Validate(Enderecos.ToList())); + if (list.Count > 0) + { + return list; + } + SelectedSeguradora.Contatos = Contatos.Where((SeguradoraContato x) => !string.IsNullOrEmpty(x.NomeContato) || (int)x.TipoContato == 1).ToList(); + SelectedSeguradora.Enderecos = Enderecos.Where((SeguradoraEndereco x) => !string.IsNullOrEmpty(((EnderecoBase)x).Bairro)).ToList(); + Seguradora value = await _servico.Save(SelectedSeguradora, Config); + string text = ((((DomainBase)SelectedSeguradora).Id == 0L) ? "INCLUIU" : "ALTEROU"); + if (!_servico.Sucesso) + { + return null; + } + RegistrarAcao(text + " SEGURADORA \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)13, $"SEGURADORA \"{value.Nome}\", ID: {((DomainBase)value).Id}"); + await SelecionaSeguradoras(); + FiltrarSeguradora(Pesquisa); + SelectedSeguradora = ((IEnumerable<Seguradora>)SeguradorasFiltradas).FirstOrDefault((Func<Seguradora, bool>)((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) ?? SeguradorasFiltradas.FirstOrDefault(); + Alterar(alterar: false); + ToggleSnackBar("SEGURADORA SALVA COM SUCESSO"); + return null; + } + + private void WorkOnSelectedSeguradora(Seguradora value, bool registrar = true) + { + //IL_002e: Unknown result type (might be due to invalid IL or missing references) + //IL_008b: Unknown result type (might be due to invalid IL or missing references) + //IL_0092: Invalid comparison between Unknown and I4 + //IL_014c: Unknown result type (might be due to invalid IL or missing references) + CancelSeguradora = (Seguradora)((value == null || ((DomainBase)value).Id == 0L) ? ((object)CancelSeguradora) : ((object)(Seguradora)((DomainBase)value).Clone())); + CancelEnderecos = new ObservableCollection<SeguradoraEndereco>(Enderecos); + CancelContatos = new ObservableCollection<SeguradoraContato>(Contatos); + if (value == null || ((DomainBase)value).Id == 0L || (LastAccessId == ((DomainBase)value).Id && (int)LastAccessTela == 13)) + { + return; + } + Seguradora selectedSeguradora = SelectedSeguradora; + if (((selectedSeguradora != null) ? selectedSeguradora.Contatos : null) != null) + { + Contatos = new ObservableCollection<SeguradoraContato>(SelectedSeguradora.Contatos); + } + Seguradora selectedSeguradora2 = SelectedSeguradora; + if (((selectedSeguradora2 != null) ? selectedSeguradora2.Enderecos : null) != null) + { + Enderecos = new ObservableCollection<SeguradoraEndereco>(SelectedSeguradora.Enderecos); + } + if (registrar) + { + RegistrarAcao("ACESSOU SEGURADORA \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)13, $"ID SEGURADORA: {((DomainBase)value).Id}"); + } + LastAccessId = ((DomainBase)value).Id; + LastAccessTela = (TipoTela)13; + Seguradora selectedSeguradora3 = SelectedSeguradora; + if (((selectedSeguradora3 != null) ? new long?(((DomainBase)selectedSeguradora3).Id) : null) != ((DomainBase)value).Id) + { + SelectedSeguradora = ((IEnumerable<Seguradora>)SeguradorasFiltradas).FirstOrDefault((Func<Seguradora, bool>)((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id)); + } + Seguradora selectedSeguradora4 = SelectedSeguradora; + Tolerancia = ((selectedSeguradora4 != null) ? selectedSeguradora4.Tolerancia : null).GetValueOrDefault(); + } + + public void CancelarAlteracao() + { + if (CancelSeguradora != null && Seguradoras.Any((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelSeguradora).Id)) + { + DomainBase.Copy<Seguradora, Seguradora>(Seguradoras.First((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelSeguradora).Id), CancelSeguradora); + if (SeguradorasFiltradas.Count > 0 && SeguradorasFiltradas.Any((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelSeguradora).Id)) + { + DomainBase.Copy<Seguradora, Seguradora>(SeguradorasFiltradas.First((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelSeguradora).Id), CancelSeguradora); + } + else + { + SeguradorasFiltradas.Add(CancelSeguradora); + } + SeguradorasFiltradas = new ObservableCollection<Seguradora>(SeguradorasFiltradas); + ConfigFiltrados = new ObservableCollection<ConfigExtratoImport>(ConfigFiltrados); + SelectedSeguradora = SeguradorasFiltradas.First((Seguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelSeguradora).Id); + Enderecos = CancelEnderecos; + Contatos = CancelContatos; + } + Alterar(alterar: false); + } + + internal async Task<List<Seguradora>> Filtrar(string value) + { + return await Task.Run(() => FiltrarSeguradora(value)); + } + + public List<Seguradora> FiltrarSeguradora(string filter) + { + Pesquisa = filter; + SeguradorasFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Seguradora>(Seguradoras) : new ObservableCollection<Seguradora>(from x in Seguradoras + where ValidationHelper.RemoveDiacritics(x.Nome.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || ValidationHelper.RemoveDiacritics(x.NomeSocial).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby x.Ativo descending, x.Nome + select x)); + return SeguradorasFiltradas.ToList(); + } + + internal async Task<List<ConfigExtratoImport>> FiltrarConfig(string value) + { + return await Task.Run(() => FiltrarDescricao(value)); + } + + public List<ConfigExtratoImport> FiltrarDescricao(string filter) + { + ConfigFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<ConfigExtratoImport>(Config) : new ObservableCollection<ConfigExtratoImport>(from x in Config + where ValidationHelper.RemoveDiacritics(x.Descricao.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby x.Descricao + select x)); + return ConfigFiltrados.ToList(); + } + + public async void SelecionaSeguradora(Seguradora seguradora) + { + Loading(isLoading: true); + SelectedSeguradora = seguradora; + Contatos = await _servico.BuscarContatos(((DomainBase)SelectedSeguradora).Id); + Enderecos = await _servico.BuscarEnderecos(((DomainBase)SelectedSeguradora).Id); + Config = await _servico.BuscarConfig(((DomainBase)SelectedSeguradora).Id); + ConfigFiltrados = new ObservableCollection<ConfigExtratoImport>(Config); + Loading(isLoading: false); + } + + public void Clonar() + { + //IL_000c: Unknown result type (might be due to invalid IL or missing references) + //IL_0016: Expected O, but got Unknown + CancelSeguradora = (Seguradora)((DomainBase)SelectedSeguradora).Clone(); + CancelEnderecos = new ObservableCollection<SeguradoraEndereco>(Enderecos); + CancelContatos = new ObservableCollection<SeguradoraContato>(Contatos); + } + + public async void Incluir(Seguradora seguradora) + { + seguradora.Tolerancia = 2; + seguradora.ToleranciaPremio = 2; + seguradora.Ativo = true; + await _servico.Insert(seguradora); + if (_servico.Sucesso) + { + await SelecionaSeguradoras(seguradora); + } + } +} |