summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs')
-rw-r--r--Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs380
1 files changed, 0 insertions, 380 deletions
diff --git a/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
deleted file mode 100644
index a084abd..0000000
--- a/Gestor.Application/ViewModels/Ferramentas/EstipulanteViewModel.cs
+++ /dev/null
@@ -1,380 +0,0 @@
-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;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-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 ObservableCollection<Estipulante> EstipulantesFiltrados
- {
- get
- {
- return this._estipulantesFiltrados;
- }
- set
- {
- this._estipulantesFiltrados = value;
- this.IsExpanded = (value != null ? value.Count > 0 : false);
- base.OnPropertyChanged("EstipulantesFiltrados");
- }
- }
-
- public bool IsExpanded
- {
- get
- {
- return this._isExpanded;
- }
- set
- {
- this._isExpanded = value;
- base.OnPropertyChanged("IsExpanded");
- }
- }
-
- public Estipulante SelectedEstipulante
- {
- get
- {
- return this._selectedEstipulante;
- }
- set
- {
- long? nullable;
- this._selectedEstipulante = value;
- this.WorkOnSelectedEstipulante(value, true);
- if (value != null)
- {
- nullable = new long?(value.get_Id());
- }
- else
- {
- nullable = null;
- }
- base.VerificarEnables(nullable);
- base.OnPropertyChanged("SelectedEstipulante");
- if (value == null)
- {
- return;
- }
- this.SelectedEstipulante.Initialize();
- }
- }
-
- public EstipulanteViewModel()
- {
- this._servico = new EstipulanteServico();
- base.EnableMenu = true;
- this.Seleciona();
- }
-
- public void CancelarAlteracao()
- {
- if (this.CancelEstipulante == null || !this.Estipulantes.Any<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()))
- {
- this.Incluir();
- }
- else
- {
- DomainBase.Copy<Estipulante, Estipulante>(this.Estipulantes.First<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante);
- if (this.EstipulantesFiltrados.Count <= 0 || !this.EstipulantesFiltrados.Any<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()))
- {
- this.EstipulantesFiltrados.Add(this.CancelEstipulante);
- }
- else
- {
- DomainBase.Copy<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id()), this.CancelEstipulante);
- }
- this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.EstipulantesFiltrados);
- this.SelectedEstipulante = this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == this.CancelEstipulante.get_Id());
- }
- base.Alterar(false);
- }
-
- public async void Excluir()
- {
- Estipulante estipulante;
- if (this.SelectedEstipulante != null && this.SelectedEstipulante.get_Id() != 0)
- {
- base.Loading(true);
- List<Documento> documentos = await (new BaseServico()).BuscarDocumentosPorEstipulante(this.SelectedEstipulante.get_Id());
- base.Loading(false);
- if (documentos.Count > 0)
- {
- string str = "ESTIPULANTE NÃO PODE SER EXCLUÍDO POIS ESTÁ VINCULADO AOS SEGUINTES DOCUMENTOS:";
- foreach (Documento documento in documentos)
- {
- if (!string.IsNullOrWhiteSpace(documento.get_Apolice()))
- {
- object[] newLine = new object[] { Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta(), documento.get_Apolice() };
- str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2}, NÚMERO DA APÓLICE: {3})", newLine));
- }
- else
- {
- str = string.Concat(str, string.Format("{0}DOCUMENTO {1} (NÚMERO DA PROPOSTA: {2})", Environment.NewLine, documentos.IndexOf(documento) + 1, documento.get_Proposta()));
- }
- }
- await base.ShowMessage(str, "OK", "", false);
- }
- else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false))
- {
- base.Loading(true);
- if (await this._servico.Delete(this.SelectedEstipulante))
- {
- base.RegistrarAcao(string.Concat("EXCLUIU ESTIPULANTE \"", this.SelectedEstipulante.get_Nome(), "\""), this.SelectedEstipulante.get_Id(), new TipoTela?(9), string.Format("ESTIPULANTE \"{0}\", ID: {1}", this.SelectedEstipulante.get_Nome(), this.SelectedEstipulante.get_Id()));
- int num = this.EstipulantesFiltrados.IndexOf(this.SelectedEstipulante);
- this.Estipulantes.Remove(this.SelectedEstipulante);
- this.EstipulantesFiltrados.Remove(this.SelectedEstipulante);
- this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.EstipulantesFiltrados);
- if (this.EstipulantesFiltrados.Count <= 0)
- {
- this.SelectedEstipulante = new Estipulante();
- base.Alterar(false);
- base.EnableMenu = false;
- }
- else
- {
- EstipulanteViewModel estipulanteViewModel = this;
- estipulante = (num < this.EstipulantesFiltrados.Count ? this.EstipulantesFiltrados.ElementAt<Estipulante>(num) : this.EstipulantesFiltrados.Last<Estipulante>());
- estipulanteViewModel.SelectedEstipulante = estipulante;
- }
- Recursos.Estipulantes = await (new BaseServico()).BuscarEstipulantesAsync();
- base.Loading(false);
- base.ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO", true);
- }
- else
- {
- base.Loading(false);
- }
- }
- }
- }
-
- internal async Task<List<Estipulante>> Filtrar(string value)
- {
- List<Estipulante> estipulantes = await Task.Run<List<Estipulante>>(() => this.FiltrarEstipulante(value));
- return estipulantes;
- }
-
- public List<Estipulante> FiltrarEstipulante(string filter)
- {
- this.EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Estipulante>(this.Estipulantes) : new ObservableCollection<Estipulante>(
- from x in this.Estipulantes
- where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
- orderby x.get_Ativo() descending, x.get_Nome()
- select x));
- this.SelectedEstipulante = this.EstipulantesFiltrados.FirstOrDefault<Estipulante>();
- return this.EstipulantesFiltrados.ToList<Estipulante>();
- }
-
- public void Incluir()
- {
- Estipulante estipulante = new Estipulante();
- estipulante.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa());
- estipulante.set_Ativo(true);
- this.SelectedEstipulante = estipulante;
- base.Alterar(true);
- }
-
- public async Task<List<KeyValuePair<string, string>>> Salvar()
- {
- List<KeyValuePair<string, string>> keyValuePairs;
- string str;
- string str1;
- List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedEstipulante.Validate();
- List<KeyValuePair<string, string>> keyValuePairs2 = keyValuePairs1;
- keyValuePairs2.AddRange(await this.Validate());
- keyValuePairs2 = null;
- if (keyValuePairs1.Count <= 0)
- {
- str = (this.SelectedEstipulante.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
- str1 = str;
- Estipulante estipulante = await this._servico.Save(this.SelectedEstipulante);
- if (this._servico.Sucesso)
- {
- base.RegistrarAcao(string.Concat(str1, " ESTIPULANTE \"", estipulante.get_Nome(), "\""), estipulante.get_Id(), new TipoTela?(9), string.Format("ESTIPULANTE \"{0}\", ID: {1}", estipulante.get_Nome(), estipulante.get_Id()));
- if (!this.Estipulantes.Any<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()))
- {
- this.Estipulantes.Add(estipulante);
- }
- else
- {
- DomainBase.Copy<Estipulante, Estipulante>(this.Estipulantes.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante);
- }
- if (!this.EstipulantesFiltrados.Any<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()))
- {
- this.EstipulantesFiltrados.Add(estipulante);
- }
- else
- {
- DomainBase.Copy<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante);
- }
- this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.EstipulantesFiltrados);
- Recursos.Estipulantes = this.Estipulantes;
- this.WorkOnSelectedEstipulante(estipulante, false);
- base.Alterar(false);
- this.SelectedEstipulante.Initialize();
- base.ToggleSnackBar("ESTIPULANTE SALVO COM SUCESSO", true);
- keyValuePairs = null;
- }
- else
- {
- keyValuePairs = null;
- }
- }
- else
- {
- keyValuePairs = keyValuePairs1;
- }
- keyValuePairs1 = null;
- str1 = null;
- return keyValuePairs;
- }
-
- private async void Seleciona()
- {
- base.Loading(true);
- await base.PermissaoTela(9);
- await this.SelecionaEstipulantes();
- base.Loading(false);
- }
-
- public async void SelecionaEstipulante(Estipulante estipulante)
- {
- Estipulante estipulante1 = await this._servico.BuscarEstipulantePorId(estipulante.get_Id());
- DomainBase.Copy<Estipulante, Estipulante>(this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id()), estipulante1);
- this.SelectedEstipulante = this.EstipulantesFiltrados.First<Estipulante>((Estipulante x) => x.get_Id() == estipulante.get_Id());
- }
-
- private async Task SelecionaEstipulantes()
- {
- base.Loading(true);
- List<Estipulante> estipulantes = await (new BaseServico()).BuscarEstipulantesAsync();
- EstipulanteViewModel list = this;
- List<Estipulante> estipulantes1 = estipulantes;
- IEnumerable<Estipulante> estipulantes2 = estipulantes1.Where<Estipulante>((Estipulante x) => {
- if (Recursos.Usuario.get_IdEmpresa() == (long)1)
- {
- return true;
- }
- return Recursos.Usuario.get_IdEmpresa() == x.get_IdEmpresa();
- });
- IOrderedEnumerable<Estipulante> ativo =
- from x in estipulantes2
- orderby x.get_Ativo() descending
- select x;
- list.Estipulantes = ativo.ThenBy<Estipulante, string>((Estipulante x) => x.get_Nome()).ToList<Estipulante>();
- this.EstipulantesFiltrados = new ObservableCollection<Estipulante>(this.Estipulantes);
- if (this.EstipulantesFiltrados.Count <= 0)
- {
- this.SelectedEstipulante = new Estipulante();
- base.Alterar(false);
- base.EnableMenu = false;
- }
- else
- {
- this.SelecionaEstipulante(this.EstipulantesFiltrados.First<Estipulante>());
- }
- Recursos.Estipulantes = estipulantes;
- base.Loading(false);
- }
-
- public async Task<List<KeyValuePair<string, string>>> Validate()
- {
- List<Estipulante> estipulantes;
- List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
- bool flag = !string.IsNullOrEmpty(this.SelectedEstipulante.get_Nome());
- if (!ValidationHelper.ValidateDocument(this.SelectedEstipulante.get_Documento()))
- {
- estipulantes = new List<Estipulante>();
- }
- else
- {
- estipulantes = await (new BaseServico()).BuscarEstipulante(this.SelectedEstipulante.get_Documento());
- }
- List<Estipulante> estipulantes1 = estipulantes;
- string nome = "";
- if (estipulantes1.Count > 0)
- {
- estipulantes1.ForEach((Estipulante x) => {
- if (x.get_Id() == this.SelectedEstipulante.get_Id())
- {
- return;
- }
- if (!string.IsNullOrEmpty(this.SelectedEstipulante.get_Documento()) && x.get_Documento() == this.SelectedEstipulante.get_Documento())
- {
- flag = false;
- nome = x.get_Nome();
- }
- });
- }
- if (!flag)
- {
- keyValuePairs.Add(new KeyValuePair<string, string>("Documento", string.Concat("O DOCUMENTO ESTÁ CADASTRADO PARA O ESTIPULANTE ", nome, ".")));
- }
- List<KeyValuePair<string, string>> keyValuePairs1 = keyValuePairs;
- keyValuePairs = null;
- return keyValuePairs1;
- }
-
- private void WorkOnSelectedEstipulante(Estipulante value, bool registrar = true)
- {
- long? nullable;
- this.CancelEstipulante = (value == null || value.get_Id() == 0 ? this.CancelEstipulante : (Estipulante)value.Clone());
- if (value == null || value.get_Id() == 0 || this.LastAccessId == value.get_Id() && this.LastAccessTela == 9)
- {
- return;
- }
- if (registrar)
- {
- base.RegistrarAcao(string.Concat("ACESSOU ESTIPULANTE \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(9), string.Format("ID ESTIPULANTE: {0}", value.get_Id()));
- }
- this.LastAccessId = value.get_Id();
- this.LastAccessTela = 9;
- Estipulante selectedEstipulante = this.SelectedEstipulante;
- if (selectedEstipulante != null)
- {
- nullable = new long?(selectedEstipulante.get_Id());
- }
- else
- {
- nullable = null;
- }
- long? nullable1 = nullable;
- long id = value.get_Id();
- if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue)
- {
- this.SelectedEstipulante = this.EstipulantesFiltrados.FirstOrDefault<Estipulante>((Estipulante x) => x.get_Id() == value.get_Id());
- }
- }
- }
-} \ No newline at end of file