diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs | 2567 |
1 files changed, 2567 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs b/Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs new file mode 100644 index 0000000..1570e96 --- /dev/null +++ b/Codemerx/Gestor.Application/Servicos/Generic/BaseServico.cs @@ -0,0 +1,2567 @@ +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.Repository.Interface;
+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;
+using System;
+using System.Collections;
+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.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.Servicos.Generic
+{
+ public class BaseServico
+ {
+ private const int UnathorizedSsoCode = 401;
+
+ private const int NotFoundSsoCode = 404;
+
+ public bool Sucesso
+ {
+ get;
+ set;
+ }
+
+ public BaseServico()
+ {
+ }
+
+ internal async Task<UserSso> AddOrUpdateUsuarioSso(Usuario usuario, string documentoEmpresa, string ssoId = null)
+ {
+ UserSso userSso;
+ HttpResponseMessage httpResponseMessage;
+ UserSso userSso1;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "user" };
+ Uri uri = apiSso.Append(strArrays);
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso()));
+ UserSso userSso2 = usuario.ToUserSso(ApplicationHelper.NumeroSerial, documentoEmpresa, ssoId);
+ httpResponseMessage = (userSso2.get_Id() != null ? await httpClient.PutAsync(uri, userSso2.ToHttpContent<UserSso>(null, "application/json")) : await httpClient.PostAsync(uri, userSso2.ToHttpContent<UserSso>(null, "application/json")));
+ HttpResponseMessage httpResponseMessage1 = httpResponseMessage;
+ if (!httpResponseMessage1.get_IsSuccessStatusCode())
+ {
+ userSso1 = null;
+ }
+ else
+ {
+ userSso1 = JsonConvert.DeserializeObject<UserSso>(await httpResponseMessage1.get_Content().ReadAsStringAsync());
+ }
+ userSso = userSso1;
+ }
+ return userSso;
+ }
+
+ public async Task<ControleArquivoDigital> ArquivoDigital()
+ {
+ int num = 3;
+ ControleArquivoDigital controleArquivoDigital1 = await Task.Run<ControleArquivoDigital>(() => {
+ ControleArquivoDigital controleArquivoDigital;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().BuscarBanco();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 188, num, null, true);
+ continue;
+ }
+ return controleArquivoDigital;
+ }
+ return new ControleArquivoDigital();
+ });
+ return controleArquivoDigital1;
+ }
+
+ public async Task<ControleArquivoDigital> ArquivoDigital(string banco)
+ {
+ int num = 3;
+ ControleArquivoDigital controleArquivoDigital1 = await Task.Run<ControleArquivoDigital>(() => {
+ ControleArquivoDigital controleArquivoDigital;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().ConsultarBanco(banco);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 188, num, banco, true);
+ continue;
+ }
+ return controleArquivoDigital;
+ }
+ return new ControleArquivoDigital();
+ });
+ return controleArquivoDigital1;
+ }
+
+ public async Task<List<ArquivoVinculo>> ArquivoVinculo(List<long> ids, TipoArquivoVinculo type)
+ {
+ int num = 3;
+ List<ArquivoVinculo> arquivoVinculos1 = await Task.Run<List<ArquivoVinculo>>(() => {
+ List<ArquivoVinculo> arquivoVinculos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ arquivoVinculos = read.get_VinculoDocumentoRepository().BuscarArquivos(ids, type);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 293, num, null, true);
+ continue;
+ }
+ return arquivoVinculos;
+ }
+ return null;
+ });
+ return arquivoVinculos1;
+ }
+
+ private async Task AtualizarUsuarios()
+ {
+ bool count;
+ try
+ {
+ if (!Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(Recursos.Usuario.get_TokenSso()))
+ {
+ List<UserSso> userSsos = await this.BuscarUsuariosSso();
+ List<UserSso> userSsos1 = userSsos;
+ if (userSsos1 != null)
+ {
+ count = userSsos1.Count == 0;
+ }
+ else
+ {
+ count = false;
+ }
+ if (count || userSsos == null)
+ {
+ return;
+ }
+ else
+ {
+ List<Usuario> usuarios = await this.BuscarUsuariosAsync();
+ foreach (UserSso userSso in userSsos)
+ {
+ Usuario usuario = usuarios.FirstOrDefault<Usuario>((Usuario u) => {
+ if (u.get_SsoId() != null)
+ {
+ return userSso.get_Id() == u.get_SsoId();
+ }
+ return u.get_Login() == userSso.get_Username();
+ });
+ if (usuario != null && (userSso.get_IsDeleted() != usuario.get_Excluido() || Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Password(), usuario.get_Senha()) || Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Name(), usuario.get_Nome()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Email()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Email(), usuario.get_Email()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Document()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Document(), usuario.get_Documento().Clear()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Phone()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Phone(), string.Concat(usuario.get_Prefixo(), usuario.get_Telefone()).Clear()) || Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(usuario.get_SsoId())))
+ {
+ string phone = userSso.get_Phone();
+ usuario.set_Nome(userSso.get_Name());
+ usuario.set_Documento(userSso.get_Document());
+ if (Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(phone) && phone.Length > 3)
+ {
+ usuario.set_Prefixo(phone.Substring(0, 2));
+ usuario.set_Telefone(phone.Substring(2, phone.Length - 2));
+ }
+ usuario.set_Login(userSso.get_Username());
+ usuario.set_Senha(userSso.get_Password());
+ usuario.set_Email(userSso.get_Email());
+ usuario.set_Excluido(userSso.get_IsDeleted());
+ usuario.set_SsoId(userSso.get_Id());
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_UsuarioRepository().Merge(usuario);
+ commited.Commit();
+ }
+ }
+ if (usuario != null)
+ {
+ continue;
+ }
+ using (UnitOfWork read = Instancia.Read)
+ {
+ Empresa empresa = read.get_EmpresaRepository().FindByDocumento(userSso.get_CustomerDocument());
+ Usuario usuario1 = new Usuario();
+ usuario1.set_IdEmpresa(empresa.get_Id());
+ usuario1.set_Nome(userSso.get_Name());
+ usuario1.set_Documento(userSso.get_Document());
+ usuario1.set_Login(userSso.get_Username());
+ usuario1.set_Senha(userSso.get_Password());
+ usuario1.set_Email(userSso.get_Email());
+ usuario1.set_SsoId(userSso.get_Id());
+ usuario1.set_Excluido(userSso.get_IsDeleted());
+ usuario1.set_Administrador(false);
+ usuario1.set_PermissaoAggilizador(new long?((long)1));
+ usuario = usuario1;
+ string str = userSso.get_Phone();
+ if (Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(str) && str.Length > 3)
+ {
+ usuario.set_Prefixo(str.Substring(0, 2));
+ usuario.set_Telefone(str.Substring(2, str.Length - 2));
+ }
+ }
+ using (UnitOfWork unitOfWork = Instancia.Commited)
+ {
+ unitOfWork.get_UsuarioRepository().SaveOrUpdate(usuario);
+ unitOfWork.Commit();
+ }
+ }
+ userSsos = null;
+ }
+ }
+ else
+ {
+ return;
+ }
+ }
+ catch (Exception exception)
+ {
+ this.Registrar(exception, 239, 1, null, true);
+ }
+ }
+
+ private static async Task AtualizaUsuariosSso(List<Usuario> usuarios)
+ {
+ List<Usuario> list;
+ List<Usuario> usuarios1 = usuarios;
+ IEnumerable<Usuario> excluido =
+ from usuario in usuarios1
+ where !usuario.get_Excluido()
+ select usuario;
+ if (excluido != null)
+ {
+ list = excluido.ToList<Usuario>();
+ }
+ else
+ {
+ list = null;
+ }
+ usuarios = list;
+ foreach (Usuario usuario1 in usuarios)
+ {
+ UserSso userSso = new UserSso();
+ userSso.set_Name(usuario1.get_Nome());
+ userSso.set_Username(usuario1.get_Login());
+ userSso.set_Password(usuario1.get_Senha());
+ userSso.set_Email(usuario1.get_Email());
+ userSso.set_Phone(usuario1.get_Telefone());
+ userSso.set_IsDeleted(usuario1.get_Excluido());
+ userSso.set_Id(usuario1.get_SsoId());
+ string documento = Recursos.Empresas.FirstOrDefault<Empresa>((Empresa x) => x.get_Id() == usuario1.get_IdEmpresa()).get_Documento();
+ await (new BaseServico()).AddOrUpdateUsuarioSso(usuario1, documento, usuario1.get_SsoId());
+ }
+ }
+
+ public async Task<bool> BancosContasUtilizado(long id)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ flag = read.get_LancamentoRepository().BancosContasUtilizado(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 155, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ internal async Task<List<CoberturaPadrao>> BuscaCoberturas()
+ {
+ int num = 3;
+ List<CoberturaPadrao> coberturaPadraos1 = await Task.Run<List<CoberturaPadrao>>(() => {
+ List<CoberturaPadrao> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<CoberturaPadrao> coberturaPadraos = read.get_CoberturaPadraoRepository().Find();
+ Func<CoberturaPadrao, string> u003cu003e9_511 = BaseServico.u003cu003ec.u003cu003e9__51_1;
+ if (u003cu003e9_511 == null)
+ {
+ u003cu003e9_511 = (CoberturaPadrao x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__51_1 = u003cu003e9_511;
+ }
+ list = coberturaPadraos.OrderBy<CoberturaPadrao, string>(u003cu003e9_511).ToList<CoberturaPadrao>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 58, num, null, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<CoberturaPadrao>();
+ });
+ return coberturaPadraos1;
+ }
+
+ public async Task<List<Adiantamento>> BuscarAdiantamentoAsync(Vendedor vendedor)
+ {
+ int num = 3;
+ List<Adiantamento> adiantamentos2 = await Task.Run<List<Adiantamento>>(() => {
+ List<Adiantamento> adiantamentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Adiantamento> adiantamentos1 = read.get_AdiantamentoRepository().Find(vendedor.get_Id());
+ Func<Adiantamento, long> u003cu003e9_371 = BaseServico.u003cu003ec.u003cu003e9__37_1;
+ if (u003cu003e9_371 == null)
+ {
+ u003cu003e9_371 = (Adiantamento x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__37_1 = u003cu003e9_371;
+ }
+ adiantamentos = new List<Adiantamento>(adiantamentos1.OrderBy<Adiantamento, long>(u003cu003e9_371));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 185, num, vendedor, true);
+ continue;
+ }
+ return adiantamentos;
+ }
+ return new List<Adiantamento>();
+ });
+ return adiantamentos2;
+ }
+
+ public async Task<List<Agenda>> BuscarAgendasAsync()
+ {
+ int num = 3;
+ List<Agenda> agendas2 = await Task.Run<List<Agenda>>(() => {
+ List<Agenda> agendas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Agenda> agendas1 = read.get_AgendaRepository().Find();
+ Func<Agenda, long> u003cu003e9_461 = BaseServico.u003cu003ec.u003cu003e9__46_1;
+ if (u003cu003e9_461 == null)
+ {
+ u003cu003e9_461 = (Agenda x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__46_1 = u003cu003e9_461;
+ }
+ agendas = new List<Agenda>(agendas1.OrderBy<Agenda, long>(u003cu003e9_461));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 129, num, null, true);
+ continue;
+ }
+ return agendas;
+ }
+ return new List<Agenda>();
+ });
+ return agendas2;
+ }
+
+ internal async Task<List<Atividade>> BuscarAtividade(string value)
+ {
+ int num = 3;
+ List<Atividade> atividades1 = await Task.Run<List<Atividade>>(() => {
+ List<Atividade> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Atividade> atividades = read.get_AtividadeRepository().Find(value);
+ Func<Atividade, string> u003cu003e9_161 = BaseServico.u003cu003ec.u003cu003e9__16_1;
+ if (u003cu003e9_161 == null)
+ {
+ u003cu003e9_161 = (Atividade x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__16_1 = u003cu003e9_161;
+ }
+ list = atividades.OrderBy<Atividade, string>(u003cu003e9_161).ToList<Atividade>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 181, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Atividade>();
+ });
+ return atividades1;
+ }
+
+ internal async Task<List<Banco>> BuscarBanco(string value)
+ {
+ int num = 3;
+ List<Banco> bancos1 = await Task.Run<List<Banco>>(() => {
+ List<Banco> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Banco> bancos = read.get_BancoRepository().Find(value);
+ Func<Banco, string> u003cu003e9_171 = BaseServico.u003cu003ec.u003cu003e9__17_1;
+ if (u003cu003e9_171 == null)
+ {
+ u003cu003e9_171 = (Banco x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__17_1 = u003cu003e9_171;
+ }
+ list = bancos.OrderBy<Banco, string>(u003cu003e9_171).ToList<Banco>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 144, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Banco>();
+ });
+ return bancos1;
+ }
+
+ internal async Task<List<BancosContas>> BuscarBancosContas(string value)
+ {
+ int num = 3;
+ List<BancosContas> bancosContas1 = await Task.Run<List<BancosContas>>(() => {
+ List<BancosContas> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<BancosContas> bancosContas = read.get_BancosContasRepository().Find(value);
+ Func<BancosContas, string> u003cu003e9_181 = BaseServico.u003cu003ec.u003cu003e9__18_1;
+ if (u003cu003e9_181 == null)
+ {
+ u003cu003e9_181 = (BancosContas x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__18_1 = u003cu003e9_181;
+ }
+ list = bancosContas.OrderBy<BancosContas, string>(u003cu003e9_181).ToList<BancosContas>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 146, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<BancosContas>();
+ });
+ return bancosContas1;
+ }
+
+ public async Task<List<Centro>> BuscarCentroAsync()
+ {
+ int num = 3;
+ List<Centro> centros1 = await Task.Run<List<Centro>>(() => {
+ List<Centro> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Centro> centros = read.get_CentroRepository().Find();
+ Func<Centro, string> u003cu003e9_601 = BaseServico.u003cu003ec.u003cu003e9__60_1;
+ if (u003cu003e9_601 == null)
+ {
+ u003cu003e9_601 = (Centro x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__60_1 = u003cu003e9_601;
+ }
+ list = centros.OrderBy<Centro, string>(u003cu003e9_601).ToList<Centro>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 153, num, null, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Centro>();
+ });
+ return centros1;
+ }
+
+ internal async Task<List<Cliente>> BuscarClienteEmpresa(string value)
+ {
+ List<Cliente> clientes3;
+ if (!string.IsNullOrWhiteSpace(value))
+ {
+ int num = 3;
+ clientes3 = await Task.Run<List<Cliente>>(() => {
+ List<Cliente> clientes;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Cliente> clientes1 = read.get_ClienteRepository().Find(value, (long)0, false, false);
+ Func<Cliente, string> u003cu003e9_731 = BaseServico.u003cu003ec.u003cu003e9__73_1;
+ if (u003cu003e9_731 == null)
+ {
+ u003cu003e9_731 = (Cliente x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__73_1 = u003cu003e9_731;
+ }
+ List<Cliente> list = clientes1.OrderBy<Cliente, string>(u003cu003e9_731).ToList<Cliente>();
+ List<Cliente> clientes2 = read.get_EmpresaRepository().FindAsCliente(value);
+ Func<Cliente, string> u003cu003e9_732 = BaseServico.u003cu003ec.u003cu003e9__73_2;
+ if (u003cu003e9_732 == null)
+ {
+ u003cu003e9_732 = (Cliente x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__73_2 = u003cu003e9_732;
+ }
+ list.AddRange(clientes2.OrderBy<Cliente, string>(u003cu003e9_732).ToList<Cliente>());
+ clientes = list;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 29, num, value, true);
+ continue;
+ }
+ return clientes;
+ }
+ return new List<Cliente>();
+ });
+ }
+ else
+ {
+ clientes3 = new List<Cliente>();
+ }
+ return clientes3;
+ }
+
+ public async Task<ControleArquivoDigital> BuscarControle()
+ {
+ ControleArquivoDigital controleArquivoDigital1 = await Task.Run<ControleArquivoDigital>(() => {
+ ControleArquivoDigital controleArquivoDigital;
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().BuscarBanco();
+ }
+ }
+ catch (Exception exception)
+ {
+ controleArquivoDigital = null;
+ }
+ return controleArquivoDigital;
+ });
+ return controleArquivoDigital1;
+ }
+
+ public async Task<List<Credencial>> BuscarCredenciais()
+ {
+ int num = 3;
+ List<Credencial> credencials1 = await Task.Run<List<Credencial>>(() => {
+ List<Credencial> credencials;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ credencials = read.get_CredencialRepository().Find(Recursos.Empresa.get_Id());
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 187, num, null, true);
+ continue;
+ }
+ return credencials;
+ }
+ return new List<Credencial>();
+ });
+ return credencials1;
+ }
+
+ public async Task<List<Documento>> BuscarDocumentosPorEstipulante(long id)
+ {
+ int num = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(() => {
+ List<Documento> documentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documentos = read.get_DocumentoRepository().BuscarDocumentoPorEstipulante(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 11, num, id, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Documento>> BuscarDocumentosPorStatus(long id)
+ {
+ int num = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(() => {
+ List<Documento> documentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documentos = read.get_DocumentoRepository().BuscarDocumentoPorStatus(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 12, num, id, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ internal Empresa BuscarEmpresa(long id)
+ {
+ Empresa empresa;
+ int num = 3;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ empresa = read.get_EmpresaRepository().FindById(id);
+ }
+ }
+ catch (Exception exception1)
+ {
+ Exception exception = exception1;
+ num = this.Registrar(exception, 114, num, id, true);
+ continue;
+ }
+ return empresa;
+ }
+ return new Empresa();
+ }
+
+ public async Task<List<Empresa>> BuscarEmpresasAsync()
+ {
+ int num = 3;
+ List<Empresa> empresas2 = await Task.Run<List<Empresa>>(() => {
+ List<Empresa> empresas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Empresa> empresas1 = read.get_EmpresaRepository().Find((long)0);
+ Func<Empresa, long> u003cu003e9_251 = BaseServico.u003cu003ec.u003cu003e9__25_1;
+ if (u003cu003e9_251 == null)
+ {
+ u003cu003e9_251 = (Empresa x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__25_1 = u003cu003e9_251;
+ }
+ empresas = new List<Empresa>(empresas1.OrderBy<Empresa, long>(u003cu003e9_251));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 113, num, null, true);
+ continue;
+ }
+ return empresas;
+ }
+ return new List<Empresa>();
+ });
+ return empresas2;
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulante(string value)
+ {
+ int num = 3;
+ List<Estipulante> estipulantes1 = await Task.Run<List<Estipulante>>(() => {
+ List<Estipulante> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Estipulante> estipulantes = read.get_EstipulanteRepository().Find(value, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()));
+ Func<Estipulante, string> u003cu003e9_221 = BaseServico.u003cu003ec.u003cu003e9__22_1;
+ if (u003cu003e9_221 == null)
+ {
+ u003cu003e9_221 = (Estipulante x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__22_1 = u003cu003e9_221;
+ }
+ list = estipulantes.OrderBy<Estipulante, string>(u003cu003e9_221).ToList<Estipulante>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 111, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Estipulante>();
+ });
+ return estipulantes1;
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulantes()
+ {
+ int num = 3;
+ List<Estipulante> estipulantes1 = await Task.Run<List<Estipulante>>(() => {
+ List<Estipulante> estipulantes;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ Recursos.Estipulantes = read.get_EstipulanteRepository().Find();
+ estipulantes = Recursos.Estipulantes;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 186, num, null, true);
+ continue;
+ }
+ return estipulantes;
+ }
+ return Recursos.Estipulantes;
+ });
+ return estipulantes1;
+ }
+
+ public async Task<List<Estipulante>> BuscarEstipulantesAsync()
+ {
+ int num = 3;
+ List<Estipulante> estipulantes2 = await Task.Run<List<Estipulante>>(() => {
+ List<Estipulante> estipulantes;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Estipulante> estipulantes1 = read.get_EstipulanteRepository().Find();
+ Func<Estipulante, long> u003cu003e9_231 = BaseServico.u003cu003ec.u003cu003e9__23_1;
+ if (u003cu003e9_231 == null)
+ {
+ u003cu003e9_231 = (Estipulante x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__23_1 = u003cu003e9_231;
+ }
+ estipulantes = new List<Estipulante>(estipulantes1.OrderBy<Estipulante, long>(u003cu003e9_231));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 112, num, null, true);
+ continue;
+ }
+ return estipulantes;
+ }
+ return new List<Estipulante>();
+ });
+ return estipulantes2;
+ }
+
+ internal async Task<List<Fabricante>> BuscarFabricante(string value)
+ {
+ int num = 3;
+ List<Fabricante> fabricantes1 = await Task.Run<List<Fabricante>>(() => {
+ List<Fabricante> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Fabricante> fabricantes = read.get_FabricanteRepository().Find(value);
+ Func<Fabricante, string> u003cu003e9_191 = BaseServico.u003cu003ec.u003cu003e9__19_1;
+ if (u003cu003e9_191 == null)
+ {
+ u003cu003e9_191 = (Fabricante x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__19_1 = u003cu003e9_191;
+ }
+ list = fabricantes.OrderBy<Fabricante, string>(u003cu003e9_191).ToList<Fabricante>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 182, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Fabricante>();
+ });
+ return fabricantes1;
+ }
+
+ public async Task<List<Fornecedor>> BuscarFornecedor(string value, bool ativo = false)
+ {
+ int num = 3;
+ List<Fornecedor> fornecedors1 = await Task.Run<List<Fornecedor>>(() => {
+ List<Fornecedor> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Fornecedor> fornecedors = read.get_FornecedorRepository().Find(value, ativo);
+ Func<Fornecedor, string> u003cu003e9_631 = BaseServico.u003cu003ec.u003cu003e9__63_1;
+ if (u003cu003e9_631 == null)
+ {
+ u003cu003e9_631 = (Fornecedor x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__63_1 = u003cu003e9_631;
+ }
+ list = fornecedors.OrderBy<Fornecedor, string>(u003cu003e9_631).ToList<Fornecedor>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 159, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Fornecedor>();
+ });
+ return fornecedors1;
+ }
+
+ public async Task<List<Fornecedor>> BuscarFornecedor()
+ {
+ int num = 3;
+ List<Fornecedor> fornecedors1 = await Task.Run<List<Fornecedor>>(() => {
+ List<Fornecedor> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Fornecedor> fornecedors = read.get_FornecedorRepository().Find();
+ Func<Fornecedor, string> u003cu003e9_641 = BaseServico.u003cu003ec.u003cu003e9__64_1;
+ if (u003cu003e9_641 == null)
+ {
+ u003cu003e9_641 = (Fornecedor x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__64_1 = u003cu003e9_641;
+ }
+ list = fornecedors.OrderBy<Fornecedor, string>(u003cu003e9_641).ToList<Fornecedor>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 166, num, null, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Fornecedor>();
+ });
+ return fornecedors1;
+ }
+
+ public async Task<List<MetaSeguradora>> BuscarMetaSeguradoraAsync(Seguradora seguradora)
+ {
+ int num = 3;
+ List<MetaSeguradora> metaSeguradoras2 = await Task.Run<List<MetaSeguradora>>(() => {
+ List<MetaSeguradora> metaSeguradoras;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<MetaSeguradora> metaSeguradoras1 = read.get_MetaSeguradoraRepository().Find(seguradora.get_Id());
+ Func<MetaSeguradora, long> u003cu003e9_381 = BaseServico.u003cu003ec.u003cu003e9__38_1;
+ if (u003cu003e9_381 == null)
+ {
+ u003cu003e9_381 = (MetaSeguradora x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__38_1 = u003cu003e9_381;
+ }
+ metaSeguradoras = new List<MetaSeguradora>(metaSeguradoras1.OrderBy<MetaSeguradora, long>(u003cu003e9_381));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 184, num, seguradora, true);
+ continue;
+ }
+ return metaSeguradoras;
+ }
+ return new List<MetaSeguradora>();
+ });
+ return metaSeguradoras2;
+ }
+
+ public async Task<List<MetaVendedor>> BuscarMetaVendedorAsync(Vendedor vendedor)
+ {
+ int num = 3;
+ List<MetaVendedor> metaVendedors2 = await Task.Run<List<MetaVendedor>>(() => {
+ List<MetaVendedor> metaVendedors;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<MetaVendedor> metaVendedors1 = read.get_MetaVendedorRepository().Find(vendedor.get_Id());
+ Func<MetaVendedor, long> u003cu003e9_361 = BaseServico.u003cu003ec.u003cu003e9__36_1;
+ if (u003cu003e9_361 == null)
+ {
+ u003cu003e9_361 = (MetaVendedor x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__36_1 = u003cu003e9_361;
+ }
+ metaVendedors = new List<MetaVendedor>(metaVendedors1.OrderBy<MetaVendedor, long>(u003cu003e9_361));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 183, num, vendedor, true);
+ continue;
+ }
+ return metaVendedors;
+ }
+ return new List<MetaVendedor>();
+ });
+ return metaVendedors2;
+ }
+
+ public async Task<List<Parceiro>> BuscarParceirosAsync()
+ {
+ int num = 3;
+ List<Parceiro> parceiros2 = await Task.Run<List<Parceiro>>(() => {
+ List<Parceiro> parceiros;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Parceiro> parceiros1 = read.get_ParceiroRepository().Find();
+ Func<Parceiro, long> u003cu003e9_351 = BaseServico.u003cu003ec.u003cu003e9__35_1;
+ if (u003cu003e9_351 == null)
+ {
+ u003cu003e9_351 = (Parceiro x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__35_1 = u003cu003e9_351;
+ }
+ parceiros = new List<Parceiro>(parceiros1.OrderBy<Parceiro, long>(u003cu003e9_351));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 72, num, null, true);
+ continue;
+ }
+ return parceiros;
+ }
+ return new List<Parceiro>();
+ });
+ return parceiros2;
+ }
+
+ public async Task<ParcelaPendente> BuscarParcelaPendente(long id)
+ {
+ int num = 3;
+ ParcelaPendente parcelaPendente1 = await Task.Run<ParcelaPendente>(() => {
+ ParcelaPendente parcelaPendente;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcelaPendente = read.get_ParcelaRepository().BuscarPendencia(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 299, num, id, true);
+ continue;
+ }
+ return parcelaPendente;
+ }
+ return null;
+ });
+ return parcelaPendente1;
+ }
+
+ public async Task<List<Plano>> BuscarPlanoAsync()
+ {
+ int num = 3;
+ List<Plano> planos2 = await Task.Run<List<Plano>>(() => {
+ List<Plano> planos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Plano> planos1 = read.get_PlanoRepository().Find();
+ Func<Plano, string> u003cu003e9_611 = BaseServico.u003cu003ec.u003cu003e9__61_1;
+ if (u003cu003e9_611 == null)
+ {
+ u003cu003e9_611 = (Plano x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__61_1 = u003cu003e9_611;
+ }
+ planos = new List<Plano>(planos1.OrderBy<Plano, string>(u003cu003e9_611));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 167, num, null, true);
+ continue;
+ }
+ return planos;
+ }
+ return new List<Plano>();
+ });
+ return planos2;
+ }
+
+ public async Task<List<Planos>> BuscarPlanosAsync()
+ {
+ int num = 3;
+ List<Planos> planos1 = await Task.Run<List<Planos>>(() => {
+ List<Planos> planos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ planos = new List<Planos>(read.get_PlanosRepository().Find());
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 168, num, null, true);
+ continue;
+ }
+ return planos;
+ }
+ return new List<Planos>();
+ });
+ return planos1;
+ }
+
+ public async Task<List<Produto>> BuscarProduto(string value)
+ {
+ int num = 3;
+ List<Produto> produtos1 = await Task.Run<List<Produto>>(() => {
+ List<Produto> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Produto> produtos = read.get_ProdutoRepository().Find(value);
+ Func<Produto, string> u003cu003e9_411 = BaseServico.u003cu003ec.u003cu003e9__41_1;
+ if (u003cu003e9_411 == null)
+ {
+ u003cu003e9_411 = (Produto x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__41_1 = u003cu003e9_411;
+ }
+ list = produtos.OrderBy<Produto, string>(u003cu003e9_411).ToList<Produto>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 117, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Produto>();
+ });
+ return produtos1;
+ }
+
+ public async Task<List<Produto>> BuscarProdutosAsync()
+ {
+ int num = 3;
+ List<Produto> produtos2 = await Task.Run<List<Produto>>(() => {
+ List<Produto> produtos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Produto> produtos1 = read.get_ProdutoRepository().Find();
+ Func<Produto, string> u003cu003e9_491 = BaseServico.u003cu003ec.u003cu003e9__49_1;
+ if (u003cu003e9_491 == null)
+ {
+ u003cu003e9_491 = (Produto x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__49_1 = u003cu003e9_491;
+ }
+ produtos = new List<Produto>(produtos1.OrderBy<Produto, string>(u003cu003e9_491));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 118, num, null, true);
+ continue;
+ }
+ return produtos;
+ }
+ return new List<Produto>();
+ });
+ return produtos2;
+ }
+
+ internal async Task<List<Profissao>> BuscarProfissao(string value)
+ {
+ int num = 3;
+ List<Profissao> profissaos1 = await Task.Run<List<Profissao>>(() => {
+ List<Profissao> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Profissao> profissaos = read.get_ProfissaoRepository().Find(value);
+ Func<Profissao, string> u003cu003e9_151 = BaseServico.u003cu003ec.u003cu003e9__15_1;
+ if (u003cu003e9_151 == null)
+ {
+ u003cu003e9_151 = (Profissao x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__15_1 = u003cu003e9_151;
+ }
+ list = profissaos.OrderBy<Profissao, string>(u003cu003e9_151).ToList<Profissao>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 180, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Profissao>();
+ });
+ return profissaos1;
+ }
+
+ public async Task<Qualificacao> BuscarQualificacaoAsync()
+ {
+ int num = 3;
+ Qualificacao qualificacao1 = await Task.Run<Qualificacao>(() => {
+ Qualificacao qualificacao;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ qualificacao = read.get_QualificacaoRepository().FindById((long)1);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 170, num, null, true);
+ continue;
+ }
+ return qualificacao;
+ }
+ return new Qualificacao();
+ });
+ return qualificacao1;
+ }
+
+ public async Task<List<Ramo>> BuscarRamosAsync()
+ {
+ int num = 3;
+ List<Ramo> ramos2 = await Task.Run<List<Ramo>>(() => {
+ List<Ramo> ramos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Ramo> ramos1 = read.get_RamoRepository().Find();
+ Func<Ramo, string> u003cu003e9_431 = BaseServico.u003cu003ec.u003cu003e9__43_1;
+ if (u003cu003e9_431 == null)
+ {
+ u003cu003e9_431 = (Ramo x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__43_1 = u003cu003e9_431;
+ }
+ ramos = new List<Ramo>(ramos1.OrderBy<Ramo, string>(u003cu003e9_431));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 169, num, null, true);
+ continue;
+ }
+ return ramos;
+ }
+ return new List<Ramo>();
+ });
+ return ramos2;
+ }
+
+ public async Task<List<Seguradora>> BuscarSeguradorasAsync()
+ {
+ int num = 3;
+ List<Seguradora> seguradoras2 = await Task.Run<List<Seguradora>>(() => {
+ List<Seguradora> seguradoras;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Seguradora> seguradoras1 = read.get_SeguradoraRepository().Find();
+ Func<Seguradora, long> u003cu003e9_451 = BaseServico.u003cu003ec.u003cu003e9__45_1;
+ if (u003cu003e9_451 == null)
+ {
+ u003cu003e9_451 = (Seguradora x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__45_1 = u003cu003e9_451;
+ }
+ seguradoras = new List<Seguradora>(seguradoras1.OrderBy<Seguradora, long>(u003cu003e9_451));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 127, num, null, true);
+ continue;
+ }
+ return seguradoras;
+ }
+ return new List<Seguradora>();
+ });
+ return seguradoras2;
+ }
+
+ public async Task<List<Socio>> BuscarSociosAsync(long id)
+ {
+ int num = 3;
+ List<Socio> socios1 = await Task.Run<List<Socio>>(() => {
+ List<Socio> socios;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ socios = read.get_SocioRepository().FindByEmpresa(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 122, num, id, true);
+ continue;
+ }
+ return socios;
+ }
+ return new List<Socio>();
+ });
+ return socios1;
+ }
+
+ public async Task<List<Status>> BuscarStatus(string value)
+ {
+ int num = 3;
+ List<Status> statuses1 = await Task.Run<List<Status>>(() => {
+ List<Status> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Status> statuses = read.get_StatusRepository().Find(value);
+ Func<Status, string> u003cu003e9_421 = BaseServico.u003cu003ec.u003cu003e9__42_1;
+ if (u003cu003e9_421 == null)
+ {
+ u003cu003e9_421 = (Status x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__42_1 = u003cu003e9_421;
+ }
+ list = statuses.OrderBy<Status, string>(u003cu003e9_421).ToList<Status>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 120, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Status>();
+ });
+ return statuses1;
+ }
+
+ public async Task<List<Status>> BuscarStatusAsync()
+ {
+ int num = 3;
+ List<Status> statuses2 = await Task.Run<List<Status>>(() => {
+ List<Status> statuses;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Status> statuses1 = read.get_StatusRepository().Find();
+ Func<Status, string> u003cu003e9_501 = BaseServico.u003cu003ec.u003cu003e9__50_1;
+ if (u003cu003e9_501 == null)
+ {
+ u003cu003e9_501 = (Status x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__50_1 = u003cu003e9_501;
+ }
+ statuses = new List<Status>(statuses1.OrderBy<Status, string>(u003cu003e9_501));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 121, num, null, true);
+ continue;
+ }
+ return statuses;
+ }
+ return new List<Status>();
+ });
+ return statuses2;
+ }
+
+ public async Task<List<TipoVendedor>> BuscarTipoVendedoresAsync()
+ {
+ int num = 3;
+ List<TipoVendedor> tipoVendedors1 = await Task.Run<List<TipoVendedor>>(() => {
+ List<TipoVendedor> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<TipoVendedor> tipoVendedors = read.get_TipoVendedorRepository().Find();
+ Func<TipoVendedor, long> u003cu003e9_481 = BaseServico.u003cu003ec.u003cu003e9__48_1;
+ if (u003cu003e9_481 == null)
+ {
+ u003cu003e9_481 = (TipoVendedor x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__48_1 = u003cu003e9_481;
+ }
+ list = tipoVendedors.OrderBy<TipoVendedor, long>(u003cu003e9_481).ToList<TipoVendedor>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 141, num, null, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<TipoVendedor>();
+ });
+ return tipoVendedors1;
+ }
+
+ internal async Task<List<Usuario>> BuscarUsuario(string value)
+ {
+ int num = 3;
+ List<Usuario> usuarios1 = await Task.Run<List<Usuario>>(() => {
+ List<Usuario> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Usuario> usuarios = read.get_UsuarioRepository().Find(value, (long)0);
+ Func<Usuario, string> u003cu003e9_271 = BaseServico.u003cu003ec.u003cu003e9__27_1;
+ if (u003cu003e9_271 == null)
+ {
+ u003cu003e9_271 = (Usuario x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__27_1 = u003cu003e9_271;
+ }
+ list = usuarios.OrderBy<Usuario, string>(u003cu003e9_271).ToList<Usuario>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 132, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Usuario>();
+ });
+ return usuarios1;
+ }
+
+ internal async Task<Usuario> BuscarUsuario(string login, string password)
+ {
+ int num = 3;
+ string str = (new Token()).AggerEncrypt(password);
+ Usuario usuario2 = await Task.Run<Usuario>(() => {
+ Usuario usuario;
+ Usuario usuario1;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ Empresa empresa = read.get_EmpresaRepository().FindBySerial(ApplicationHelper.NumeroSerial);
+ AuthSso result = this.BuscaUsuarioSso(login, str, empresa.get_Documento()).Result;
+ if (result == null || result.get_Code() == 401)
+ {
+ usuario1 = null;
+ }
+ else if (result.get_Code() != 404)
+ {
+ usuario = read.get_UsuarioRepository().SsoId(result) ?? read.get_UsuarioRepository().FindFromSso(result.get_Data().get_User());
+ if (usuario != null)
+ {
+ if (usuario.get_Excluido())
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ usuario.set_Excluido(false);
+ commited.get_UsuarioRepository().Merge(usuario);
+ commited.Commit();
+ }
+ }
+ usuario.set_TokenSso(result.get_Data().get_Token());
+ if (!Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(usuario.get_SsoId()) || !usuario.get_SsoId().Equals(result.get_Data().get_User().get_Id()))
+ {
+ using (UnitOfWork unitOfWork = Instancia.Commited)
+ {
+ usuario.set_SsoId(result.get_Data().get_User().get_Id());
+ unitOfWork.get_UsuarioRepository().Merge(usuario);
+ unitOfWork.Commit();
+ }
+ usuario1 = usuario;
+ }
+ else
+ {
+ usuario1 = usuario;
+ }
+ }
+ else
+ {
+ using (UnitOfWork commited1 = Instancia.Commited)
+ {
+ usuario = commited1.get_UsuarioRepository().AddUsuarioFromSso(result.get_Data().get_User());
+ commited1.Commit();
+ }
+ usuario.set_TokenSso(result.get_Data().get_Token());
+ usuario1 = usuario;
+ }
+ }
+ else
+ {
+ usuario = read.get_UsuarioRepository().ValidateLogin(login, str);
+ if (usuario != null)
+ {
+ usuario.set_TokenSso(result.get_Data().get_Token());
+ UserSso userSso = this.AddOrUpdateUsuarioSso(usuario, empresa.get_Documento(), null).Result;
+ if (userSso != null)
+ {
+ using (UnitOfWork unitOfWork1 = Instancia.Commited)
+ {
+ usuario.set_SsoId(userSso.get_Id());
+ unitOfWork1.get_UsuarioRepository().Merge(usuario);
+ unitOfWork1.Commit();
+ }
+ usuario.set_TokenSso(this.BuscaUsuarioSso(login, str, empresa.get_Documento()).Result.get_Data().get_Token());
+ usuario1 = usuario;
+ }
+ else
+ {
+ usuario1 = usuario;
+ }
+ }
+ else
+ {
+ usuario1 = null;
+ }
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 134, num, null, true);
+ continue;
+ }
+ return usuario1;
+ }
+ return new Usuario();
+ });
+ return usuario2;
+ }
+
+ internal async Task<bool> BuscarUsuarioMesmoDocumento(string value, long id, long idempresa)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ flag = read.get_UsuarioRepository().FindDocUsedByDocumento(value, id, idempresa);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 134, num, value, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ internal async Task<List<Usuario>> BuscarUsuarioPorLoginInteiro(string value)
+ {
+ int num = 3;
+ List<Usuario> usuarios1 = await Task.Run<List<Usuario>>(() => {
+ List<Usuario> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Usuario> usuarios = read.get_UsuarioRepository().FindByLoginInteiro(value);
+ Func<Usuario, string> u003cu003e9_391 = BaseServico.u003cu003ec.u003cu003e9__39_1;
+ if (u003cu003e9_391 == null)
+ {
+ u003cu003e9_391 = (Usuario x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__39_1 = u003cu003e9_391;
+ }
+ list = usuarios.OrderBy<Usuario, string>(u003cu003e9_391).ToList<Usuario>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 134, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Usuario>();
+ });
+ return usuarios1;
+ }
+
+ public async Task<List<Usuario>> BuscarUsuariosAsync()
+ {
+ int num = 3;
+ List<Usuario> usuarios2 = await Task.Run<List<Usuario>>(() => {
+ List<Usuario> usuarios;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Usuario> usuarios1 = read.get_UsuarioRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()));
+ Func<Usuario, long> u003cu003e9_241 = BaseServico.u003cu003ec.u003cu003e9__24_1;
+ if (u003cu003e9_241 == null)
+ {
+ u003cu003e9_241 = (Usuario x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__24_1 = u003cu003e9_241;
+ }
+ usuarios = new List<Usuario>(usuarios1.OrderBy<Usuario, long>(u003cu003e9_241));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 131, num, null, true);
+ continue;
+ }
+ return usuarios;
+ }
+ return new List<Usuario>();
+ });
+ return usuarios2;
+ }
+
+ public async Task<List<UserSso>> BuscarUsuariosSso()
+ {
+ List<UserSso> userSsos;
+ List<UserSso> userSsos1;
+ try
+ {
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "user" };
+ Uri uri = apiSso.Append(strArrays);
+ string[] strArrays1 = new string[] { "onlyempresa" };
+ Uri uri1 = uri.Append(strArrays1);
+ string[] strArrays2 = new string[] { "list" };
+ Uri uri2 = uri1.Append(strArrays2);
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", Recursos.Usuario.get_TokenSso()));
+ HttpResponseMessage async = await httpClient.GetAsync(uri2);
+ if (!async.get_IsSuccessStatusCode())
+ {
+ userSsos1 = null;
+ }
+ else
+ {
+ userSsos1 = JsonConvert.DeserializeObject<List<UserSso>>(await async.get_Content().ReadAsStringAsync());
+ }
+ userSsos = userSsos1;
+ }
+ }
+ catch
+ {
+ userSsos = new List<UserSso>();
+ }
+ return userSsos;
+ }
+
+ internal async Task<List<Vendedor>> BuscarVendedor(string value)
+ {
+ int num = 3;
+ List<Vendedor> vendedors1 = await Task.Run<List<Vendedor>>(() => {
+ List<Vendedor> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Vendedor> vendedors = read.get_VendedorRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()));
+ Func<Vendedor, string> u003cu003e9_211 = BaseServico.u003cu003ec.u003cu003e9__21_1;
+ if (u003cu003e9_211 == null)
+ {
+ u003cu003e9_211 = (Vendedor x) => x.get_Nome();
+ BaseServico.u003cu003ec.u003cu003e9__21_1 = u003cu003e9_211;
+ }
+ list = vendedors.OrderBy<Vendedor, string>(u003cu003e9_211).ToList<Vendedor>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 140, num, value, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Vendedor>();
+ });
+ return vendedors1;
+ }
+
+ public async Task<List<Vendedor>> BuscarVendedoresAsync()
+ {
+ int num = 3;
+ List<Vendedor> vendedors2 = await Task.Run<List<Vendedor>>(() => {
+ List<Vendedor> vendedors;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Vendedor> vendedors1 = read.get_VendedorRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()));
+ Func<Vendedor, long> u003cu003e9_471 = BaseServico.u003cu003ec.u003cu003e9__47_1;
+ if (u003cu003e9_471 == null)
+ {
+ u003cu003e9_471 = (Vendedor x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__47_1 = u003cu003e9_471;
+ }
+ vendedors = new List<Vendedor>(vendedors1.OrderBy<Vendedor, long>(u003cu003e9_471));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 140, num, null, true);
+ continue;
+ }
+ return vendedors;
+ }
+ return new List<Vendedor>();
+ });
+ return vendedors2;
+ }
+
+ private async Task<bool> BuscaUsuarioByToken(Usuario usuario)
+ {
+ bool flag;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "user" };
+ Uri uri = apiSso.Append(strArrays);
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso()));
+ JsonConvert.DeserializeObject<UserSso>(await await httpClient.GetAsync(uri).get_Content().ReadAsStringAsync());
+ flag = true;
+ }
+ return flag;
+ }
+
+ internal async Task<AuthSso> BuscaUsuarioSso(string login, string password, string documentoEmpresa)
+ {
+ AuthSso authSso;
+ AuthSso authSso1;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "auth" };
+ Uri uri = apiSso.Append(strArrays);
+ object[] ticks = new object[] { login, password, ApplicationHelper.NumeroSerial, documentoEmpresa, null };
+ DateTime universalTime = Funcoes.GetNetworkTime().ToUniversalTime();
+ ticks[4] = universalTime.Ticks;
+ string base64BasicEncode = string.Format("{0}:{1}:{2}:{3}:{4}", ticks).ToBase64BasicEncode();
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", base64BasicEncode);
+ HttpResponseMessage async = await httpClient.GetAsync(uri);
+ if (!async.get_IsSuccessStatusCode())
+ {
+ authSso1 = null;
+ }
+ else
+ {
+ authSso1 = JsonConvert.DeserializeObject<AuthSso>(await async.get_Content().ReadAsStringAsync());
+ }
+ authSso = authSso1;
+ }
+ return authSso;
+ }
+
+ public async Task<List<Usuario>> CarregarUsuarios()
+ {
+ await this.AtualizarUsuarios();
+ return await this.BuscarUsuariosAsync();
+ }
+
+ public RegistroLog CreateDynamicLog(long id, dynamic lista, TipoTela tela)
+ {
+ RegistroLog registroLog;
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ try
+ {
+ List<Diferenca> diferencas = new List<Diferenca>();
+ List<ValorOriginal> valorOriginals = new List<ValorOriginal>();
+ foreach (dynamic listum in (IEnumerable)lista)
+ {
+ if (listum == (dynamic)null)
+ {
+ continue;
+ }
+ if (!listum.GetType().Name.ToUpper().StartsWith("LIST"))
+ {
+ try
+ {
+ diferencas.AddRange(this.DynamicObjeto(listum));
+ }
+ catch
+ {
+ }
+ }
+ else
+ {
+ foreach (dynamic obj1 in (IEnumerable)listum)
+ {
+ try
+ {
+ if (obj1.Id != 0)
+ {
+ diferencas.AddRange(this.DynamicObjeto(obj1));
+ }
+ else
+ {
+ valorOriginals.AddRange(obj1.GetValorOriginal());
+ }
+ }
+ catch
+ {
+ }
+ }
+ }
+ }
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ if (diferencas == null || diferencas.Count != 0)
+ {
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ str = JsonConvert.SerializeObject(diferencas, jsonSerializerSetting).Replace("]", ",").Replace("[", "");
+ }
+ else
+ {
+ str = "";
+ }
+ string str4 = str;
+ if (valorOriginals == null || valorOriginals.Count != 0)
+ {
+ JsonSerializerSettings jsonSerializerSetting1 = new JsonSerializerSettings();
+ jsonSerializerSetting1.set_ReferenceLoopHandling(1);
+ str1 = JsonConvert.SerializeObject(valorOriginals, jsonSerializerSetting1).Replace("]", "").Replace("[", "");
+ }
+ else
+ {
+ str1 = "";
+ }
+ string str5 = str1;
+ RegistroLog registroLog1 = new RegistroLog();
+ registroLog1.set_Acao(1);
+ registroLog1.set_Usuario(Recursos.Usuario);
+ registroLog1.set_DataHora(networkTime);
+ if (!string.IsNullOrEmpty(str4) || !string.IsNullOrEmpty(str5))
+ {
+ str2 = string.Concat("[", str4, str5, "]");
+ }
+ else
+ {
+ str2 = null;
+ }
+ registroLog1.set_Descricao(str2);
+ registroLog1.set_EntidadeId(id);
+ registroLog1.set_Tela(tela);
+ registroLog1.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog1.set_NomeMaquina(Environment.MachineName);
+ registroLog1.set_UsuarioMaquina(Environment.UserName);
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Recursos.Host.AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str3 = pAddress.ToString();
+ }
+ else
+ {
+ str3 = null;
+ }
+ registroLog1.set_Ip(str3);
+ registroLog1.set_ModeloNovo(true);
+ registroLog = registroLog1;
+ }
+ catch (Exception exception)
+ {
+ registroLog = null;
+ }
+ return registroLog;
+ }
+
+ public RegistroLog CreateLog(long id, dynamic obj, TipoTela tela)
+ {
+ RegistroLog registroLog;
+ string str;
+ string str1;
+ try
+ {
+ List<Diferenca> diferencas = (List<Diferenca>)obj.Compare();
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ RegistroLog registroLog1 = new RegistroLog();
+ registroLog1.set_Acao(1);
+ registroLog1.set_Usuario(Recursos.Usuario);
+ registroLog1.set_DataHora(networkTime);
+ if (diferencas == null || diferencas.Count != 0)
+ {
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ str = JsonConvert.SerializeObject(diferencas, jsonSerializerSetting);
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog1.set_Descricao(str);
+ registroLog1.set_EntidadeId(id);
+ registroLog1.set_Tela(tela);
+ registroLog1.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog1.set_NomeMaquina(Environment.MachineName);
+ registroLog1.set_UsuarioMaquina(Environment.UserName);
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Recursos.Host.AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str1 = pAddress.ToString();
+ }
+ else
+ {
+ str1 = null;
+ }
+ registroLog1.set_Ip(str1);
+ registroLog1.set_ModeloNovo(true);
+ registroLog = registroLog1;
+ }
+ catch (Exception exception)
+ {
+ registroLog = null;
+ }
+ return registroLog;
+ }
+
+ public RegistroLog CreateLog(long id, List<Diferenca> diferenca, TipoTela tela)
+ {
+ RegistroLog registroLog;
+ string str;
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ RegistroLog registroLog1 = new RegistroLog();
+ registroLog1.set_Acao(1);
+ registroLog1.set_Usuario(Recursos.Usuario);
+ registroLog1.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog1.set_Descricao(JsonConvert.SerializeObject(diferenca, jsonSerializerSetting));
+ registroLog1.set_EntidadeId(id);
+ registroLog1.set_Tela(tela);
+ registroLog1.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog1.set_NomeMaquina(Environment.MachineName);
+ registroLog1.set_UsuarioMaquina(Environment.UserName);
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Recursos.Host.AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog1.set_Ip(str);
+ registroLog1.set_ModeloNovo(true);
+ registroLog = registroLog1;
+ }
+ catch (Exception exception)
+ {
+ registroLog = null;
+ }
+ return registroLog;
+ }
+
+ public RegistroLog CreateLog(long id, List<Diferenca> diferenca, TipoTela tela, TipoAcao acao)
+ {
+ RegistroLog registroLog;
+ string str;
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ RegistroLog registroLog1 = new RegistroLog();
+ registroLog1.set_Acao(acao);
+ registroLog1.set_Usuario(Recursos.Usuario);
+ registroLog1.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog1.set_Descricao(JsonConvert.SerializeObject(diferenca, jsonSerializerSetting));
+ registroLog1.set_EntidadeId(id);
+ registroLog1.set_Tela(tela);
+ registroLog1.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog1.set_NomeMaquina(Environment.MachineName);
+ registroLog1.set_UsuarioMaquina(Environment.UserName);
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Recursos.Host.AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog1.set_Ip(str);
+ registroLog1.set_ModeloNovo(true);
+ registroLog = registroLog1;
+ }
+ catch (Exception exception)
+ {
+ registroLog = null;
+ }
+ return registroLog;
+ }
+
+ public RegistroLog CreateLog(long id, List<ValorOriginal> valor, TipoTela tela, TipoAcao acao)
+ {
+ RegistroLog registroLog;
+ string str;
+ try
+ {
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ RegistroLog registroLog1 = new RegistroLog();
+ registroLog1.set_Acao(acao);
+ registroLog1.set_Usuario(Recursos.Usuario);
+ registroLog1.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog1.set_Descricao(JsonConvert.SerializeObject(valor, jsonSerializerSetting));
+ registroLog1.set_EntidadeId(id);
+ registroLog1.set_Tela(tela);
+ registroLog1.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog1.set_NomeMaquina(Environment.MachineName);
+ registroLog1.set_UsuarioMaquina(Environment.UserName);
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Recursos.Host.AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog1.set_Ip(str);
+ registroLog1.set_ModeloNovo(true);
+ registroLog = registroLog1;
+ }
+ catch (Exception exception)
+ {
+ registroLog = null;
+ }
+ return registroLog;
+ }
+
+ internal async Task<UserSso> DeleteUsuarioSso(Usuario usuario, string documentoEmpresa)
+ {
+ UserSso userSso;
+ UserSso userSso1;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "user" };
+ Uri uri = apiSso.Append(strArrays).AddQuery<string>("userId", usuario.get_SsoId());
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso()));
+ HttpResponseMessage httpResponseMessage = await httpClient.DeleteAsync(uri);
+ if (!httpResponseMessage.get_IsSuccessStatusCode())
+ {
+ userSso1 = null;
+ }
+ else
+ {
+ userSso1 = JsonConvert.DeserializeObject<UserSso>(await httpResponseMessage.get_Content().ReadAsStringAsync());
+ }
+ userSso = userSso1;
+ }
+ return userSso;
+ }
+
+ public List<Diferenca> DynamicObjeto(dynamic objeto)
+ {
+ dynamic obj = objeto.Compare();
+ if (obj.Count <= 0)
+ {
+ return new List<Diferenca>();
+ }
+ return (List<Diferenca>)obj;
+ }
+
+ public async Task<bool> LoadInicialParameters()
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Parceiro> parceiros = read.get_ParceiroRepository().Find();
+ Func<Parceiro, long> u003cu003e9_521 = BaseServico.u003cu003ec.u003cu003e9__52_1;
+ if (u003cu003e9_521 == null)
+ {
+ u003cu003e9_521 = (Parceiro x) => x.get_Id();
+ BaseServico.u003cu003ec.u003cu003e9__52_1 = u003cu003e9_521;
+ }
+ Recursos.Parceiros = new List<Parceiro>(parceiros.OrderBy<Parceiro, long>(u003cu003e9_521));
+ List<Fabricante> fabricantes = read.get_FabricanteRepository().Select();
+ Func<Fabricante, string> u003cu003e9_522 = BaseServico.u003cu003ec.u003cu003e9__52_2;
+ if (u003cu003e9_522 == null)
+ {
+ u003cu003e9_522 = (Fabricante x) => x.get_Descricao();
+ BaseServico.u003cu003ec.u003cu003e9__52_2 = u003cu003e9_522;
+ }
+ Recursos.Fabricantes = fabricantes.OrderBy<Fabricante, string>(u003cu003e9_522).ToList<Fabricante>();
+ Recursos.Configuracoes = read.get_ConfiguracaoRepository().BuscarConfiguracoes();
+ read.CriarAuxiliar(false);
+ Recursos.Empresas = Auxiliar.get_Empresas();
+ Recursos.Ramos = Auxiliar.get_Ramos();
+ Recursos.Seguradoras = Auxiliar.get_Seguradoras();
+ Recursos.Produtos = Auxiliar.get_Produtos();
+ Recursos.Status = Auxiliar.get_StatusApolice();
+ Recursos.TipoVendedor = Auxiliar.get_TipoVendedores();
+ Recursos.Estipulantes = Auxiliar.get_Estipulantes();
+ Recursos.Vendedores = Auxiliar.get_Vendedores();
+ Recursos.Usuarios = Auxiliar.get_Usuarios();
+ Recursos.TiposTarefa = Auxiliar.get_TiposTarefa();
+ Recursos.StatusProspeccao = Auxiliar.get_StatusProspeccao();
+ Recursos.Coberturas = Auxiliar.get_CoberturasPadrao();
+ }
+ flag = true;
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 186, num, null, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> ParceiroUtilizado(long id)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ flag = read.get_SinistroAutoRepository().ParceiroUtilizado(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 156, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public int Registrar(Exception e, TipoErro erro, int tries, object objeto = null, bool abrirTela = true)
+ {
+ string str;
+ string nome;
+ string nome1;
+ long id;
+ string str1;
+ tries--;
+ if (tries > 0)
+ {
+ return tries;
+ }
+ try
+ {
+ int fileLineNumber = (new StackTrace(e, true)).GetFrame(0).GetFileLineNumber();
+ if (objeto != null)
+ {
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ str = JsonConvert.SerializeObject(objeto, 1, jsonSerializerSetting);
+ }
+ else
+ {
+ str = null;
+ }
+ string str2 = str;
+ LogError logError = new LogError();
+ logError.set_IdFornecedor(ApplicationHelper.IdFornecedor);
+ Empresa empresa = Recursos.Empresa;
+ if (empresa != null)
+ {
+ nome = empresa.get_Nome();
+ }
+ else
+ {
+ nome = null;
+ }
+ logError.set_Fornecedor(nome);
+ Usuario usuario = Recursos.Usuario;
+ if (usuario != null)
+ {
+ nome1 = usuario.get_Nome();
+ }
+ else
+ {
+ nome1 = null;
+ }
+ logError.set_UsuarioLogado(nome1);
+ Usuario usuario1 = Recursos.Usuario;
+ if (usuario1 != null)
+ {
+ id = usuario1.get_Id();
+ }
+ else
+ {
+ id = (long)0;
+ }
+ logError.set_IdUsuarioLogado(id);
+ logError.set_Versao(ApplicationHelper.Versao.ToString());
+ logError.set_Data(Funcoes.GetNetworkTime());
+ logError.set_IdErro(erro);
+ logError.set_Erro(Gestor.Common.Validation.ValidationHelper.GetDescription(erro));
+ logError.set_HResult(e.HResult);
+ Exception innerException = e.InnerException;
+ if (innerException != null)
+ {
+ str1 = innerException.ToString();
+ }
+ else
+ {
+ str1 = null;
+ }
+ logError.set_InnerException(str1);
+ logError.set_HelpLink(e.HelpLink);
+ logError.set_Message(e.Message);
+ logError.set_Source(e.Source);
+ logError.set_StackTrace(e.StackTrace);
+ logError.set_Maquina(Environment.MachineName);
+ logError.set_UsuarioMaquina(Environment.UserName);
+ logError.set_Linha(fileLineNumber.ToString());
+ logError.set_Objeto(str2);
+ Erro.RegistrarErro(logError, abrirTela);
+ this.Sucesso = false;
+ }
+ catch (Exception exception)
+ {
+ }
+ return 0;
+ }
+
+ public async Task<bool> ReloadAuxiliar()
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ read.CriarAuxiliar(true);
+ Recursos.Empresas = Auxiliar.get_Empresas();
+ Recursos.Ramos = Auxiliar.get_Ramos();
+ Recursos.Seguradoras = Auxiliar.get_Seguradoras();
+ Recursos.Produtos = Auxiliar.get_Produtos();
+ Recursos.Status = Auxiliar.get_StatusApolice();
+ Recursos.TipoVendedor = Auxiliar.get_TipoVendedores();
+ Recursos.Estipulantes = Auxiliar.get_Estipulantes();
+ Recursos.Vendedores = Auxiliar.get_Vendedores();
+ Recursos.Usuarios = Auxiliar.get_Usuarios();
+ Recursos.TiposTarefa = Auxiliar.get_TiposTarefa();
+ Recursos.StatusProspeccao = Auxiliar.get_StatusProspeccao();
+ }
+ flag = true;
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 186, num, null, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public void SalvarAcao(RegistroAcao log, object obs = null)
+ {
+ string str;
+ string str1;
+ if (log == null || Recursos.Usuario.get_Id() == 0)
+ {
+ return;
+ }
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ log.set_Usuario(Recursos.Usuario);
+ log.set_DataHora(Funcoes.GetNetworkTime());
+ log.set_Versao(LoginViewModel.VersaoAtual);
+ log.set_NomeMaquina(Environment.MachineName);
+ log.set_UsuarioMaquina(Environment.UserName);
+ RegistroAcao registroAcao = log;
+ IPAddress pAddress = ((IEnumerable<IPAddress>)Dns.GetHostEntry(Dns.GetHostName()).AddressList).FirstOrDefault<IPAddress>((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroAcao.set_Ip(str);
+ RegistroAcao registroAcao1 = log;
+ if (obs == null)
+ {
+ str1 = "";
+ }
+ else if (!(obs is string))
+ {
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ str1 = JsonConvert.SerializeObject(obs, jsonSerializerSetting);
+ }
+ else
+ {
+ str1 = obs.ToString();
+ }
+ registroAcao1.set_Observacao(str1);
+ commited.get_RegistroAcaoRepository().SaveOrUpdate(log);
+ commited.Commit();
+ }
+ }
+ catch (Exception exception)
+ {
+ this.Registrar(exception, 0, 3, log, true);
+ }
+ }
+
+ public async Task SalvarControle(ControleArquivoDigital controle)
+ {
+ int num = 3;
+ await Task.Run(() => {
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_IndiceArquivoDigitalRepository().SaveOrUpdate(controle);
+ commited.Commit();
+ }
+ break;
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 179, num, controle, true);
+ }
+ }
+ });
+ }
+
+ public void SaveLog(RegistroLog keyValues, UnitOfWork unitOfWork)
+ {
+ if (keyValues == null)
+ {
+ return;
+ }
+ try
+ {
+ unitOfWork.get_RegistroLogRepository().SaveOrUpdate(keyValues);
+ }
+ catch (Exception exception)
+ {
+ }
+ }
+
+ public void SaveLog(List<RegistroLog> keyValues, UnitOfWork unitOfWork)
+ {
+ if (keyValues == null)
+ {
+ return;
+ }
+ try
+ {
+ List<RegistroLog> list = keyValues.Where<RegistroLog>((RegistroLog x) => {
+ if (string.IsNullOrEmpty((x != null ? x.get_Descricao() : null)))
+ {
+ return false;
+ }
+ return !string.IsNullOrEmpty(x.get_Versao());
+ }).ToList<RegistroLog>();
+ unitOfWork.get_RegistroLogRepository().AddRange(list);
+ }
+ catch (Exception exception)
+ {
+ }
+ }
+
+ public async Task<int> Sincronizar(List<DadosVinculo> dados, Filtros filtros)
+ {
+ int num2 = 3;
+ int num3 = await Task.Run<int>(() => {
+ int num;
+ while (num2 > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ int num1 = commited.get_VinculoDocumentoRepository().Sincronize(filtros.get_Inicio(), dados);
+ commited.Commit();
+ num = num1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num2 = this.Registrar(exception, 293, num2, null, true);
+ continue;
+ }
+ return num;
+ }
+ return 0;
+ });
+ return num3;
+ }
+
+ public async Task<int[]> Sincronizar(DateTime data, List<long> ids = null)
+ {
+ int num = 3;
+ int[] numArray2 = await Task.Run<int[]>(() => {
+ int[] numArray;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ int[] numArray1 = commited.get_ParcelaRepository().SincronizarPendencia(data, ids);
+ commited.Commit();
+ numArray = numArray1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 300, num, false, true);
+ continue;
+ }
+ return numArray;
+ }
+ return new int[2];
+ });
+ return numArray2;
+ }
+
+ public async Task<bool> TipoVendedorUtilizado(long id)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ flag = read.get_VendedorParcelaRepository().TipoVendedorUtilizado(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = this.Registrar(exception, 155, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ internal async Task<AuthSso> VerificaUsuarioSso(string login, string documentoEmpresa)
+ {
+ AuthSso authSso;
+ AuthSso authSso1;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ Uri apiSso = Address.get_ApiSso();
+ string[] strArrays = new string[] { "exist" };
+ Uri uri = apiSso.Append(strArrays);
+ object[] ticks = new object[] { login, login, ApplicationHelper.NumeroSerial, documentoEmpresa, null };
+ DateTime universalTime = Funcoes.GetNetworkTime().ToUniversalTime();
+ ticks[4] = universalTime.Ticks;
+ string base64BasicEncode = string.Format("{0}:{1}:{2}:{3}:{4}", ticks).ToBase64BasicEncode();
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", base64BasicEncode);
+ HttpResponseMessage async = await httpClient.GetAsync(uri);
+ if (!async.get_IsSuccessStatusCode())
+ {
+ authSso1 = null;
+ }
+ else
+ {
+ authSso1 = JsonConvert.DeserializeObject<AuthSso>(await async.get_Content().ReadAsStringAsync());
+ }
+ authSso = authSso1;
+ }
+ return authSso;
+ }
+ }
+}
\ No newline at end of file |