summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs')
-rw-r--r--Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs2412
1 files changed, 2412 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs b/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs
new file mode 100644
index 0000000..be9b6fb
--- /dev/null
+++ b/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs
@@ -0,0 +1,2412 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Net.Sockets;
+using System.Threading.Tasks;
+using Agger.Registro;
+using Gestor.Application.Helpers;
+using Gestor.Application.ViewModels;
+using Gestor.Common.Security;
+using Gestor.Common.Validation;
+using Gestor.Infrastructure.Helpers;
+using Gestor.Infrastructure.UnitOfWork.Generic;
+using Gestor.Infrastructure.UnitOfWork.Logic;
+using Gestor.Model.API;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Aggilizador;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Financeiro;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Relatorios;
+using Gestor.Model.Domain.Seguros;
+using Newtonsoft.Json;
+
+namespace Gestor.Application.Servicos.Generic;
+
+public class BaseServico
+{
+ private const int UnathorizedSsoCode = 401;
+
+ private const int NotFoundSsoCode = 404;
+
+ public bool Sucesso { get; set; }
+
+ public int Registrar(Exception e, TipoErro erro, int tries, object objeto = null, bool abrirTela = true)
+ {
+ //IL_0029: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_003a: Expected O, but got Unknown
+ //IL_003b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0040: Unknown result type (might be due to invalid IL or missing references)
+ //IL_004b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0062: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0079: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0091: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00a1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ad: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b3: Expected I4, but got Unknown
+ //IL_00b3: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b4: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00c4: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00d0: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e8: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f4: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0100: Unknown result type (might be due to invalid IL or missing references)
+ //IL_010c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0118: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0123: Unknown result type (might be due to invalid IL or missing references)
+ //IL_012e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_013b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0149: Expected O, but got Unknown
+ tries--;
+ if (tries > 0)
+ {
+ return tries;
+ }
+ try
+ {
+ int fileLineNumber = new StackTrace(e, fNeedFileInfo: true).GetFrame(0).GetFileLineNumber();
+ string objeto2 = ((objeto != null) ? JsonConvert.SerializeObject(objeto, (Formatting)1, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }) : null);
+ LogError val = new LogError
+ {
+ IdFornecedor = ApplicationHelper.IdFornecedor
+ };
+ Empresa empresa = Recursos.Empresa;
+ val.Fornecedor = ((empresa != null) ? empresa.Nome : null);
+ Usuario usuario = Recursos.Usuario;
+ val.UsuarioLogado = ((usuario != null) ? usuario.Nome : null);
+ Usuario usuario2 = Recursos.Usuario;
+ val.IdUsuarioLogado = ((usuario2 != null) ? ((DomainBase)usuario2).Id : 0);
+ val.Versao = ApplicationHelper.Versao.ToString();
+ val.Data = Funcoes.GetNetworkTime();
+ val.IdErro = (int)erro;
+ val.Erro = ValidationHelper.GetDescription((Enum)(object)erro);
+ val.HResult = e.HResult;
+ val.InnerException = e.InnerException?.ToString();
+ val.HelpLink = e.HelpLink;
+ val.Message = e.Message;
+ val.Source = e.Source;
+ val.StackTrace = e.StackTrace;
+ val.Maquina = Environment.MachineName;
+ val.UsuarioMaquina = Environment.UserName;
+ val.Linha = fileLineNumber.ToString();
+ val.Objeto = objeto2;
+ Erro.RegistrarErro(val, abrirTela);
+ Sucesso = false;
+ }
+ catch (Exception)
+ {
+ }
+ return 0;
+ }
+
+ public RegistroLog CreateLog(long id, dynamic obj, TipoTela tela)
+ {
+ //IL_0092: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0097: Unknown result type (might be due to invalid IL or missing references)
+ //IL_009e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00a9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b0: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00bd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00c2: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ce: Expected O, but got Unknown
+ //IL_00d6: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00dd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00de: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e4: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ef: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0105: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0145: Unknown result type (might be due to invalid IL or missing references)
+ //IL_014d: Expected O, but got Unknown
+ try
+ {
+ List<Diferenca> list = obj.Compare();
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ return new RegistroLog
+ {
+ Acao = (TipoAcao)1,
+ Usuario = Recursos.Usuario,
+ DataHora = networkTime,
+ Descricao = ((list != null && list.Count == 0) ? null : JsonConvert.SerializeObject((object)list, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ })),
+ EntidadeId = id,
+ Tela = tela,
+ Versao = LoginViewModel.VersaoAtual,
+ NomeMaquina = Environment.MachineName,
+ UsuarioMaquina = Environment.UserName,
+ Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(),
+ ModeloNovo = true
+ };
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public RegistroLog CreateDynamicLog(long id, dynamic lista, TipoTela tela)
+ {
+ //IL_063f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0644: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0650: Expected O, but got Unknown
+ //IL_0682: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0687: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0693: Expected O, but got Unknown
+ //IL_06ba: Unknown result type (might be due to invalid IL or missing references)
+ //IL_06bf: Unknown result type (might be due to invalid IL or missing references)
+ //IL_06c6: Unknown result type (might be due to invalid IL or missing references)
+ //IL_06d1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_06d8: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0704: Unknown result type (might be due to invalid IL or missing references)
+ //IL_070b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_070c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0712: Unknown result type (might be due to invalid IL or missing references)
+ //IL_071d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0728: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0733: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0773: Unknown result type (might be due to invalid IL or missing references)
+ //IL_077c: Expected O, but got Unknown
+ try
+ {
+ List<Diferenca> list = new List<Diferenca>();
+ List<ValorOriginal> list2 = new List<ValorOriginal>();
+ foreach (dynamic listum in lista)
+ {
+ if (listum == null)
+ {
+ continue;
+ }
+ if (listum.GetType().Name.ToUpper().StartsWith("LIST"))
+ {
+ foreach (dynamic item in listum)
+ {
+ try
+ {
+ if (!((item.Id == 0) ? true : false))
+ {
+ list.AddRange(DynamicObjeto(item));
+ }
+ else
+ {
+ list2.AddRange(item.GetValorOriginal());
+ }
+ }
+ catch
+ {
+ }
+ }
+ }
+ else
+ {
+ try
+ {
+ list.AddRange(DynamicObjeto(listum));
+ }
+ catch
+ {
+ }
+ }
+ }
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ string text = ((list != null && list.Count == 0) ? "" : JsonConvert.SerializeObject((object)list, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }).Replace("]", ",").Replace("[", ""));
+ string text2 = ((list2 != null && list2.Count == 0) ? "" : JsonConvert.SerializeObject((object)list2, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }).Replace("]", "").Replace("[", ""));
+ return new RegistroLog
+ {
+ Acao = (TipoAcao)1,
+ Usuario = Recursos.Usuario,
+ DataHora = networkTime,
+ Descricao = ((string.IsNullOrEmpty(text) && string.IsNullOrEmpty(text2)) ? null : ("[" + text + text2 + "]")),
+ EntidadeId = id,
+ Tela = tela,
+ Versao = LoginViewModel.VersaoAtual,
+ NomeMaquina = Environment.MachineName,
+ UsuarioMaquina = Environment.UserName,
+ Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(),
+ ModeloNovo = true
+ };
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public List<Diferenca> DynamicObjeto(dynamic objeto)
+ {
+ dynamic val = objeto.Compare();
+ if (val.Count > 0)
+ {
+ return val;
+ }
+ return new List<Diferenca>();
+ }
+
+ public RegistroLog CreateLog(long id, List<Diferenca> diferenca, TipoTela tela)
+ {
+ //IL_0006: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0012: Unknown result type (might be due to invalid IL or missing references)
+ //IL_001d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0024: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0026: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0037: Expected O, but got Unknown
+ //IL_003c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0043: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0044: Unknown result type (might be due to invalid IL or missing references)
+ //IL_004a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0055: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0060: Unknown result type (might be due to invalid IL or missing references)
+ //IL_006b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ab: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b3: Expected O, but got Unknown
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ return new RegistroLog
+ {
+ Acao = (TipoAcao)1,
+ Usuario = Recursos.Usuario,
+ DataHora = networkTime,
+ Descricao = JsonConvert.SerializeObject((object)diferenca, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }),
+ EntidadeId = id,
+ Tela = tela,
+ Versao = LoginViewModel.VersaoAtual,
+ NomeMaquina = Environment.MachineName,
+ UsuarioMaquina = Environment.UserName,
+ Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(),
+ ModeloNovo = true
+ };
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public RegistroLog CreateLog(long id, List<Diferenca> diferenca, TipoTela tela, TipoAcao acao)
+ {
+ //IL_0006: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0013: Unknown result type (might be due to invalid IL or missing references)
+ //IL_001e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0025: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0027: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0038: Expected O, but got Unknown
+ //IL_003d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0044: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0045: Unknown result type (might be due to invalid IL or missing references)
+ //IL_004b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0056: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0061: Unknown result type (might be due to invalid IL or missing references)
+ //IL_006c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b4: Expected O, but got Unknown
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ return new RegistroLog
+ {
+ Acao = acao,
+ Usuario = Recursos.Usuario,
+ DataHora = networkTime,
+ Descricao = JsonConvert.SerializeObject((object)diferenca, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }),
+ EntidadeId = id,
+ Tela = tela,
+ Versao = LoginViewModel.VersaoAtual,
+ NomeMaquina = Environment.MachineName,
+ UsuarioMaquina = Environment.UserName,
+ Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(),
+ ModeloNovo = true
+ };
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public RegistroLog CreateLog(long id, List<ValorOriginal> valor, TipoTela tela, TipoAcao acao)
+ {
+ //IL_0006: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0013: Unknown result type (might be due to invalid IL or missing references)
+ //IL_001e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0025: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0027: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0038: Expected O, but got Unknown
+ //IL_003d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0044: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0045: Unknown result type (might be due to invalid IL or missing references)
+ //IL_004b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0056: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0061: Unknown result type (might be due to invalid IL or missing references)
+ //IL_006c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b4: Expected O, but got Unknown
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ return new RegistroLog
+ {
+ Acao = acao,
+ Usuario = Recursos.Usuario,
+ DataHora = networkTime,
+ Descricao = JsonConvert.SerializeObject((object)valor, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }),
+ EntidadeId = id,
+ Tela = tela,
+ Versao = LoginViewModel.VersaoAtual,
+ NomeMaquina = Environment.MachineName,
+ UsuarioMaquina = Environment.UserName,
+ Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(),
+ ModeloNovo = true
+ };
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public void SaveLog(RegistroLog keyValues, UnitOfWork unitOfWork)
+ {
+ if (keyValues == null)
+ {
+ return;
+ }
+ try
+ {
+ unitOfWork.RegistroLogRepository.SaveOrUpdate(keyValues);
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ public void SaveLog(List<RegistroLog> keyValues, UnitOfWork unitOfWork)
+ {
+ if (keyValues == null)
+ {
+ return;
+ }
+ try
+ {
+ List<RegistroLog> list = keyValues.Where((RegistroLog x) => !string.IsNullOrEmpty((x != null) ? x.Descricao : null) && !string.IsNullOrEmpty(x.Versao)).ToList();
+ unitOfWork.RegistroLogRepository.AddRange(list);
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ internal async Task<List<Profissao>> BuscarProfissao(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.ProfissaoRepository.Find(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)180, tries, value);
+ }
+ }
+ return new List<Profissao>();
+ });
+ }
+
+ internal async Task<List<Atividade>> BuscarAtividade(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.AtividadeRepository.Find(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)181, tries, value);
+ }
+ }
+ return new List<Atividade>();
+ });
+ }
+
+ internal async Task<List<Banco>> BuscarBanco(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.BancoRepository.Find(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)144, tries, value);
+ }
+ }
+ return new List<Banco>();
+ });
+ }
+
+ internal async Task<List<BancosContas>> BuscarBancosContas(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.BancosContasRepository.Find(value)
+ orderby x.Descricao
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)146, tries, value);
+ }
+ }
+ return new List<BancosContas>();
+ });
+ }
+
+ internal async Task<List<Fabricante>> BuscarFabricante(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.FabricanteRepository.Find(value)
+ orderby x.Descricao
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)182, tries, value);
+ }
+ }
+ return new List<Fabricante>();
+ });
+ }
+
+ internal Empresa BuscarEmpresa(long id)
+ {
+ //IL_003d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0043: Expected O, but got Unknown
+ int num = 3;
+ while (num > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.EmpresaRepository.FindById(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ num = Registrar(e, (TipoErro)114, num, id);
+ }
+ }
+ return new Empresa();
+ }
+
+ internal async Task<List<Vendedor>> BuscarVendedor(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.VendedorRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)140, tries, value);
+ }
+ }
+ return new List<Vendedor>();
+ });
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulante(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.EstipulanteRepository.Find(value, (Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)111, tries, value);
+ }
+ }
+ return new List<Estipulante>();
+ });
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulantesAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Estipulante>(from x in read.EstipulanteRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)112, tries);
+ }
+ }
+ return new List<Estipulante>();
+ });
+ }
+
+ public async Task<List<Usuario>> BuscarUsuariosAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Usuario>(from x in read.UsuarioRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)131, tries);
+ }
+ }
+ return new List<Usuario>();
+ });
+ }
+
+ public async Task<List<Empresa>> BuscarEmpresasAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Empresa>(from x in read.EmpresaRepository.Find(0L)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)113, tries);
+ }
+ }
+ return new List<Empresa>();
+ });
+ }
+
+ public async Task<List<Socio>> BuscarSociosAsync(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.SocioRepository.FindByEmpresa(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)122, tries, id);
+ }
+ }
+ return new List<Socio>();
+ });
+ }
+
+ internal async Task<List<Usuario>> BuscarUsuario(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.UsuarioRepository.Find(value, 0L)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)132, tries, value);
+ }
+ }
+ return new List<Usuario>();
+ });
+ }
+
+ internal async Task<AuthSso> BuscaUsuarioSso(string login, string password, string documentoEmpresa)
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("auth");
+ string text = $"{login}:{password}:{ApplicationHelper.NumeroSerial}:{documentoEmpresa}:{Funcoes.GetNetworkTime().ToUniversalTime().Ticks}".ToBase64BasicEncode();
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", text);
+ HttpResponseMessage val = await client.GetAsync(uri);
+ return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject<AuthSso>(await val.Content.ReadAsStringAsync());
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+
+ internal async Task<AuthSso> VerificaUsuarioSso(string login, string documentoEmpresa)
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("exist");
+ string text = $"{login}:{login}:{ApplicationHelper.NumeroSerial}:{documentoEmpresa}:{Funcoes.GetNetworkTime().ToUniversalTime().Ticks}".ToBase64BasicEncode();
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", text);
+ HttpResponseMessage val = await client.GetAsync(uri);
+ return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject<AuthSso>(await val.Content.ReadAsStringAsync());
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+
+ internal async Task<UserSso> AddOrUpdateUsuarioSso(Usuario usuario, string documentoEmpresa, string ssoId = null)
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("user");
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso);
+ UserSso val = usuario.ToUserSso(ApplicationHelper.NumeroSerial, documentoEmpresa, ssoId);
+ HttpResponseMessage val2 = ((val.Id != null) ? (await client.PutAsync(uri, (HttpContent)(object)val.ToHttpContent<UserSso>())) : (await client.PostAsync(uri, (HttpContent)(object)val.ToHttpContent<UserSso>())));
+ HttpResponseMessage val3 = val2;
+ return (!val3.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject<UserSso>(await val3.Content.ReadAsStringAsync());
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+
+ internal async Task<UserSso> DeleteUsuarioSso(Usuario usuario, string documentoEmpresa)
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("user").AddQuery("userId", usuario.SsoId);
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso);
+ HttpResponseMessage val = await client.DeleteAsync(uri);
+ return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject<UserSso>(await val.Content.ReadAsStringAsync());
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+
+ private async Task<bool> BuscaUsuarioByToken(Usuario usuario)
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("user");
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso);
+ JsonConvert.DeserializeObject<UserSso>(await (await client.GetAsync(uri)).Content.ReadAsStringAsync());
+ return true;
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+
+ internal async Task<Usuario> BuscarUsuario(string login, string password)
+ {
+ int tries = 3;
+ Token val = new Token();
+ string encryptedPassword = val.AggerEncrypt(password);
+ return await Task.Run((Func<Usuario>)delegate
+ {
+ //IL_02a9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_02af: Expected O, but got Unknown
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ Empresa val2 = read.EmpresaRepository.FindBySerial(ApplicationHelper.NumeroSerial);
+ AuthSso result = BuscaUsuarioSso(login, encryptedPassword, val2.Documento).Result;
+ if (result == null || result.Code == 401)
+ {
+ return (Usuario)null;
+ }
+ Usuario val3;
+ if (result.Code == 404)
+ {
+ val3 = read.UsuarioRepository.ValidateLogin(login, encryptedPassword);
+ if (val3 == null)
+ {
+ return (Usuario)null;
+ }
+ val3.TokenSso = result.Data.Token;
+ UserSso result2 = AddOrUpdateUsuarioSso(val3, val2.Documento).Result;
+ if (result2 == null)
+ {
+ return val3;
+ }
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ val3.SsoId = result2.Id;
+ commited.UsuarioRepository.Merge(val3);
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ AuthSso result3 = BuscaUsuarioSso(login, encryptedPassword, val2.Documento).Result;
+ val3.TokenSso = result3.Data.Token;
+ return val3;
+ }
+ val3 = read.UsuarioRepository.SsoId(result) ?? read.UsuarioRepository.FindFromSso(result.Data.User);
+ if (val3 == null)
+ {
+ UnitOfWork commited2 = Instancia.Commited;
+ try
+ {
+ val3 = commited2.UsuarioRepository.AddUsuarioFromSso(result.Data.User);
+ ((GenericUnitOfWork)commited2).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited2)?.Dispose();
+ }
+ val3.TokenSso = result.Data.Token;
+ return val3;
+ }
+ if (val3.Excluido)
+ {
+ UnitOfWork commited3 = Instancia.Commited;
+ try
+ {
+ val3.Excluido = false;
+ commited3.UsuarioRepository.Merge(val3);
+ ((GenericUnitOfWork)commited3).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited3)?.Dispose();
+ }
+ }
+ val3.TokenSso = result.Data.Token;
+ if (ValidationHelper.IsNotNullOrEmpty(val3.SsoId) && val3.SsoId.Equals(result.Data.User.Id))
+ {
+ return val3;
+ }
+ UnitOfWork commited4 = Instancia.Commited;
+ try
+ {
+ val3.SsoId = result.Data.User.Id;
+ commited4.UsuarioRepository.Merge(val3);
+ ((GenericUnitOfWork)commited4).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited4)?.Dispose();
+ }
+ return val3;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)134, tries);
+ }
+ }
+ return new Usuario();
+ });
+ }
+
+ public async Task<List<UserSso>> BuscarUsuariosSso()
+ {
+ _ = 1;
+ try
+ {
+ HttpClient client = new HttpClient();
+ try
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri uri = Address.ApiSso.Append("user").Append("onlyempresa").Append("list");
+ ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + Recursos.Usuario.TokenSso);
+ HttpResponseMessage val = await client.GetAsync(uri);
+ return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject<List<UserSso>>(await val.Content.ReadAsStringAsync());
+ }
+ finally
+ {
+ ((IDisposable)client)?.Dispose();
+ }
+ }
+ catch
+ {
+ return new List<UserSso>();
+ }
+ }
+
+ public async Task<List<Parceiro>> BuscarParceirosAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Parceiro>(from x in read.ParceiroRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)72, tries);
+ }
+ }
+ return new List<Parceiro>();
+ });
+ }
+
+ public async Task<List<MetaVendedor>> BuscarMetaVendedorAsync(Vendedor vendedor)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<MetaVendedor>(from x in read.MetaVendedorRepository.Find(((DomainBase)vendedor).Id)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)183, tries, vendedor);
+ }
+ }
+ return new List<MetaVendedor>();
+ });
+ }
+
+ public async Task<List<Adiantamento>> BuscarAdiantamentoAsync(Vendedor vendedor)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Adiantamento>(from x in read.AdiantamentoRepository.Find(((DomainBase)vendedor).Id)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)185, tries, vendedor);
+ }
+ }
+ return new List<Adiantamento>();
+ });
+ }
+
+ public async Task<List<MetaSeguradora>> BuscarMetaSeguradoraAsync(Seguradora seguradora)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<MetaSeguradora>(from x in read.MetaSeguradoraRepository.Find(((DomainBase)seguradora).Id)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)184, tries, seguradora);
+ }
+ }
+ return new List<MetaSeguradora>();
+ });
+ }
+
+ internal async Task<List<Usuario>> BuscarUsuarioPorLoginInteiro(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.UsuarioRepository.FindByLoginInteiro(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)134, tries, value);
+ }
+ }
+ return new List<Usuario>();
+ });
+ }
+
+ internal async Task<bool> BuscarUsuarioMesmoDocumento(string value, long id, long idempresa)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.UsuarioRepository.FindDocUsedByDocumento(value, id, idempresa);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)134, tries, value);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<List<Produto>> BuscarProduto(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.ProdutoRepository.Find(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)117, tries, value);
+ }
+ }
+ return new List<Produto>();
+ });
+ }
+
+ public async Task<List<Status>> BuscarStatus(string value)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.StatusRepository.Find(value)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)120, tries, value);
+ }
+ }
+ return new List<Status>();
+ });
+ }
+
+ public async Task<List<Ramo>> BuscarRamosAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Ramo>(from x in read.RamoRepository.Find()
+ orderby x.Nome
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)169, tries);
+ }
+ }
+ return new List<Ramo>();
+ });
+ }
+
+ public async Task<Qualificacao> BuscarQualificacaoAsync()
+ {
+ int tries = 3;
+ return await Task.Run((Func<Qualificacao>)delegate
+ {
+ //IL_004e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0054: Expected O, but got Unknown
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.QualificacaoRepository.FindById(1L);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)170, tries);
+ }
+ }
+ return new Qualificacao();
+ });
+ }
+
+ public async Task<List<Seguradora>> BuscarSeguradorasAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Seguradora>(from x in read.SeguradoraRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)127, tries);
+ }
+ }
+ return new List<Seguradora>();
+ });
+ }
+
+ public async Task<List<Agenda>> BuscarAgendasAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Agenda>(from x in read.AgendaRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)129, tries);
+ }
+ }
+ return new List<Agenda>();
+ });
+ }
+
+ public async Task<List<Vendedor>> BuscarVendedoresAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Vendedor>(from x in read.VendedorRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa)
+ orderby ((DomainBase)x).Id
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)140, tries);
+ }
+ }
+ return new List<Vendedor>();
+ });
+ }
+
+ public async Task<List<TipoVendedor>> BuscarTipoVendedoresAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.TipoVendedorRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)141, tries);
+ }
+ }
+ return new List<TipoVendedor>();
+ });
+ }
+
+ public async Task<List<Produto>> BuscarProdutosAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Produto>(from x in read.ProdutoRepository.Find()
+ orderby x.Nome
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)118, tries);
+ }
+ }
+ return new List<Produto>();
+ });
+ }
+
+ public async Task<List<Status>> BuscarStatusAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Status>(from x in read.StatusRepository.Find()
+ orderby x.Nome
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)121, tries);
+ }
+ }
+ return new List<Status>();
+ });
+ }
+
+ internal async Task<List<CoberturaPadrao>> BuscaCoberturas()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.CoberturaPadraoRepository.Find()
+ orderby x.Descricao
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)58, tries);
+ }
+ }
+ return new List<CoberturaPadrao>();
+ });
+ }
+
+ public async Task<bool> LoadInicialParameters()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ Recursos.Parceiros = new List<Parceiro>(from x in read.ParceiroRepository.Find()
+ orderby ((DomainBase)x).Id
+ select x);
+ Recursos.Fabricantes = (from x in read.FabricanteRepository.Select()
+ orderby x.Descricao
+ select x).ToList();
+ Recursos.Configuracoes = read.ConfiguracaoRepository.BuscarConfiguracoes();
+ read.CriarAuxiliar(false);
+ Recursos.Empresas = Auxiliar.Empresas;
+ Recursos.Ramos = Auxiliar.Ramos;
+ Recursos.Seguradoras = Auxiliar.Seguradoras;
+ Recursos.Produtos = Auxiliar.Produtos;
+ Recursos.Status = Auxiliar.StatusApolice;
+ Recursos.TipoVendedor = Auxiliar.TipoVendedores;
+ Recursos.Estipulantes = Auxiliar.Estipulantes;
+ Recursos.Vendedores = Auxiliar.Vendedores;
+ Recursos.Usuarios = Auxiliar.Usuarios;
+ Recursos.TiposTarefa = Auxiliar.TiposTarefa;
+ Recursos.StatusProspeccao = Auxiliar.StatusProspeccao;
+ Recursos.Coberturas = Auxiliar.CoberturasPadrao;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)186, tries);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<bool> ReloadAuxiliar()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ read.CriarAuxiliar(true);
+ Recursos.Empresas = Auxiliar.Empresas;
+ Recursos.Ramos = Auxiliar.Ramos;
+ Recursos.Seguradoras = Auxiliar.Seguradoras;
+ Recursos.Produtos = Auxiliar.Produtos;
+ Recursos.Status = Auxiliar.StatusApolice;
+ Recursos.TipoVendedor = Auxiliar.TipoVendedores;
+ Recursos.Estipulantes = Auxiliar.Estipulantes;
+ Recursos.Vendedores = Auxiliar.Vendedores;
+ Recursos.Usuarios = Auxiliar.Usuarios;
+ Recursos.TiposTarefa = Auxiliar.TiposTarefa;
+ Recursos.StatusProspeccao = Auxiliar.StatusProspeccao;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)186, tries);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<List<Documento>> BuscarDocumentosPorEstipulante(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.DocumentoRepository.BuscarDocumentoPorEstipulante(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)11, tries, id);
+ }
+ }
+ return new List<Documento>();
+ });
+ }
+
+ public async Task<List<Documento>> BuscarDocumentosPorStatus(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.DocumentoRepository.BuscarDocumentoPorStatus(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)12, tries, id);
+ }
+ }
+ return new List<Documento>();
+ });
+ }
+
+ public async Task<bool> TipoVendedorUtilizado(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.VendedorParcelaRepository.TipoVendedorUtilizado(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)155, tries, id);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<bool> BancosContasUtilizado(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.LancamentoRepository.BancosContasUtilizado(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)155, tries, id);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<bool> ParceiroUtilizado(long id)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.SinistroAutoRepository.ParceiroUtilizado(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)156, tries, id);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<List<Credencial>> BuscarCredenciais()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.CredencialRepository.Find(((DomainBase)Recursos.Empresa).Id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)187, tries);
+ }
+ }
+ return new List<Credencial>();
+ });
+ }
+
+ public async Task<List<Centro>> BuscarCentroAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.CentroRepository.Find()
+ orderby x.Descricao
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)153, tries);
+ }
+ }
+ return new List<Centro>();
+ });
+ }
+
+ public async Task<List<Plano>> BuscarPlanoAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Plano>(from x in read.PlanoRepository.Find()
+ orderby x.Descricao
+ select x);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)167, tries);
+ }
+ }
+ return new List<Plano>();
+ });
+ }
+
+ public async Task<List<Planos>> BuscarPlanosAsync()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return new List<Planos>(read.PlanosRepository.Find());
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)168, tries);
+ }
+ }
+ return new List<Planos>();
+ });
+ }
+
+ public async Task<List<Fornecedor>> BuscarFornecedor(string value, bool ativo = false)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.FornecedorRepository.Find(value, ativo)
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)159, tries, value);
+ }
+ }
+ return new List<Fornecedor>();
+ });
+ }
+
+ public async Task<List<Fornecedor>> BuscarFornecedor()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return (from x in read.FornecedorRepository.Find()
+ orderby x.Nome
+ select x).ToList();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)166, tries);
+ }
+ }
+ return new List<Fornecedor>();
+ });
+ }
+
+ public async Task<ControleArquivoDigital> ArquivoDigital()
+ {
+ int tries = 3;
+ return await Task.Run((Func<ControleArquivoDigital>)delegate
+ {
+ //IL_004c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0052: Expected O, but got Unknown
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.IndiceArquivoDigitalRepository.BuscarBanco();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)188, tries);
+ }
+ }
+ return new ControleArquivoDigital();
+ });
+ }
+
+ public async Task<ControleArquivoDigital> ArquivoDigital(string banco)
+ {
+ int tries = 3;
+ return await Task.Run((Func<ControleArquivoDigital>)delegate
+ {
+ //IL_0057: Unknown result type (might be due to invalid IL or missing references)
+ //IL_005d: Expected O, but got Unknown
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.IndiceArquivoDigitalRepository.ConsultarBanco(banco);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)188, tries, banco);
+ }
+ }
+ return new ControleArquivoDigital();
+ });
+ }
+
+ public async Task SalvarControle(ControleArquivoDigital controle)
+ {
+ int tries = 3;
+ await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ commited.IndiceArquivoDigitalRepository.SaveOrUpdate(controle);
+ ((GenericUnitOfWork)commited).Commit();
+ break;
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)179, tries, controle);
+ }
+ }
+ });
+ }
+
+ public async Task<ControleArquivoDigital> BuscarControle()
+ {
+ return await Task.Run((Func<ControleArquivoDigital>)delegate
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.IndiceArquivoDigitalRepository.BuscarBanco();
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception)
+ {
+ return (ControleArquivoDigital)null;
+ }
+ });
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulantes()
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ Recursos.Estipulantes = read.EstipulanteRepository.Find();
+ return Recursos.Estipulantes;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)186, tries);
+ }
+ }
+ return Recursos.Estipulantes;
+ });
+ }
+
+ public async Task<int> Sincronizar(List<DadosVinculo> dados, Filtros filtros)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ int result = commited.VinculoDocumentoRepository.Sincronize(filtros.Inicio, dados);
+ ((GenericUnitOfWork)commited).Commit();
+ return result;
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)293, tries);
+ }
+ }
+ return 0;
+ });
+ }
+
+ public async Task<int[]> Sincronizar(DateTime data, List<long> ids = null)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ int[] result = commited.ParcelaRepository.SincronizarPendencia(data, ids);
+ ((GenericUnitOfWork)commited).Commit();
+ return result;
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)300, tries, false);
+ }
+ }
+ return new int[2];
+ });
+ }
+
+ public async Task<List<ArquivoVinculo>> ArquivoVinculo(List<long> ids, TipoArquivoVinculo type)
+ {
+ //IL_001e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_001f: Unknown result type (might be due to invalid IL or missing references)
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ //IL_0016: Unknown result type (might be due to invalid IL or missing references)
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.VinculoDocumentoRepository.BuscarArquivos(ids, type);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)293, tries);
+ }
+ }
+ return (List<ArquivoVinculo>)null;
+ });
+ }
+
+ internal async Task<List<Cliente>> BuscarClienteEmpresa(string value)
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ return new List<Cliente>();
+ }
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ List<Cliente> list = (from x in read.ClienteRepository.Find(value, 0L, false, false)
+ orderby x.Nome
+ select x).ToList();
+ list.AddRange((from x in read.EmpresaRepository.FindAsCliente(value)
+ orderby x.Nome
+ select x).ToList());
+ return list;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)29, tries, value);
+ }
+ }
+ return new List<Cliente>();
+ });
+ }
+
+ public async Task<ParcelaPendente> BuscarParcelaPendente(long id)
+ {
+ int tries = 3;
+ return await Task.Run((Func<ParcelaPendente>)delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.ParcelaRepository.BuscarPendencia(id);
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)299, tries, id);
+ }
+ }
+ return (ParcelaPendente)null;
+ });
+ }
+
+ public void SalvarAcao(RegistroAcao log, object obs = null)
+ {
+ //IL_00af: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b4: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00c0: Expected O, but got Unknown
+ if (log == null || ((DomainBase)Recursos.Usuario).Id == 0L)
+ {
+ return;
+ }
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ log.Usuario = Recursos.Usuario;
+ log.DataHora = Funcoes.GetNetworkTime();
+ log.Versao = LoginViewModel.VersaoAtual;
+ log.NomeMaquina = Environment.MachineName;
+ log.UsuarioMaquina = Environment.UserName;
+ log.Ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString();
+ log.Observacao = ((obs == null) ? "" : ((!(obs is string)) ? JsonConvert.SerializeObject(obs, new JsonSerializerSettings
+ {
+ ReferenceLoopHandling = (ReferenceLoopHandling)1
+ }) : obs.ToString()));
+ commited.RegistroAcaoRepository.SaveOrUpdate(log);
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ Registrar(e, (TipoErro)0, 3, log);
+ }
+ }
+
+ public async Task<List<Usuario>> CarregarUsuarios()
+ {
+ await AtualizarUsuarios();
+ return await BuscarUsuariosAsync();
+ }
+
+ private async Task AtualizarUsuarios()
+ {
+ _ = 1;
+ try
+ {
+ if (ValidationHelper.IsNullOrEmpty(Recursos.Usuario.TokenSso))
+ {
+ return;
+ }
+ List<UserSso> ssoUsuarios = await BuscarUsuariosSso();
+ if ((ssoUsuarios != null && ssoUsuarios.Count == 0) || ssoUsuarios == null)
+ {
+ return;
+ }
+ List<Usuario> source = await BuscarUsuariosAsync();
+ foreach (UserSso ssoUsuario in ssoUsuarios)
+ {
+ Usuario val = ((IEnumerable<Usuario>)source).FirstOrDefault((Func<Usuario, bool>)((Usuario u) => (u.SsoId != null) ? (ssoUsuario.Id == u.SsoId) : (u.Login == ssoUsuario.Username)));
+ if (val != null && (ssoUsuario.IsDeleted != val.Excluido || ValidationHelper.NotEquals(ssoUsuario.Password, val.Senha) || ValidationHelper.NotEquals(ssoUsuario.Name, val.Nome) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Email) && ValidationHelper.NotEquals(ssoUsuario.Email, val.Email)) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Document) && ValidationHelper.NotEquals(ssoUsuario.Document, val.Documento.Clear())) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Phone) && ValidationHelper.NotEquals(ssoUsuario.Phone, (val.Prefixo + val.Telefone).Clear())) || ValidationHelper.IsNullOrEmpty(val.SsoId)))
+ {
+ string phone = ssoUsuario.Phone;
+ val.Nome = ssoUsuario.Name;
+ val.Documento = ssoUsuario.Document;
+ if (ValidationHelper.IsNotNullOrEmpty(phone) && phone.Length > 3)
+ {
+ val.Prefixo = phone.Substring(0, 2);
+ val.Telefone = phone.Substring(2, phone.Length - 2);
+ }
+ val.Login = ssoUsuario.Username;
+ val.Senha = ssoUsuario.Password;
+ val.Email = ssoUsuario.Email;
+ val.Excluido = ssoUsuario.IsDeleted;
+ val.SsoId = ssoUsuario.Id;
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ commited.UsuarioRepository.Merge(val);
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ }
+ if (val != null)
+ {
+ continue;
+ }
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ Empresa val2 = read.EmpresaRepository.FindByDocumento(ssoUsuario.CustomerDocument);
+ val = new Usuario
+ {
+ IdEmpresa = ((DomainBase)val2).Id,
+ Nome = ssoUsuario.Name,
+ Documento = ssoUsuario.Document,
+ Login = ssoUsuario.Username,
+ Senha = ssoUsuario.Password,
+ Email = ssoUsuario.Email,
+ SsoId = ssoUsuario.Id,
+ Excluido = ssoUsuario.IsDeleted,
+ Administrador = false,
+ PermissaoAggilizador = 1L
+ };
+ string phone2 = ssoUsuario.Phone;
+ if (ValidationHelper.IsNotNullOrEmpty(phone2) && phone2.Length > 3)
+ {
+ val.Prefixo = phone2.Substring(0, 2);
+ val.Telefone = phone2.Substring(2, phone2.Length - 2);
+ }
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ UnitOfWork commited2 = Instancia.Commited;
+ try
+ {
+ commited2.UsuarioRepository.SaveOrUpdate(val);
+ ((GenericUnitOfWork)commited2).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited2)?.Dispose();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ Registrar(e, (TipoErro)239, 1);
+ }
+ }
+
+ private static async Task AtualizaUsuariosSso(List<Usuario> usuarios)
+ {
+ usuarios = usuarios.Where((Usuario usuario) => !usuario.Excluido)?.ToList();
+ foreach (Usuario usuarioBanco in usuarios)
+ {
+ new UserSso
+ {
+ Name = usuarioBanco.Nome,
+ Username = usuarioBanco.Login,
+ Password = usuarioBanco.Senha,
+ Email = usuarioBanco.Email,
+ Phone = usuarioBanco.Telefone,
+ IsDeleted = usuarioBanco.Excluido,
+ Id = usuarioBanco.SsoId
+ };
+ string documento = ((IEnumerable<Empresa>)Recursos.Empresas).FirstOrDefault((Func<Empresa, bool>)((Empresa x) => ((DomainBase)x).Id == usuarioBanco.IdEmpresa)).Documento;
+ await new BaseServico().AddOrUpdateUsuarioSso(usuarioBanco, documento, usuarioBanco.SsoId);
+ }
+ }
+}