summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Ferramentas/EstipulanteViewModel.cs316
1 files changed, 316 insertions, 0 deletions
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<Estipulante> _estipulantesFiltrados = new ObservableCollection<Estipulante>();
+
+ private bool _isExpanded;
+
+ public List<Estipulante> 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<Estipulante> 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<Estipulante> 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<Estipulante>(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<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();
+ bool valida = !string.IsNullOrEmpty(SelectedEstipulante.Nome);
+ List<Estipulante> list = ((!ValidationHelper.ValidateDocument(SelectedEstipulante.Documento)) ? new List<Estipulante>() : (await new BaseServico().BuscarEstipulante(SelectedEstipulante.Documento)));
+ List<Estipulante> 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<string, string>("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<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> errorMessages = SelectedEstipulante.Validate();
+ List<KeyValuePair<string, string>> 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<Estipulante, Estipulante>(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<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value);
+ }
+ else
+ {
+ EstipulantesFiltrados.Add(value);
+ }
+ EstipulantesFiltrados = new ObservableCollection<Estipulante>(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<Estipulante>)EstipulantesFiltrados).FirstOrDefault((Func<Estipulante, bool>)((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<Estipulante, Estipulante>(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<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id), CancelEstipulante);
+ }
+ else
+ {
+ EstipulantesFiltrados.Add(CancelEstipulante);
+ }
+ EstipulantesFiltrados = new ObservableCollection<Estipulante>(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<Documento> 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<Estipulante>(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<List<Estipulante>> Filtrar(string value)
+ {
+ return await Task.Run(() => FiltrarEstipulante(value));
+ }
+
+ public List<Estipulante> FiltrarEstipulante(string filter)
+ {
+ EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Estipulante>(Estipulantes) : new ObservableCollection<Estipulante>(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<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id), val);
+ SelectedEstipulante = EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id);
+ }
+}