summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs')
-rw-r--r--Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs1848
1 files changed, 1848 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs b/Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs
new file mode 100644
index 0000000..0aae6a5
--- /dev/null
+++ b/Codemerx/Gestor.Application/Servicos/Seguros/ApoliceServico.cs
@@ -0,0 +1,1848 @@
+using CsQuery.ExtensionMethods;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels;
+using Gestor.Infrastructure.Repository.Interface;
+using Gestor.Infrastructure.UnitOfWork.Generic;
+using Gestor.Infrastructure.UnitOfWork.Logic;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Relatorios;
+using Gestor.Model.Domain.Relatorios.Fechamento;
+using Gestor.Model.Domain.Relatorios.Tarefa;
+using Gestor.Model.Domain.Seguros;
+using Gestor.Model.License;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.Servicos.Seguros
+{
+ internal class ApoliceServico : BaseServico
+ {
+ private bool _carregando;
+
+ public ApoliceServico()
+ {
+ }
+
+ public async Task<bool> AtualizarNumero(long id, string numero, string endosso, int tipoDocumento)
+ {
+ bool flag2 = await Task.Run<bool>(() => {
+ bool flag;
+ try
+ {
+ bool flag1 = true;
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ flag1 = commited.get_DocumentoRepository().AtualizarNumero(id, numero, endosso, tipoDocumento);
+ commited.Commit();
+ }
+ flag = flag1;
+ }
+ catch (Exception exception)
+ {
+ flag = false;
+ }
+ return flag;
+ });
+ return flag2;
+ }
+
+ public async Task<List<Documento>> Auditoria(Filtros filtro)
+ {
+ 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().Auditoria(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 13, num, filtro, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<bool> BaixarParcelasCancelamento(Documento documento, bool estorno)
+ {
+ int num1 = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ string str1;
+ Action<VendedorParcela> action3 = null;
+ Action<VendedorParcela> action4 = null;
+ while (num1 > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_ParcelaRepository().FindByDocumentId(documento.get_Id()).ToList<Parcela>().ForEach((Parcela x) => {
+ Action<VendedorParcela> action;
+ List<VendedorParcela> vendedorParcelas = commited.get_VendedorParcelaRepository().FindByParcela(x.get_Id());
+ if (vendedorParcelas.Count > 0)
+ {
+ if (!estorno)
+ {
+ List<VendedorParcela> vendedorParcelas1 = vendedorParcelas;
+ Func<VendedorParcela, bool> u003cu003e9_302 = ApoliceServico.u003cu003ec.u003cu003e9__30_2;
+ if (u003cu003e9_302 == null)
+ {
+ u003cu003e9_302 = (VendedorParcela v) => !v.get_DataPrePagamento().HasValue;
+ ApoliceServico.u003cu003ec.u003cu003e9__30_2 = u003cu003e9_302;
+ }
+ List<VendedorParcela> list = vendedorParcelas1.Where<VendedorParcela>(u003cu003e9_302).ToList<VendedorParcela>();
+ Action<VendedorParcela> u003cu003e9_3 = action4;
+ if (u003cu003e9_3 == null)
+ {
+ Action<VendedorParcela> action1 = (VendedorParcela v) => {
+ v.set_ValorRepasse(new decimal?(new decimal()));
+ v.set_DataPagamento(new DateTime?(networkTime));
+ v.set_DataPrePagamento(new DateTime?(v.get_DataPrePagamento().GetValueOrDefault(networkTime)));
+ commited.get_VendedorParcelaRepository().Merge(v);
+ };
+ action = action1;
+ action4 = action1;
+ u003cu003e9_3 = action;
+ }
+ list.ForEach(u003cu003e9_3);
+ }
+ else
+ {
+ string str = (documento.get_Tipo() == 0 ? string.Concat(" PROPOSTA ", documento.get_Proposta(), " DO CLIENTE ", documento.get_Controle().get_Cliente().get_Nome()) : string.Concat(" PROPOSTA DE ENDOSSO ", documento.get_PropostaEndosso(), " DO CLIENTE ", documento.get_Controle().get_Cliente().get_Nome()));
+ List<VendedorParcela> vendedorParcelas2 = vendedorParcelas;
+ Func<VendedorParcela, bool> u003cu003e9_304 = ApoliceServico.u003cu003ec.u003cu003e9__30_4;
+ if (u003cu003e9_304 == null)
+ {
+ u003cu003e9_304 = (VendedorParcela v) => v.get_DataPagamento().HasValue;
+ ApoliceServico.u003cu003ec.u003cu003e9__30_4 = u003cu003e9_304;
+ }
+ IEnumerable<VendedorParcela> vendedorParcelas3 = vendedorParcelas2.Where<VendedorParcela>(u003cu003e9_304);
+ Func<VendedorParcela, long> u003cu003e9_305 = ApoliceServico.u003cu003ec.u003cu003e9__30_5;
+ if (u003cu003e9_305 == null)
+ {
+ u003cu003e9_305 = (VendedorParcela v) => v.get_Vendedor().get_Id();
+ ApoliceServico.u003cu003ec.u003cu003e9__30_5 = u003cu003e9_305;
+ }
+ List<Adiantamento> adiantamentos = vendedorParcelas3.GroupBy<VendedorParcela, long>(u003cu003e9_305).Select<IGrouping<long, VendedorParcela>, Adiantamento>((IGrouping<long, VendedorParcela> v) => {
+ Adiantamento adiantamento = new Adiantamento();
+ adiantamento.set_Vendedor(v.First<VendedorParcela>().get_Vendedor());
+ adiantamento.set_Data(new DateTime?(networkTime));
+ IGrouping<long, VendedorParcela> nums = v;
+ Func<VendedorParcela, bool> u003cu003e9_309 = ApoliceServico.u003cu003ec.u003cu003e9__30_9;
+ if (u003cu003e9_309 == null)
+ {
+ u003cu003e9_309 = (VendedorParcela s) => s.get_ValorRepasse().HasValue;
+ ApoliceServico.u003cu003ec.u003cu003e9__30_9 = u003cu003e9_309;
+ }
+ adiantamento.set_Valor(nums.Where<VendedorParcela>(u003cu003e9_309).Sum<VendedorParcela>((VendedorParcela s) => {
+ decimal? nullable;
+ decimal? nullable1;
+ decimal? valorRepasse = s.get_ValorRepasse();
+ decimal value = valorRepasse.Value;
+ decimal num = 1;
+ valorRepasse = v.First<VendedorParcela>().get_Vendedor().get_Desconto();
+ if (valorRepasse.HasValue)
+ {
+ nullable1 = new decimal?(num - valorRepasse.GetValueOrDefault());
+ }
+ else
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ nullable = nullable1;
+ return value * nullable.GetValueOrDefault();
+ }));
+ adiantamento.set_Historico(string.Format("ESTORNO DEVIDO A RECUSA {0} PARCELA {1}", str, x.get_NumeroParcela()));
+ return adiantamento;
+ }).ToList<Adiantamento>();
+ commited.get_AdiantamentoRepository().AddRange(adiantamentos);
+ List<VendedorParcela> vendedorParcelas4 = vendedorParcelas;
+ Func<VendedorParcela, bool> u003cu003e9_307 = ApoliceServico.u003cu003ec.u003cu003e9__30_7;
+ if (u003cu003e9_307 == null)
+ {
+ u003cu003e9_307 = (VendedorParcela v) => !v.get_DataPagamento().HasValue;
+ ApoliceServico.u003cu003ec.u003cu003e9__30_7 = u003cu003e9_307;
+ }
+ List<VendedorParcela> list1 = vendedorParcelas4.Where<VendedorParcela>(u003cu003e9_307).ToList<VendedorParcela>();
+ Action<VendedorParcela> u003cu003e9_8 = action3;
+ if (u003cu003e9_8 == null)
+ {
+ Action<VendedorParcela> action2 = (VendedorParcela v) => {
+ v.set_ValorRepasse(new decimal?(new decimal()));
+ v.set_DataPagamento(new DateTime?(networkTime));
+ v.set_DataPrePagamento(new DateTime?(v.get_DataPrePagamento().GetValueOrDefault(networkTime)));
+ commited.get_VendedorParcelaRepository().Merge(v);
+ };
+ action = action2;
+ action3 = action2;
+ u003cu003e9_8 = action;
+ }
+ list1.ForEach(u003cu003e9_8);
+ }
+ }
+ if (x.get_DataRecebimento().HasValue)
+ {
+ return;
+ }
+ x.set_DataRecebimento(new DateTime?(networkTime));
+ x.set_DataCredito(new DateTime?(networkTime));
+ x.set_ValorComissao(decimal.Zero);
+ x.set_ValorComDesconto(decimal.Zero);
+ commited.get_ParcelaRepository().Merge(x);
+ });
+ commited.get_DocumentoRepository().Merge(documento);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(1);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ Documento documento1 = documento;
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(documento1, jsonSerializerSetting));
+ registroLog.set_EntidadeId(documento.get_Id());
+ registroLog.set_Tela(2);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_3011 = ApoliceServico.u003cu003ec.u003cu003e9__30_11;
+ if (u003cu003e9_3011 == null)
+ {
+ u003cu003e9_3011 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__30_11 = u003cu003e9_3011;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_3011);
+ if (pAddress != null)
+ {
+ str1 = pAddress.ToString();
+ }
+ else
+ {
+ str1 = null;
+ }
+ registroLog.set_Ip(str1);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num1 = base.Registrar(exception, 26, num1, documento, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ internal async Task<List<Documento>> BuscarApolice(string pesquisa, FiltroStatusDocumento status, List<VendedorUsuario> vendedorVinculado, string campo = "Apolice", bool tipobusca = false)
+ {
+ int num1 = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(() => {
+ List<Documento> documentos;
+ long num;
+ while (num1 > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ IDocumentoRepository documentoRepository = read.get_DocumentoRepository();
+ string str = pesquisa;
+ FiltroStatusDocumento filtroStatusDocumento = status;
+ List<VendedorUsuario> vendedorUsuarios = vendedorVinculado;
+ string str1 = campo;
+ num = (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa());
+ List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ Func<ConfiguracaoSistema, bool> u003cu003e9_211 = ApoliceServico.u003cu003ec.u003cu003e9__21_1;
+ if (u003cu003e9_211 == null)
+ {
+ u003cu003e9_211 = (ConfiguracaoSistema x) => x.get_Configuracao() == 43;
+ ApoliceServico.u003cu003ec.u003cu003e9__21_1 = u003cu003e9_211;
+ }
+ documentos = documentoRepository.FindApolice(str, filtroStatusDocumento, vendedorUsuarios, str1, num, configuracoes.Any<ConfiguracaoSistema>(u003cu003e9_211), tipobusca);
+ }
+ }
+ catch (Exception exception)
+ {
+ num1 = base.Registrar(exception, 7, num1, new { pesquisa = pesquisa, status = status, campo = campo }, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<Documento> BuscarApoliceAsync(long id, bool itens = false, bool sinistrosPorControle = false)
+ {
+ int num = 3;
+ Documento documento1 = await Task.Run<Documento>(() => {
+ Documento documento;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documento = read.get_DocumentoRepository().FindById(id, itens, sinistrosPorControle);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, id, true);
+ continue;
+ }
+ return documento;
+ }
+ return new Documento();
+ });
+ return documento1;
+ }
+
+ public async Task<List<Documento>> BuscarApolices(Filtros filtro, bool buscarAssinatura = false, bool painelBi = false)
+ {
+ int num = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(async () => {
+ List<Documento> documentos;
+ while (true)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documentos = await read.get_DocumentoRepository().BuscaDocumentosPorVigencia(filtro, buscarAssinatura, painelBi);
+ return documentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 5, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ documentos = new List<Documento>();
+ return documentos;
+ });
+ return documentos1;
+ }
+
+ internal async Task<ObservableCollection<Documento>> BuscarApolicesAsync(long id, FiltroStatusDocumento status = 0, List<VendedorUsuario> vendedorVinculado = null)
+ {
+ ObservableCollection<Documento> observableCollection1;
+ if (!this._carregando)
+ {
+ int num1 = 3;
+ observableCollection1 = await Task.Run<ObservableCollection<Documento>>(() => {
+ ObservableCollection<Documento> observableCollection;
+ while (num1 > 0)
+ {
+ try
+ {
+ this._carregando = true;
+ using (UnitOfWork read = Instancia.Read)
+ {
+ IDocumentoRepository documentoRepository = read.get_DocumentoRepository();
+ long num = id;
+ FiltroStatusDocumento filtroStatusDocumento = status;
+ List<VendedorUsuario> vendedorUsuarios = vendedorVinculado;
+ List<Licenca> produtos = LicenseHelper.Produtos;
+ bool flag1 = Recursos.Usuario.get_Id() == (long)0;
+ List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ Func<ConfiguracaoSistema, bool> u003cu003e9_11 = ApoliceServico.u003cu003ec.u003cu003e9__1_1;
+ if (u003cu003e9_11 == null)
+ {
+ u003cu003e9_11 = (ConfiguracaoSistema x) => x.get_Configuracao() == 43;
+ ApoliceServico.u003cu003ec.u003cu003e9__1_1 = u003cu003e9_11;
+ }
+ this._carregando = false;
+ observableCollection = new ObservableCollection<Documento>(documentoRepository.FindApoliceByCustomer(num, filtroStatusDocumento, vendedorUsuarios, produtos, false, flag1, configuracoes.Any<ConfiguracaoSistema>(u003cu003e9_11)));
+ }
+ }
+ catch (Exception exception1)
+ {
+ Exception exception = exception1;
+ List<Licenca> licencas = LicenseHelper.Produtos;
+ Func<Licenca, bool> u003cu003e9_12 = ApoliceServico.u003cu003ec.u003cu003e9__1_2;
+ if (u003cu003e9_12 == null)
+ {
+ u003cu003e9_12 = (Licenca x) => {
+ if (x.get_Produto() != 86)
+ {
+ return false;
+ }
+ return x.get_Status() != 3;
+ };
+ ApoliceServico.u003cu003ec.u003cu003e9__1_2 = u003cu003e9_12;
+ }
+ bool flag = licencas.Any<Licenca>(u003cu003e9_12);
+ num1 = base.Registrar(exception, 1, num1, new { id = id, status = status, vendedorVinculado = vendedorVinculado, assinatura = flag }, true);
+ continue;
+ }
+ return observableCollection;
+ }
+ this._carregando = false;
+ return new ObservableCollection<Documento>();
+ });
+ }
+ else
+ {
+ observableCollection1 = new ObservableCollection<Documento>();
+ }
+ return observableCollection1;
+ }
+
+ internal async Task<ObservableCollection<Documento>> BuscarApolicesComissao(long id, FiltroStatusDocumento status = 0)
+ {
+ int num = 3;
+ ObservableCollection<Documento> observableCollection1 = await Task.Run<ObservableCollection<Documento>>(() => {
+ ObservableCollection<Documento> observableCollection;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ observableCollection = new ObservableCollection<Documento>(read.get_DocumentoRepository().FindApoliceByCustomer(id, status, null, LicenseHelper.Produtos, true, false, false));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 2, num, new { id = id, status = status }, true);
+ continue;
+ }
+ return observableCollection;
+ }
+ return new ObservableCollection<Documento>();
+ });
+ return observableCollection1;
+ }
+
+ public async Task<List<Documento>> BuscarApolicesPendentes(Filtros filtro)
+ {
+ 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().FindPendenciasByVigencia(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 10, num, filtro, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Documento>> BuscarApolicesPorId(List<long> ids)
+ {
+ 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().FindByIds(ids);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, ids, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Documento>> BuscarApolicesPorIdParcela(List<long> ids)
+ {
+ 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().FindByParcelaIds(ids);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, ids, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Documento>> BuscarApolicesVigenciaFinal(Filtros filtro, bool somarPremios = false)
+ {
+ 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().FindByVigenciaFinal(filtro, LicenseHelper.Produtos, somarPremios);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 6, num, filtro, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ internal async Task<Documento> BuscarCodDocumento(long pesquisa, List<VendedorUsuario> vendedorVinculado)
+ {
+ int num = 3;
+ Documento documento1 = await Task.Run<Documento>(() => {
+ Documento documento;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documento = read.get_DocumentoRepository().FindById(pesquisa, vendedorVinculado);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, pesquisa, true);
+ continue;
+ }
+ return documento;
+ }
+ return new Documento();
+ });
+ return documento1;
+ }
+
+ public async Task<Controle> BuscarControleAsync(long id)
+ {
+ int num = 3;
+ Controle controle1 = await Task.Run<Controle>(() => {
+ Controle controle;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ controle = read.get_ControleRepository().FindById(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 4, num, id, true);
+ continue;
+ }
+ return controle;
+ }
+ return new Controle();
+ });
+ return controle1;
+ }
+
+ public async Task<List<Documento>> BuscarEndossos(Filtros filtro, bool buscarAssinatura = false)
+ {
+ int num = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(async () => {
+ List<Documento> documentos;
+ while (true)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documentos = await read.get_DocumentoRepository().FindEndossoByVigencia(filtro, buscarAssinatura);
+ return documentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 5, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ documentos = new List<Documento>();
+ return documentos;
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Fechamento>> BuscarFechamento(Filtros filtro)
+ {
+ int num = 3;
+ List<Fechamento> fechamentos1 = await Task.Run<List<Fechamento>>(async () => {
+ List<Fechamento> fechamentos;
+ while (true)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ fechamentos = await read.get_DocumentoRepository().Fechamento(filtro);
+ return fechamentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 8, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ fechamentos = new List<Fechamento>();
+ return fechamentos;
+ });
+ return fechamentos1;
+ }
+
+ public async Task<List<Documento>> BuscarLicenciamentos(Filtros filtro)
+ {
+ 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().FindByLicenciamento(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 295, num, filtro, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<string> BuscarLogAntigo(long id)
+ {
+ int num = 3;
+ string str1 = await Task.Run<string>(() => {
+ string str;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ str = read.get_DocumentoRepository().BuscarLogAntigo(id, Gestor.Application.Helpers.Connection.GetConnectionString());
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 319, num, id, true);
+ continue;
+ }
+ return str;
+ }
+ return null;
+ });
+ return str1;
+ }
+
+ public async Task<List<Documento>> BuscarPlacas(Filtros filtro)
+ {
+ 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().FindByPlaca(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 327, num, filtro, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<PlanilhaCompleta>> BuscarPlanilhaCompleta(List<long> ids, bool configFranquia, bool configPremio)
+ {
+ int num = 3;
+ List<PlanilhaCompleta> planilhaCompletas1 = await Task.Run<List<PlanilhaCompleta>>(() => {
+ List<PlanilhaCompleta> planilhaCompletas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ planilhaCompletas = read.get_ReportRepository().PlanilhaCompleta(ids, configFranquia, configPremio);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 296, num, ids, true);
+ continue;
+ }
+ return planilhaCompletas;
+ }
+ return null;
+ });
+ return planilhaCompletas1;
+ }
+
+ public async Task<List<PlanilhaCompleta>> BuscarPlanilhaCompletaFatura(List<long> ids, Relatorio relatorio, DateTime inicio, DateTime fim, bool configFranquia, bool configPremio)
+ {
+ int num = 3;
+ List<PlanilhaCompleta> planilhaCompletas1 = await Task.Run<List<PlanilhaCompleta>>(() => {
+ List<PlanilhaCompleta> planilhaCompletas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ planilhaCompletas = read.get_ReportRepository().PlanilhaCompletaFatura(ids, relatorio, inicio, fim, configFranquia, configPremio);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 296, num, ids, true);
+ continue;
+ }
+ return planilhaCompletas;
+ }
+ return null;
+ });
+ return planilhaCompletas1;
+ }
+
+ public async Task<List<PlanilhaCompleta>> BuscarPlanilhaCompletaProspeccao(List<long> ids)
+ {
+ int num = 3;
+ List<PlanilhaCompleta> planilhaCompletas1 = await Task.Run<List<PlanilhaCompleta>>(() => {
+ List<PlanilhaCompleta> planilhaCompletas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ planilhaCompletas = read.get_DocumentoRepository().BuscarPlanilhaCompletaProspeccao(ids);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 296, num, ids, true);
+ continue;
+ }
+ return planilhaCompletas;
+ }
+ return null;
+ });
+ return planilhaCompletas1;
+ }
+
+ public async Task<List<Tarefa>> BuscarTarefas(Filtros filtro)
+ {
+ int num = 3;
+ List<Tarefa> tarefas1 = await Task.Run<List<Tarefa>>(() => {
+ List<Tarefa> tarefas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ tarefas = read.get_TarefaRepository().BuscarTarefaPorFiltro(filtro.get_Inicio(), filtro.get_Fim());
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 97, num, filtro, true);
+ continue;
+ }
+ return tarefas;
+ }
+ return new List<Tarefa>();
+ });
+ return tarefas1;
+ }
+
+ public async Task<Vendedor> BuscarVendedorPrincipal(long id)
+ {
+ int num = 3;
+ Vendedor vendedor1 = await Task.Run<Vendedor>(() => {
+ Vendedor vendedor;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ vendedor = read.get_VendedorParcelaRepository().BuscarVendedorPorControle(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, id, true);
+ continue;
+ }
+ return vendedor;
+ }
+ return new Vendedor();
+ });
+ return vendedor1;
+ }
+
+ public async Task<int> Cotacoes(Filtros filtro)
+ {
+ int num1 = 3;
+ int num2 = await Task.Run<int>(() => {
+ int num;
+ while (num1 > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ num = read.get_DocumentoRepository().Cotacoes(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num1 = base.Registrar(exception, 14, num1, filtro, true);
+ continue;
+ }
+ return num;
+ }
+ return 0;
+ });
+ return num2;
+ }
+
+ public async Task<Documento> Excluir(Documento documento)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ Documento documento2 = documento;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ Documento documento3 = await Task.Run<Documento>(() => {
+ Documento documento4;
+ bool id;
+ string str;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ TipoAcao tipoAcao = 2;
+ Controle controle = documento.get_Controle();
+ if (controle == null)
+ {
+ controle = commited.get_DocumentoRepository().FindById(documento.get_Id(), false, false).get_Controle();
+ documento.set_Controle(controle);
+ }
+ commited.get_ParcelaRepository().ExcluirVinculoParcelaPendenteDocExcluido(documento);
+ Status status = documento.get_Status();
+ id = (status != null ? status.get_Id() == (long)0 : false);
+ if (id)
+ {
+ documento.set_Status(null);
+ }
+ documento = commited.get_DocumentoRepository().Merge(documento);
+ documento.set_Controle(commited.get_ControleRepository().Merge(controle));
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(tipoAcao);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ Documento documento1 = documento;
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(documento1, jsonSerializerSetting));
+ registroLog.set_EntidadeId(documento.get_Id());
+ registroLog.set_Tela(2);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_41 = ApoliceServico.u003cu003ec.u003cu003e9__4_1;
+ if (u003cu003e9_41 == null)
+ {
+ u003cu003e9_41 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__4_1 = u003cu003e9_41;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_41);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ documento4 = documento;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 20, num, documento, true);
+ continue;
+ }
+ return documento4;
+ }
+ return documento2;
+ });
+ return documento3;
+ }
+
+ public async Task<bool> ExcluirCritica(long id)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ string str;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ CriticaApolice criticaApolouse = commited.get_CriticaApoliceRepository().FindByApolice(id);
+ if (criticaApolouse != null)
+ {
+ commited.get_CriticaApoliceRepository().Delete(criticaApolouse.get_Id());
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(2);
+ registroLog.set_Tela(20);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(criticaApolouse, jsonSerializerSetting));
+ registroLog.set_EntidadeId(criticaApolouse.get_Id());
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_281 = ApoliceServico.u003cu003ec.u003cu003e9__28_1;
+ if (u003cu003e9_281 == null)
+ {
+ u003cu003e9_281 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__28_1 = u003cu003e9_281;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_281);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ flag = true;
+ }
+ else
+ {
+ flag = true;
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 25, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> ExcluirPagamento(List<VendedorParcela> pagamentos)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ string str;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_VendedorParcelaRepository().DeleteRange(pagamentos);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ foreach (VendedorParcela pagamento in pagamentos)
+ {
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(2);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(pagamento, jsonSerializerSetting));
+ registroLog.set_EntidadeId(pagamento.get_Parcela().get_Id());
+ registroLog.set_Tela(37);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_141 = ApoliceServico.u003cu003ec.u003cu003e9__14_1;
+ if (u003cu003e9_141 == null)
+ {
+ u003cu003e9_141 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__14_1 = u003cu003e9_141;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_141);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ }
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 21, num, pagamentos, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ internal async Task ExcluirVinculo(long id)
+ {
+ await Task.Run(() => {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_VinculoDocumentoRepository().Delete(id);
+ commited.Commit();
+ }
+ }
+ catch (Exception exception)
+ {
+ }
+ });
+ }
+
+ public async Task<VendedorParcela> IncluirVendedor(VendedorParcela vendedor)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ VendedorParcela vendedorParcela1 = vendedor;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ VendedorParcela vendedorParcela2 = await Task.Run<VendedorParcela>(() => {
+ VendedorParcela vendedorParcela;
+ object obj;
+ string str;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ vendedorParcela1 = commited.get_VendedorParcelaRepository().SaveOrUpdate(vendedorParcela1);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(0);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ RegistroLog registroLog1 = registroLog;
+ string[] strArrays = new string[] { string.Format("O USUÁRIO {0} INCLUIU, EM {1}, O VENDEDOR DE ", Recursos.Usuario.get_Nome(), networkTime), string.Format("ID: '{0}'", vendedor.get_Id()), string.Format(", VALOR DO PAGAMENTO: 'R${0}'", vendedor.get_ValorRepasse()), string.Format(", VALOR TOTAL: 'R${0}'", vendedor.get_ValorTotal()), ", DATA DO PAGAMENTO: '", null, null, null };
+ DateTime? dataPagamento = vendedor.get_DataPagamento();
+ if (!dataPagamento.HasValue)
+ {
+ obj = "";
+ }
+ else
+ {
+ dataPagamento = vendedor.get_DataPagamento();
+ obj = (dataPagamento.HasValue ? dataPagamento.GetValueOrDefault().ToShortDateString() : null) ?? "";
+ }
+ strArrays[5] = (string)obj;
+ strArrays[6] = "'";
+ strArrays[7] = string.Format(", PORCENTAGEM DO PAGAMENTO: '{0}%'.", vendedor.get_PorcentagemRepasse());
+ registroLog1.set_Descricao(string.Concat(strArrays));
+ registroLog.set_EntidadeId(vendedor.get_Id());
+ registroLog.set_Tela(37);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ RegistroLog registroLog2 = registroLog;
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_151 = ApoliceServico.u003cu003ec.u003cu003e9__15_1;
+ if (u003cu003e9_151 == null)
+ {
+ u003cu003e9_151 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__15_1 = u003cu003e9_151;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_151);
+ if (pAddress != null)
+ {
+ str = pAddress.ToString();
+ }
+ else
+ {
+ str = null;
+ }
+ registroLog2.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ vendedorParcela = vendedorParcela1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 22, num, vendedor, true);
+ continue;
+ }
+ return vendedorParcela;
+ }
+ return vendedor;
+ });
+ return vendedorParcela2;
+ }
+
+ public async Task<List<VendedorParcela>> IncluirVendedores(List<VendedorParcela> repasses)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ List<VendedorParcela> vendedorParcelas1 = repasses;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ List<VendedorParcela> vendedorParcelas2 = await Task.Run<List<VendedorParcela>>(() => {
+ List<VendedorParcela> vendedorParcelas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ vendedorParcelas1 = commited.get_VendedorParcelaRepository().AddRange(vendedorParcelas1);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ vendedorParcelas1.ForEach((VendedorParcela x) => {
+ string str;
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(0);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(x, jsonSerializerSetting));
+ registroLog.set_EntidadeId(x.get_Parcela().get_Id());
+ registroLog.set_Tela(37);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_162 = ApoliceServico.u003cu003ec.u003cu003e9__16_2;
+ if (u003cu003e9_162 == null)
+ {
+ u003cu003e9_162 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__16_2 = u003cu003e9_162;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_162);
+ str = (pAddress != null ? pAddress.ToString() : null);
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ commited.Commit();
+ });
+ vendedorParcelas = vendedorParcelas1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 22, num, repasses, true);
+ continue;
+ }
+ return vendedorParcelas;
+ }
+ return repasses;
+ });
+ return vendedorParcelas2;
+ }
+
+ public async Task<bool> Perdido(long id)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_DocumentoRepository().FindByControle(id).ForEach((Documento x) => {
+ string str;
+ x.set_SituacaoAnterior(new TipoSeguro?(x.get_Situacao()));
+ x.set_Situacao(6);
+ commited.get_DocumentoRepository().Merge(x);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(1);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(x, jsonSerializerSetting));
+ registroLog.set_EntidadeId(x.get_Id());
+ registroLog.set_Tela(2);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_252 = ApoliceServico.u003cu003ec.u003cu003e9__25_2;
+ if (u003cu003e9_252 == null)
+ {
+ u003cu003e9_252 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__25_2 = u003cu003e9_252;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_252);
+ str = (pAddress != null ? pAddress.ToString() : null);
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ });
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 23, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> Prorrogar(long id, DateTime vigencia2)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_DocumentoRepository().FindByControle(id).ForEach((Documento x) => {
+ string str;
+ if (!x.get_NegocioCorretora().HasValue)
+ {
+ x.set_NegocioCorretora(new NegocioCorretora?((!x.get_Negocio().HasValue || x.get_Negocio().GetValueOrDefault() != 1 ? 0 : 1)));
+ }
+ x.set_Vigencia2(new DateTime?(vigencia2));
+ commited.get_DocumentoRepository().Merge(x);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(1);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(x, jsonSerializerSetting));
+ registroLog.set_EntidadeId(x.get_Id());
+ registroLog.set_Tela(2);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_232 = ApoliceServico.u003cu003ec.u003cu003e9__23_2;
+ if (u003cu003e9_232 == null)
+ {
+ u003cu003e9_232 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__23_2 = u003cu003e9_232;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_232);
+ str = (pAddress != null ? pAddress.ToString() : null);
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ });
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 23, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> Reabilitar(long id)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_DocumentoRepository().FindByControle(id).ForEach((Documento x) => {
+ string str;
+ if (x.get_TipoEndosso().HasValue && x.get_TipoEndosso().GetValueOrDefault() == 2)
+ {
+ return;
+ }
+ x.set_Situacao(4);
+ commited.get_DocumentoRepository().Merge(x);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ RegistroLog registroLog = new RegistroLog();
+ registroLog.set_Acao(1);
+ registroLog.set_Usuario(Recursos.Usuario);
+ registroLog.set_DataHora(networkTime);
+ JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
+ jsonSerializerSetting.set_ReferenceLoopHandling(1);
+ registroLog.set_Descricao(JsonConvert.SerializeObject(x, jsonSerializerSetting));
+ registroLog.set_EntidadeId(x.get_Id());
+ registroLog.set_Tela(2);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_242 = ApoliceServico.u003cu003ec.u003cu003e9__24_2;
+ if (u003cu003e9_242 == null)
+ {
+ u003cu003e9_242 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ApoliceServico.u003cu003ec.u003cu003e9__24_2 = u003cu003e9_242;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_242);
+ str = (pAddress != null ? pAddress.ToString() : null);
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ });
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 23, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task SalvarAssistencia(string id, long controleId)
+ {
+ await Task.Run(() => {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_DocumentoRepository().SalvarAssistencia(id, controleId);
+ commited.Commit();
+ }
+ }
+ catch (Exception exception)
+ {
+ }
+ });
+ }
+
+ public async Task Save(Controle controle, Cliente cliente)
+ {
+ int num = 3;
+ await Task.Run(() => {
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ List<RegistroLog> registroLogs1 = new List<RegistroLog>();
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ List<Diferenca> diferencas = new List<Diferenca>();
+ List<Diferenca> diferencas1 = new List<Diferenca>();
+ List<Diferenca> diferencas2 = diferencas;
+ Diferenca diferenca = new Diferenca();
+ diferenca.set_Campo("Cliente");
+ diferenca.set_Descricao("NOME");
+ diferenca.set_ValorAtual(cliente.get_Nome());
+ diferenca.set_ValorAnterior(controle.get_Cliente().get_Nome());
+ diferencas2.Insert(0, diferenca);
+ List<Diferenca> diferencas3 = diferencas1;
+ Diferenca diferenca1 = new Diferenca();
+ diferenca1.set_Campo("Cliente");
+ diferenca1.set_Descricao("APÓLICE TROCADA DE CLIENTE");
+ diferenca1.set_ValorAtual(cliente.get_Nome());
+ diferenca1.set_ValorAnterior(controle.get_Cliente().get_Nome());
+ diferencas3.Insert(0, diferenca1);
+ ExtensionMethods.ForEach<Documento>(controle.get_Documentos(), (Documento x) => {
+ registroLogs.Add(base.CreateLog(x.get_Id(), diferencas, 2));
+ registroLogs1.Add(base.CreateLog(x.get_Id(), diferencas1, 41));
+ });
+ commited.get_DocumentoRepository().TrocarCliente(controle, cliente);
+ base.SaveLog(registroLogs, commited);
+ base.SaveLog(registroLogs1, commited);
+ commited.Commit();
+ break;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 325, num, controle, true);
+ }
+ }
+ });
+ }
+
+ public async Task<Documento> Save(Documento documento, bool updateParcelas, bool criarParcelas)
+ {
+ Action<Parcela> action4 = null;
+ Action<VendedorParcela> action5 = null;
+ int num = 3;
+ base.Sucesso = true;
+ Documento documento1 = documento;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ Documento documento2 = await Task.Run<Documento>(() => {
+ Documento documento3;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ documento.get_Id();
+ bool id = documento.get_Id() == (long)0;
+ Controle controle = documento.get_Controle();
+ ObservableCollection<Parcela> parcelas = documento.get_Parcelas();
+ if (!id)
+ {
+ if (controle != null)
+ {
+ if ((controle != null ? controle.get_Seguradora() : false))
+ {
+ goto Label0;
+ }
+ }
+ controle = commited.get_DocumentoRepository().FindById(documento.get_Id(), false, false).get_Controle();
+ documento.set_Controle(controle);
+ Label0:
+ registroLogs.Add(base.CreateLog(documento.get_Id(), documento, 2));
+ documento = commited.get_DocumentoRepository().Merge(documento);
+ if (documento.get_TipoRecebimento().GetValueOrDefault() == 1)
+ {
+ if (criarParcelas)
+ {
+ List<Parcela> parcelas1 = commited.get_ParcelaRepository().FindByDocumentId(documento.get_Id());
+ if (parcelas1 != null)
+ {
+ Action<Parcela> u003cu003e9_3 = action4;
+ if (u003cu003e9_3 == null)
+ {
+ Action<Parcela> action = (Parcela pa) => registroLogs.Add(base.CreateLog(documento.get_Id(), pa.GetValorOriginal(), 5, 2));
+ Action<Parcela> action1 = action;
+ action4 = action;
+ u003cu003e9_3 = action1;
+ }
+ parcelas1.ForEach(u003cu003e9_3);
+ }
+ else
+ {
+ }
+ List<VendedorParcela> vendedorParcelas = commited.get_VendedorParcelaRepository().FindByDocumentId(documento.get_Id());
+ if (vendedorParcelas != null)
+ {
+ Action<VendedorParcela> u003cu003e9_4 = action5;
+ if (u003cu003e9_4 == null)
+ {
+ Action<VendedorParcela> action2 = (VendedorParcela pa) => registroLogs.Add(base.CreateLog(pa.get_Parcela().get_Id(), pa.GetValorOriginal(), 37, 2));
+ Action<VendedorParcela> action3 = action2;
+ action5 = action2;
+ u003cu003e9_4 = action3;
+ }
+ vendedorParcelas.ForEach(u003cu003e9_4);
+ }
+ else
+ {
+ }
+ commited.get_VendedorParcelaRepository().DeleteRange(documento.get_Id());
+ commited.get_ParcelaRepository().DeleteRange(documento.get_Id());
+ parcelas.ToList<Parcela>().ForEach((Parcela p) => {
+ Parcela parcela = p;
+ ObservableCollection<VendedorParcela> vendedores = parcela.get_Vendedores();
+ parcela.set_Documento(documento);
+ parcela.set_IdEmpresa(documento.get_Controle().get_IdEmpresa());
+ parcela = commited.get_ParcelaRepository().SaveOrUpdate(parcela);
+ vendedores.ToList<VendedorParcela>().ForEach((VendedorParcela v) => {
+ v.set_Documento(documento);
+ v.set_Parcela(parcela);
+ if (v.get_Repasse() != null)
+ {
+ BaseRepasse? @base = v.get_Repasse().get_Base();
+ if (@base.HasValue)
+ {
+ switch (@base.GetValueOrDefault())
+ {
+ case 1:
+ {
+ v.set_DataPrePagamento(new DateTime?(documento.get_Vigencia1()));
+ break;
+ }
+ case 2:
+ {
+ v.set_DataPrePagamento(new DateTime?(networkTime));
+ break;
+ }
+ case 3:
+ {
+ v.set_DataPrePagamento(new DateTime?(parcela.get_Vencimento()));
+ break;
+ }
+ case 4:
+ {
+ v.set_DataPrePagamento(documento.get_Emissao());
+ break;
+ }
+ case 5:
+ {
+ v.set_DataPrePagamento(documento.get_Remessa());
+ break;
+ }
+ }
+ }
+ }
+ v = commited.get_VendedorParcelaRepository().SaveOrUpdate(v);
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), v.GetValorOriginal(), 37, 0));
+ });
+ parcela.set_Vendedores(vendedores);
+ registroLogs.Add(base.CreateLog(documento.get_Id(), parcela.GetValorOriginal(), 5, 0));
+ });
+ }
+ if (updateParcelas && !criarParcelas)
+ {
+ List<Parcela> parcelas2 = commited.get_ParcelaRepository().FindByDocumentId(documento.get_Id());
+ List<VendedorParcela> vendedorParcelas1 = commited.get_VendedorParcelaRepository().FindByDocumentId(documento.get_Id());
+ parcelas.ToList<Parcela>().ForEach((Parcela p) => {
+ Parcela parcela = p;
+ ObservableCollection<VendedorParcela> vendedores = parcela.get_Vendedores();
+ parcela.set_Documento(documento);
+ parcela = commited.get_ParcelaRepository().Merge(parcela);
+ vendedores.ToList<VendedorParcela>().ForEach((VendedorParcela v) => {
+ bool flag;
+ VendedorParcela vendedorParcela = v;
+ vendedorParcela.set_Documento(documento);
+ vendedorParcela.set_Parcela(parcela);
+ flag = (vendedorParcela.get_Id() > (long)0 ? false : true);
+ vendedorParcela = (vendedorParcela.get_Id() > (long)0 ? commited.get_VendedorParcelaRepository().Merge(vendedorParcela) : commited.get_VendedorParcelaRepository().SaveOrUpdate(vendedorParcela));
+ if (!flag)
+ {
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), vendedorParcela.GetValorOriginal(), 37, 0));
+ }
+ VendedorParcela vendedorParcela1 = vendedorParcelas1.FirstOrDefault<VendedorParcela>((VendedorParcela pa) => vendedorParcela.get_Id() == pa.get_Id());
+ if (vendedorParcela1 == null)
+ {
+ return;
+ }
+ List<Diferenca> diferencas = vendedorParcela.Compare(vendedorParcela1.GetValorOriginal());
+ if (diferencas.Count > 0)
+ {
+ Diferenca diferenca = new Diferenca();
+ diferenca.set_Campo("Vendedor");
+ diferenca.set_Descricao("VENDEDOR");
+ diferenca.set_ValorAtual(vendedorParcela.get_Vendedor().get_Nome());
+ diferenca.set_ValorAnterior(vendedorParcela.get_Vendedor().get_Nome());
+ diferencas.Insert(0, diferenca);
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), diferencas, 37));
+ }
+ });
+ parcela.set_Vendedores(vendedores);
+ Parcela parcela1 = parcelas2.FirstOrDefault<Parcela>((Parcela pa) => parcela.get_Id() == pa.get_Id());
+ if (parcela1 == null)
+ {
+ return;
+ }
+ List<Diferenca> diferencas1 = parcela.Compare(parcela1.GetValorOriginal());
+ if (diferencas1.Count > 0)
+ {
+ Diferenca diferenca1 = new Diferenca();
+ diferenca1.set_Campo("Parcela");
+ diferenca1.set_Descricao("PARCELA");
+ int numeroParcela = parcela.get_NumeroParcela();
+ diferenca1.set_ValorAtual(numeroParcela.ToString());
+ numeroParcela = parcela.get_NumeroParcela();
+ diferenca1.set_ValorAnterior(numeroParcela.ToString());
+ diferencas1.Insert(0, diferenca1);
+ registroLogs.Add(base.CreateLog(documento.get_Id(), diferencas1, 5));
+ }
+ });
+ }
+ }
+ documento.set_Controle(commited.get_ControleRepository().Merge(controle));
+ }
+ else
+ {
+ controle = (documento.get_Tipo() <= 0 || controle.get_Id() <= (long)0 ? commited.get_ControleRepository().SaveOrUpdate(controle) : controle);
+ documento.set_Controle(controle);
+ documento = commited.get_DocumentoRepository().SaveOrUpdate(documento);
+ registroLogs.Add(base.CreateLog(documento.get_Id(), documento.GetValorOriginal(), 2, 0));
+ if (parcelas != null)
+ {
+ parcelas.ToList<Parcela>().ForEach((Parcela p) => {
+ Parcela parcela = p;
+ ObservableCollection<VendedorParcela> vendedores = parcela.get_Vendedores();
+ parcela.set_Documento(documento);
+ parcela.set_IdEmpresa(documento.get_Controle().get_IdEmpresa());
+ parcela = commited.get_ParcelaRepository().SaveOrUpdate(parcela);
+ registroLogs.Add(base.CreateLog(documento.get_Id(), parcela.GetValorOriginal(), 5, 0));
+ vendedores.ToList<VendedorParcela>().ForEach((VendedorParcela v) => {
+ v.set_Documento(documento);
+ v.set_Parcela(parcela);
+ if (v.get_Repasse() != null)
+ {
+ BaseRepasse? @base = v.get_Repasse().get_Base();
+ if (@base.HasValue)
+ {
+ switch (@base.GetValueOrDefault())
+ {
+ case 1:
+ {
+ v.set_DataPrePagamento(new DateTime?(documento.get_Vigencia1()));
+ break;
+ }
+ case 2:
+ {
+ v.set_DataPrePagamento(new DateTime?(networkTime));
+ break;
+ }
+ case 3:
+ {
+ v.set_DataPrePagamento(new DateTime?(parcela.get_Vencimento()));
+ break;
+ }
+ case 4:
+ {
+ v.set_DataPrePagamento(documento.get_Emissao());
+ break;
+ }
+ case 5:
+ {
+ v.set_DataPrePagamento(documento.get_Remessa());
+ break;
+ }
+ }
+ }
+ }
+ v = commited.get_VendedorParcelaRepository().SaveOrUpdate(v);
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), v.GetValorOriginal(), 37, 0));
+ });
+ parcela.set_Vendedores(vendedores);
+ });
+ }
+ }
+ documento.set_Parcelas(parcelas);
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ documento3 = documento;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 18, num, new { documentoOriginal = documento1, updateParcelas = updateParcelas, criarParcelas = criarParcelas }, true);
+ continue;
+ }
+ return documento3;
+ }
+ return documento1;
+ });
+ return documento2;
+ }
+
+ public async Task<string> Save(long id, string observacao)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ Funcoes.GetNetworkTime();
+ string str1 = await Task.Run<string>(() => {
+ string str;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ Documento documento = commited.get_DocumentoRepository().FindById(id, false, false);
+ documento.Initialize();
+ documento.set_Observacao(observacao);
+ registroLogs.Add(base.CreateLog(documento.get_Id(), documento, 2));
+ commited.get_DocumentoRepository().Merge(documento);
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ }
+ str = observacao;
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 18, num, new { id = id, observacao = observacao }, true);
+ continue;
+ }
+ return str;
+ }
+ return "";
+ });
+ return str1;
+ }
+
+ public async Task<bool> UpdateRange(Controle controle)
+ {
+ int num = 3;
+ Controle controle1 = controle;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ controle1 = commited.get_ControleRepository().Merge(controle1);
+ controle1.get_Documentos().ToList<Documento>().ForEach((Documento x) => x = commited.get_DocumentoRepository().Merge(x));
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 19, num, controle, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+ }
+} \ No newline at end of file