From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Ferramentas/CadastroEmailViewModel.cs | 362 --------------------- 1 file changed, 362 deletions(-) delete mode 100644 Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs (limited to 'Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs') diff --git a/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs b/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs deleted file mode 100644 index 2294490..0000000 --- a/Gestor.Application/ViewModels/Ferramentas/CadastroEmailViewModel.cs +++ /dev/null @@ -1,362 +0,0 @@ -using Gestor.Application.Helpers; -using Gestor.Application.Servicos.Ferramentas; -using Gestor.Application.Servicos.Generic; -using Gestor.Application.ViewModels.Generic; -using Gestor.Common.Helpers; -using Gestor.Common.Validation; -using Gestor.Model.Common; -using Gestor.Model.Domain.Ferramentas; -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 CadastroEmailViewModel : BaseSegurosViewModel - { - private readonly EmailServico _servico; - - public Credencial CancelCredencial; - - private Credencial _selectedCredencial; - - private ObservableCollection _credenciaisFiltrados = new ObservableCollection(); - - private bool _isExpanded; - - public List Credenciais - { - get; - set; - } - - public ObservableCollection CredenciaisFiltrados - { - get - { - return this._credenciaisFiltrados; - } - set - { - this._credenciaisFiltrados = value; - this.IsExpanded = (value != null ? value.Count > 0 : false); - base.OnPropertyChanged("CredenciaisFiltrados"); - } - } - - public bool IsExpanded - { - get - { - return this._isExpanded; - } - set - { - this._isExpanded = value; - base.OnPropertyChanged("IsExpanded"); - } - } - - public Credencial SelectedCredencial - { - get - { - return this._selectedCredencial; - } - set - { - long? nullable; - this._selectedCredencial = value; - this.WorkOnSelectedCredencial(value, true); - if (value != null) - { - nullable = new long?(value.get_Id()); - } - else - { - nullable = null; - } - base.VerificarEnables(nullable); - base.OnPropertyChanged("SelectedCredencial"); - } - } - - public CadastroEmailViewModel() - { - this._servico = new EmailServico(); - base.EnableMenu = true; - this.Seleciona(); - } - - public async Task CancelarAlteracao() - { - long id; - await this.CarregarCredenciais(); - if (!this.CredenciaisFiltrados.Any()) - { - this.SelectedCredencial = new Credencial(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - Credencial cancelCredencial = this.CancelCredencial; - if (cancelCredencial != null) - { - id = cancelCredencial.get_Id(); - } - else - { - id = (long)0; - } - long num = id; - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == num); - } - base.Alterar(false); - } - - private async Task CarregarCredenciais() - { - List credencials = await (new BaseServico()).BuscarCredenciais(); - foreach (Credencial credencial in credencials) - { - if (credencial.get_Email().Contains("@gmail.com")) - { - credencial.set_Tipo(1); - } - credencial.set_Senha(EncryptionHelper.Decrypt(credencial.get_Senha())); - } - CadastroEmailViewModel list = this; - List credencials1 = credencials; - list.Credenciais = ( - from x in credencials1 - orderby x.get_Descricao() - select x).ToList(); - this.CredenciaisFiltrados = new ObservableCollection(this.Credenciais); - } - - public async Task EnviarTesteEmail() - { - bool flag; - if (this.SelectedCredencial != null) - { - TipoEmail tipo = this.SelectedCredencial.get_Tipo(); - if (tipo != null) - { - if (tipo - 1 <= 1) - { - if (string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Email())) - { - await base.ShowMessage("NECESSÁRIO PREENCHER O E-MAIL PARA ENVIAR UM E-MAIL DE TESTE", "OK", "", false); - flag = false; - return flag; - } - } - } - else if (string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Email()) || !this.SelectedCredencial.get_Porta().HasValue || string.IsNullOrWhiteSpace(this.SelectedCredencial.get_Dominio())) - { - await base.ShowMessage("NECESSÁRIO PREENCHER O E-MAIL, PORTA E DOMÍNIO PARA ENVIAR UM E-MAIL DE TESTE", "OK", "", false); - flag = false; - return flag; - } - MailHelper mailHelper = new MailHelper(); - Destinatario destinatario = new Destinatario(); - destinatario.set_Assunto("TESTE ENVIO E-MAIL"); - destinatario.set_Corpo("TESTE DE ENVIO DE E-MAIL"); - destinatario.set_Email(this.SelectedCredencial.get_Email()); - destinatario.set_Nome(this.SelectedCredencial.get_Descricao()); - Destinatario destinatario1 = destinatario; - LogEnvio logEnvio = await mailHelper.SendAsync(this.SelectedCredencial, destinatario1, null, null, 0, false); - if (logEnvio.get_Enviado()) - { - flag = true; - } - else - { - await base.ShowMessage(logEnvio.get_Erro(), "OK", "", false); - flag = false; - } - } - else - { - await base.ShowMessage("NECESSÁRIO CRIAR UM E-MAIL DE ENVIO PARA PROSSEGUIR.", "OK", "", false); - flag = false; - } - return flag; - } - - public async Task Excluir() - { - if (this.SelectedCredencial != null && this.SelectedCredencial.get_Id() != 0) - { - if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR O E-MAIL ", this.SelectedCredencial.get_Email(), " PERMANENTEMENTE?"), "SIM", "NÃO", false)) - { - base.Loading(true); - if (await this._servico.Delete(this.SelectedCredencial)) - { - base.RegistrarAcao(string.Concat("EXCLUIU E-MAIL \"", this.SelectedCredencial.get_Email(), "\""), this.SelectedCredencial.get_Id(), new TipoTela?(17), string.Format("E-MAIL: {0}\nID: {1}", this.SelectedCredencial.get_Email(), this.SelectedCredencial.get_Id())); - await this.CarregarCredenciais(); - if (!this.CredenciaisFiltrados.Any()) - { - this.SelectedCredencial = new Credencial(); - base.Alterar(false); - base.EnableMenu = false; - } - else - { - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - } - base.Loading(false); - base.ToggleSnackBar("E-MAIL EXCLUÍDO COM SUCESSO", true); - } - else - { - base.Loading(false); - } - } - } - } - - internal async Task> Filtrar(string value) - { - List credencials = await Task.Run>(() => this.FiltrarCredenciais(value)); - return credencials; - } - - public List FiltrarCredenciais(string filter) - { - this.CredenciaisFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Credenciais) : new ObservableCollection( - from x in this.Credenciais - where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) - select x)); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - return this.CredenciaisFiltrados.ToList(); - } - - public void Incluir() - { - Credencial credencial = new Credencial(); - credencial.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa()); - credencial.set_IdUsuario(Recursos.Usuario.get_Id()); - this.SelectedCredencial = credencial; - base.Alterar(true); - } - - public async Task>> Salvar() - { - List> keyValuePairs; - string str; - string str1; - List> keyValuePairs1 = this.SelectedCredencial.Validate(); - keyValuePairs1.AddRange(this.Validate()); - if (keyValuePairs1.Count <= 0) - { - this.SelectedCredencial.set_Assinatura(this.SelectedCredencial.get_Assinatura().GetBody()); - this.SelectedCredencial.set_Cabecalho(this.SelectedCredencial.get_Cabecalho().GetBody()); - if (this.SelectedCredencial.get_Senha() == null) - { - this.SelectedCredencial.set_Senha(""); - } - str = (this.SelectedCredencial.get_Id() == 0 ? "INCLUIU" : "ALTEROU"); - str1 = str; - Credencial credencial = await this._servico.Save(this.SelectedCredencial); - if (this._servico.Sucesso) - { - base.RegistrarAcao(string.Concat(str1, " E-MAIL \"", credencial.get_Email(), "\""), credencial.get_Id(), new TipoTela?(17), string.Format("E-MAIL: {0}\nID: {1}", credencial.get_Email(), credencial.get_Id())); - await this.CarregarCredenciais(); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == credencial.get_Id()); - base.Alterar(false); - base.ToggleSnackBar("E-MAIL SALVO COM SUCESSO", true); - keyValuePairs = null; - } - else - { - keyValuePairs = null; - } - } - else - { - keyValuePairs = keyValuePairs1; - } - str1 = null; - return keyValuePairs; - } - - private async void Seleciona() - { - base.Loading(true); - await base.PermissaoTela(17); - base.Loading(false); - } - - public async Task SelecionaCredenciais() - { - base.Loading(true); - await this.CarregarCredenciais(); - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault(); - base.Loading(false); - } - - public void SelecionaCredencial(Credencial credencial) - { - this.SelectedCredencial = this.CredenciaisFiltrados.First((Credencial x) => x.get_Id() == credencial.get_Id()); - } - - public List> Validate() - { - List> keyValuePairs = new List>(); - if (this.Credenciais.Any((Credencial x) => { - if (x.get_Id() == this.SelectedCredencial.get_Id()) - { - return false; - } - return x.get_Descricao() == this.SelectedCredencial.get_Descricao(); - })) - { - keyValuePairs.Add(new KeyValuePair("Descricao", "UM E-MAIL COM A MESMA DESCRIÇÃO/NOME JÁ EXISTE.")); - } - return keyValuePairs; - } - - private void WorkOnSelectedCredencial(Credencial value, bool registrar = true) - { - long? nullable; - this.CancelCredencial = (value == null || value.get_Id() == 0 ? this.CancelCredencial : (Credencial)value.Clone()); - if (value == null || value.get_Id() == 0) - { - return; - } - if (this.LastAccessId == value.get_Id() && this.LastAccessTela == 17) - { - return; - } - if (registrar) - { - base.RegistrarAcao(string.Concat("ACESSOU E-MAIL \"", value.get_Email(), "\""), value.get_Id(), new TipoTela?(17), string.Format("ID E-MAIL: {0}", value.get_Id())); - } - this.LastAccessId = value.get_Id(); - this.LastAccessTela = 17; - Credencial selectedCredencial = this.SelectedCredencial; - if (selectedCredencial != null) - { - nullable = new long?(selectedCredencial.get_Id()); - } - else - { - nullable = null; - } - long? nullable1 = nullable; - long id = value.get_Id(); - if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue) - { - this.SelectedCredencial = this.CredenciaisFiltrados.FirstOrDefault((Credencial x) => x.get_Id() == value.get_Id()); - } - } - } -} \ No newline at end of file -- cgit v1.2.3