diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
| commit | 225aa1499e37faf9d38257caabbadc68d78b427e (patch) | |
| tree | 102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs | |
| parent | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff) | |
| download | gestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip | |
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs new file mode 100644 index 0000000..4e162a9 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Drawer/MetaSeguradoraViewModel.cs @@ -0,0 +1,212 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using Assinador.Infrastructure.Helpers; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Ferramentas; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Common; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels.Drawer; + +public class MetaSeguradoraViewModel : BaseSegurosViewModel +{ + private readonly MetaSeguradoraServico _servico; + + private readonly Seguradora _selectedSeguradora; + + private MetaSeguradora _selectedMetaSeguradora = new MetaSeguradora(); + + private ObservableCollection<MetaSeguradora> _metasSeguradora = new ObservableCollection<MetaSeguradora>(); + + private bool _carregando; + + public MetaSeguradora CancelMetaSeguradora; + + public MetaSeguradora SelectedMetaSeguradora + { + get + { + return _selectedMetaSeguradora; + } + set + { + _selectedMetaSeguradora = value; + CancelMetaSeguradora = ((value != null && ((DomainBase)value).Id > 0) ? value : CancelMetaSeguradora); + VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); + OnPropertyChanged("SelectedMetaSeguradora"); + } + } + + public ObservableCollection<MetaSeguradora> MetasSeguradora + { + get + { + return _metasSeguradora; + } + set + { + _metasSeguradora = value; + OnPropertyChanged("MetasSeguradora"); + } + } + + public bool Carregando + { + get + { + return _carregando; + } + set + { + _carregando = value; + base.IsEnabled = !value; + base.EnableMenu = !value; + OnPropertyChanged("Carregando"); + } + } + + public MetaSeguradoraViewModel(Seguradora seguradora) + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + _servico = new MetaSeguradoraServico(); + Seleciona(seguradora); + _selectedSeguradora = seguradora; + } + + private async void Seleciona(Seguradora seguradora) + { + Loading(isLoading: true); + await PermissaoTela((TipoTela)31); + await SelecionaMetasSeguradora(seguradora); + Loading(isLoading: false); + } + + public void SelecionaMetaSeguradora(MetaSeguradora metaSeguradora) + { + SelectedMetaSeguradora = metaSeguradora; + } + + private async Task SelecionaMetasSeguradora(Seguradora seguradora) + { + Carregando = true; + await CarregarMetas(seguradora); + if (MetasSeguradora.Count > 0) + { + SelecionaMetaSeguradora(MetasSeguradora.First()); + } + else + { + SelectedMetaSeguradora = new MetaSeguradora(); + Alterar(alterar: false); + base.EnableMenu = false; + base.EnableAlterar = false; + base.EnableExcluir = false; + } + Carregando = false; + } + + public void Incluir() + { + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + //IL_0014: Unknown result type (might be due to invalid IL or missing references) + //IL_0022: Unknown result type (might be due to invalid IL or missing references) + //IL_0034: Expected O, but got Unknown + DateTime date = Funcoes.GetNetworkTime().Date; + SelectedMetaSeguradora = new MetaSeguradora + { + Ano = date.Year, + Mes = (Mes)date.Month + }; + Alterar(alterar: true); + } + + public async Task<List<KeyValuePair<string, string>>> Salvar() + { + SelectedMetaSeguradora.Seguradora = _selectedSeguradora; + string acao = ((((DomainBase)SelectedMetaSeguradora).Id == 0L) ? "INCLUIU" : "ALTEROU"); + MetaSeguradora value = await _servico.Save(SelectedMetaSeguradora); + if (!_servico.Sucesso) + { + return null; + } + RegistrarAcao(acao + " META DA SEGURADORA \"" + value.Seguradora.Nome + "\"", ((DomainBase)value).Id, (TipoTela)31, $"ID: {((DomainBase)value).Id}\nVALOR: {value.Valor:C}\nMÊS: {Functions.GetDescription((Enum)(object)value.Mes)}\nANO: {value.Ano}"); + if (MetasSeguradora.Any((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) + { + DomainBase.Copy<MetaSeguradora, MetaSeguradora>(MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value); + } + else + { + MetasSeguradora.Add(value); + } + MetasSeguradora = new ObservableCollection<MetaSeguradora>(MetasSeguradora); + SelectedMetaSeguradora = MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id); + Alterar(alterar: false); + return null; + } + + public async Task<bool> Excluir() + { + if (SelectedMetaSeguradora == null || ((DomainBase)SelectedMetaSeguradora).Id == 0L) + { + return false; + } + if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO"))) + { + return false; + } + Carregando = true; + if (!(await _servico.Delete(SelectedMetaSeguradora))) + { + Carregando = false; + Alterar(alterar: false); + return false; + } + MetaSeguradoraViewModel metaSeguradoraViewModel = this; + Seguradora seguradora = SelectedMetaSeguradora.Seguradora; + metaSeguradoraViewModel.RegistrarAcao("EXCLUIU META DA SEGURADORA \"" + ((seguradora != null) ? seguradora.Nome : null) + "\"", ((DomainBase)SelectedMetaSeguradora).Id, (TipoTela)31, $"ID: {((DomainBase)SelectedMetaSeguradora).Id}\nVALOR: {SelectedMetaSeguradora.Valor:C}\nMÊS: {Functions.GetDescription((Enum)(object)SelectedMetaSeguradora.Mes)}\nANO: {SelectedMetaSeguradora.Ano}"); + int num = MetasSeguradora.IndexOf(SelectedMetaSeguradora); + MetasSeguradora.Remove(SelectedMetaSeguradora); + MetasSeguradora.Remove(SelectedMetaSeguradora); + MetasSeguradora = new ObservableCollection<MetaSeguradora>(MetasSeguradora); + if (MetasSeguradora.Count > 0) + { + SelectedMetaSeguradora = ((num < MetasSeguradora.Count) ? MetasSeguradora.ElementAt(num) : MetasSeguradora.Last()); + } + else + { + SelectedMetaSeguradora = new MetaSeguradora(); + Alterar(alterar: false); + base.EnableMenu = false; + base.EnableAlterar = false; + base.EnableExcluir = false; + } + Carregando = false; + return true; + } + + public void CancelarAlteracao() + { + Carregando = true; + if (CancelMetaSeguradora != null && MetasSeguradora.Any((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id)) + { + DomainBase.Copy<MetaSeguradora, MetaSeguradora>(MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id), CancelMetaSeguradora); + SelectedMetaSeguradora = MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id); + } + Alterar(alterar: false); + Carregando = false; + } + + private async Task CarregarMetas(Seguradora seguradora) + { + MetasSeguradora = new ObservableCollection<MetaSeguradora>(from x in await new BaseServico().BuscarMetaSeguradoraAsync(seguradora) + orderby x.Mes, x.Valor + select x); + } +} |