From 225aa1499e37faf9d38257caabbadc68d78b427e Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 12:29:41 -0300 Subject: decompiler.com --- .../EstipulanteViewModel.cs | 316 +++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs (limited to 'Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs') diff --git a/Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs new file mode 100644 index 0000000..2848ad4 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs @@ -0,0 +1,316 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +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.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels.Ferramentas; + +public class EstipulanteViewModel : BaseSegurosViewModel +{ + private readonly EstipulanteServico _servico; + + public Estipulante CancelEstipulante; + + private Estipulante _selectedEstipulante = new Estipulante(); + + private ObservableCollection _estipulantesFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + public List Estipulantes { get; set; } + + public Estipulante SelectedEstipulante + { + get + { + return _selectedEstipulante; + } + set + { + _selectedEstipulante = value; + WorkOnSelectedEstipulante(value); + VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); + OnPropertyChanged("SelectedEstipulante"); + if (value != null) + { + ((DomainBase)SelectedEstipulante).Initialize(); + } + } + } + + public ObservableCollection EstipulantesFiltrados + { + get + { + return _estipulantesFiltrados; + } + set + { + _estipulantesFiltrados = value; + IsExpanded = value != null && value.Count > 0; + OnPropertyChanged("EstipulantesFiltrados"); + } + } + + public bool IsExpanded + { + get + { + return _isExpanded; + } + set + { + _isExpanded = value; + OnPropertyChanged("IsExpanded"); + } + } + + public EstipulanteViewModel() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + _servico = new EstipulanteServico(); + base.EnableMenu = true; + Seleciona(); + } + + private async void Seleciona() + { + Loading(isLoading: true); + await PermissaoTela((TipoTela)9); + await SelecionaEstipulantes(); + Loading(isLoading: false); + } + + private async Task SelecionaEstipulantes() + { + Loading(isLoading: true); + List list = await new BaseServico().BuscarEstipulantesAsync(); + Estipulantes = (from x in list + where Recursos.Usuario.IdEmpresa == 1 || Recursos.Usuario.IdEmpresa == x.IdEmpresa + orderby x.Ativo descending, x.Nome + select x).ToList(); + EstipulantesFiltrados = new ObservableCollection(Estipulantes); + if (EstipulantesFiltrados.Count > 0) + { + SelecionaEstipulante(EstipulantesFiltrados.First()); + } + else + { + SelectedEstipulante = new Estipulante(); + Alterar(alterar: false); + base.EnableMenu = false; + } + Recursos.Estipulantes = list; + Loading(isLoading: false); + } + + public async Task>> Validate() + { + List> errors = new List>(); + bool valida = !string.IsNullOrEmpty(SelectedEstipulante.Nome); + List list = ((!ValidationHelper.ValidateDocument(SelectedEstipulante.Documento)) ? new List() : (await new BaseServico().BuscarEstipulante(SelectedEstipulante.Documento))); + List list2 = list; + string nome = ""; + if (list2.Count > 0) + { + list2.ForEach(delegate(Estipulante x) + { + if (((DomainBase)x).Id != ((DomainBase)SelectedEstipulante).Id && !string.IsNullOrEmpty(SelectedEstipulante.Documento) && x.Documento == SelectedEstipulante.Documento) + { + valida = false; + nome = x.Nome; + } + }); + } + if (!valida) + { + errors.Add(new KeyValuePair("Documento", "O DOCUMENTO ESTÁ CADASTRADO PARA O ESTIPULANTE " + nome + ".")); + } + return errors; + } + + public void Incluir() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_0016: Unknown result type (might be due to invalid IL or missing references) + //IL_0022: Expected O, but got Unknown + SelectedEstipulante = new Estipulante + { + IdEmpresa = Recursos.Usuario.IdEmpresa, + Ativo = true + }; + Alterar(alterar: true); + } + + public async Task>> Salvar() + { + List> errorMessages = SelectedEstipulante.Validate(); + List> list = errorMessages; + list.AddRange(await Validate()); + if (errorMessages.Count > 0) + { + return errorMessages; + } + string acao = ((((DomainBase)SelectedEstipulante).Id == 0L) ? "INCLUIU" : "ALTEROU"); + Estipulante value = await _servico.Save(SelectedEstipulante); + if (!_servico.Sucesso) + { + return null; + } + RegistrarAcao(acao + " ESTIPULANTE \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)9, $"ESTIPULANTE \"{value.Nome}\", ID: {((DomainBase)value).Id}"); + if (Estipulantes.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) + { + DomainBase.Copy(Estipulantes.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value); + } + else + { + Estipulantes.Add(value); + } + if (EstipulantesFiltrados.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) + { + DomainBase.Copy(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value); + } + else + { + EstipulantesFiltrados.Add(value); + } + EstipulantesFiltrados = new ObservableCollection(EstipulantesFiltrados); + Recursos.Estipulantes = Estipulantes; + WorkOnSelectedEstipulante(value, registrar: false); + Alterar(alterar: false); + ((DomainBase)SelectedEstipulante).Initialize(); + ToggleSnackBar("ESTIPULANTE SALVO COM SUCESSO"); + return null; + } + + private void WorkOnSelectedEstipulante(Estipulante value, bool registrar = true) + { + //IL_002e: Unknown result type (might be due to invalid IL or missing references) + //IL_0069: Unknown result type (might be due to invalid IL or missing references) + //IL_0070: Invalid comparison between Unknown and I4 + //IL_00d6: Unknown result type (might be due to invalid IL or missing references) + CancelEstipulante = (Estipulante)((value == null || ((DomainBase)value).Id == 0L) ? ((object)CancelEstipulante) : ((object)(Estipulante)((DomainBase)value).Clone())); + if (value == null || ((DomainBase)value).Id == 0L || (LastAccessId == ((DomainBase)value).Id && (int)LastAccessTela == 9)) + { + return; + } + if (registrar) + { + RegistrarAcao("ACESSOU ESTIPULANTE \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)9, $"ID ESTIPULANTE: {((DomainBase)value).Id}"); + } + LastAccessId = ((DomainBase)value).Id; + LastAccessTela = (TipoTela)9; + Estipulante selectedEstipulante = SelectedEstipulante; + if (((selectedEstipulante != null) ? new long?(((DomainBase)selectedEstipulante).Id) : null) != ((DomainBase)value).Id) + { + SelectedEstipulante = ((IEnumerable)EstipulantesFiltrados).FirstOrDefault((Func)((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id)); + } + } + + public void CancelarAlteracao() + { + if (CancelEstipulante != null && Estipulantes.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id)) + { + DomainBase.Copy(Estipulantes.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id), CancelEstipulante); + if (EstipulantesFiltrados.Count > 0 && EstipulantesFiltrados.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id)) + { + DomainBase.Copy(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id), CancelEstipulante); + } + else + { + EstipulantesFiltrados.Add(CancelEstipulante); + } + EstipulantesFiltrados = new ObservableCollection(EstipulantesFiltrados); + SelectedEstipulante = EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id); + } + else + { + Incluir(); + } + Alterar(alterar: false); + } + + public async void Excluir() + { + if (SelectedEstipulante == null || ((DomainBase)SelectedEstipulante).Id == 0L) + { + return; + } + Loading(isLoading: true); + List list = await new BaseServico().BuscarDocumentosPorEstipulante(((DomainBase)SelectedEstipulante).Id); + Loading(isLoading: false); + if (list.Count > 0) + { + string text = "ESTIPULANTE NÃO PODE SER EXCLUÍDO POIS ESTÁ VINCULADO AOS SEGUINTES DOCUMENTOS:"; + foreach (Documento item in list) + { + text = ((!string.IsNullOrWhiteSpace(item.Apolice)) ? (text + $"{Environment.NewLine}DOCUMENTO {list.IndexOf(item) + 1} (NÚMERO DA PROPOSTA: {item.Proposta}, NÚMERO DA APÓLICE: {item.Apolice})") : (text + $"{Environment.NewLine}DOCUMENTO {list.IndexOf(item) + 1} (NÚMERO DA PROPOSTA: {item.Proposta})")); + } + await ShowMessage(text); + } + else + { + if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO"))) + { + return; + } + Loading(isLoading: true); + if (!(await _servico.Delete(SelectedEstipulante))) + { + Loading(isLoading: false); + return; + } + RegistrarAcao("EXCLUIU ESTIPULANTE \"" + SelectedEstipulante.Nome + "\"", ((DomainBase)SelectedEstipulante).Id, (TipoTela)9, $"ESTIPULANTE \"{SelectedEstipulante.Nome}\", ID: {((DomainBase)SelectedEstipulante).Id}"); + int num = EstipulantesFiltrados.IndexOf(SelectedEstipulante); + Estipulantes.Remove(SelectedEstipulante); + EstipulantesFiltrados.Remove(SelectedEstipulante); + EstipulantesFiltrados = new ObservableCollection(EstipulantesFiltrados); + if (EstipulantesFiltrados.Count > 0) + { + SelectedEstipulante = ((num < EstipulantesFiltrados.Count) ? EstipulantesFiltrados.ElementAt(num) : EstipulantesFiltrados.Last()); + } + else + { + SelectedEstipulante = new Estipulante(); + Alterar(alterar: false); + base.EnableMenu = false; + } + Recursos.Estipulantes = await new BaseServico().BuscarEstipulantesAsync(); + Loading(isLoading: false); + ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO"); + } + } + + internal async Task> Filtrar(string value) + { + return await Task.Run(() => FiltrarEstipulante(value)); + } + + public List FiltrarEstipulante(string filter) + { + EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(Estipulantes) : new ObservableCollection(from x in Estipulantes + where ValidationHelper.RemoveDiacritics(x.Nome.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby x.Ativo descending, x.Nome + select x)); + SelectedEstipulante = EstipulantesFiltrados.FirstOrDefault(); + return EstipulantesFiltrados.ToList(); + } + + public async void SelecionaEstipulante(Estipulante estipulante) + { + Estipulante val = await _servico.BuscarEstipulantePorId(((DomainBase)estipulante).Id); + DomainBase.Copy(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id), val); + SelectedEstipulante = EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id); + } +} -- cgit v1.2.3