From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../Servicos/Seguros/ClienteServico.cs | 1194 ++++++++++++++++++++ 1 file changed, 1194 insertions(+) create mode 100644 Gestor.Application/Servicos/Seguros/ClienteServico.cs (limited to 'Gestor.Application/Servicos/Seguros/ClienteServico.cs') diff --git a/Gestor.Application/Servicos/Seguros/ClienteServico.cs b/Gestor.Application/Servicos/Seguros/ClienteServico.cs new file mode 100644 index 0000000..db5c9d2 --- /dev/null +++ b/Gestor.Application/Servicos/Seguros/ClienteServico.cs @@ -0,0 +1,1194 @@ +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Generic; +using Gestor.Common.Validation; +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.Ferramentas; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using Gestor.Model.Domain.Relatorios.Classificacao; +using Gestor.Model.Domain.Relatorios.ClientesAtivosInativos; +using Gestor.Model.Domain.Relatorios.Dashboard; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.License; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.Servicos.Seguros +{ + internal class ClienteServico : BaseServico + { + public ClienteServico() + { + } + + public async Task AddCentralSegurado(long id, bool update = true) + { + await Task.Run(() => { + using (UnitOfWork commited = Instancia.Commited) + { + commited.get_ClienteRepository().AddCentralSegurado(id, update); + } + }); + } + + public async Task> BuscarAniversariantes(Filtros filtro) + { + int num = 3; + List clientesAtivosInativos1 = await Task.Run>(() => { + List clientesAtivosInativos; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientesAtivosInativos = read.get_ClienteRepository().BuscarAniversariantes(filtro, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 41, num, null, true); + continue; + } + return clientesAtivosInativos; + } + return new List(); + }); + return clientesAtivosInativos1; + } + + public async Task> BuscarAniversariantesVinculo(Filtros filtro, List vinculo) + { + int num = 3; + List clientesAtivosInativos1 = await Task.Run>(() => { + List clientesAtivosInativos; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientesAtivosInativos = read.get_ClienteRepository().BuscarAniversariantesVinculo(filtro, vinculo, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 41, num, null, true); + continue; + } + return clientesAtivosInativos; + } + return new List(); + }); + return clientesAtivosInativos1; + } + + public async Task> BuscarClassificacoes() + { + int num = 3; + List classificacaos1 = await Task.Run>(async () => { + List classificacaos; + while (true) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + classificacaos = await read.get_ClienteRepository().BuscarClassificacoes((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + return classificacaos; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 286, num, null, true); + } + if (num <= 0) + { + break; + } + } + classificacaos = new List(); + return classificacaos; + }); + return classificacaos1; + } + + internal async Task> BuscarCliente(string value, List vinculos = null, TipoFiltroCliente tipoFiltroCliente = 2) + { + List clientes1; + string str = value; + str = ValidationHelper.RemoverAcentos(str.Trim()); + if (!string.IsNullOrWhiteSpace(str)) + { + int num1 = 3; + clientes1 = await Task.Run>(() => { + List list; + while (num1 > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + long num = (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()); + List produtos = LicenseHelper.Produtos; + Func u003cu003e9_01 = ClienteServico.u003cu003ec.u003cu003e9__0_1; + if (u003cu003e9_01 == null) + { + u003cu003e9_01 = (Licenca x) => { + if (x.get_Produto() != 86) + { + return false; + } + return x.get_Status() != 3; + }; + ClienteServico.u003cu003ec.u003cu003e9__0_1 = u003cu003e9_01; + } + bool flag = produtos.Any(u003cu003e9_01); + List clientes = read.get_ClienteRepository().FindClienteVinculo(str, vinculos, num, Recursos.Usuario.get_Id() == (long)0, flag, tipoFiltroCliente); + Func u003cu003e9_02 = ClienteServico.u003cu003ec.u003cu003e9__0_2; + if (u003cu003e9_02 == null) + { + u003cu003e9_02 = (Cliente x) => x.get_Nome(); + ClienteServico.u003cu003ec.u003cu003e9__0_2 = u003cu003e9_02; + } + list = clientes.OrderBy(u003cu003e9_02).ToList(); + } + } + catch (Exception exception) + { + num1 = base.Registrar(exception, 29, num1, str, true); + continue; + } + return list; + } + return new List(); + }); + } + else + { + clientes1 = new List(); + } + return clientes1; + } + + internal async Task BuscarCliente(long id) + { + int num = 3; + Cliente cliente2 = await Task.Run(() => { + Cliente cliente; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + Cliente cliente1 = read.get_ClienteRepository().FindById(id); + cliente1.set_Nome(cliente1.get_Nome()); + cliente = cliente1; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 28, num, id, true); + continue; + } + return cliente; + } + return new Cliente(); + }); + return cliente2; + } + + public async Task BuscarClienteAsync(long id) + { + int num = 3; + Cliente cliente2 = await Task.Run(() => { + Cliente cliente; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + Cliente cliente1 = read.get_ClienteRepository().FindById(id); + cliente1.set_Nome(cliente1.get_Nome()); + cliente = cliente1; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 27, num, null, true); + continue; + } + return cliente; + } + return new Cliente(); + }); + return cliente2; + } + + internal async Task> BuscarClientePorDocumento(string documento) + { + List clientes1; + string upper = documento; + upper = ValidationHelper.RemoverAcentos(upper.Trim()).ToUpper(); + if (!string.IsNullOrWhiteSpace(upper)) + { + int num = 3; + clientes1 = await Task.Run>(() => { + List list; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clientes = read.get_ClienteRepository().FindClienteDocumento(upper); + Func u003cu003e9_11 = ClienteServico.u003cu003ec.u003cu003e9__1_1; + if (u003cu003e9_11 == null) + { + u003cu003e9_11 = (Cliente c) => c.get_Nome(); + ClienteServico.u003cu003ec.u003cu003e9__1_1 = u003cu003e9_11; + } + list = clientes.OrderBy(u003cu003e9_11).ToList(); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 29, num, upper, true); + continue; + } + return list; + } + return new List(); + }); + } + else + { + clientes1 = new List(); + } + return clientes1; + } + + public async Task> BuscarClientesAtvosInativos(bool completo) + { + int num = 3; + IEnumerable clientesAtivosInativos1 = await Task.Run>(async () => { + IEnumerable clientesAtivosInativos; + while (true) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientesAtivosInativos = await read.get_ClienteRepository().BuscaClientes(completo, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + return clientesAtivosInativos; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 286, num, null, true); + } + if (num <= 0) + { + break; + } + } + clientesAtivosInativos = new List(); + return clientesAtivosInativos; + }); + return clientesAtivosInativos1; + } + + public async Task> BuscarClientesAtvosInativosVinculo(bool completo, List vinculo) + { + int num = 3; + IEnumerable clientesAtivosInativos1 = await Task.Run>(async () => { + IEnumerable clientesAtivosInativos; + while (true) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientesAtivosInativos = await read.get_ClienteRepository().BuscaClientesVinculo(completo, vinculo, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + return clientesAtivosInativos; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 286, num, null, true); + } + if (num <= 0) + { + break; + } + } + clientesAtivosInativos = new List(); + return clientesAtivosInativos; + }); + return clientesAtivosInativos1; + } + + internal async Task> BuscarClienteVinculo(string value, long id) + { + List clientes1; + if (!string.IsNullOrWhiteSpace(value)) + { + int num = 3; + clientes1 = await Task.Run>(() => { + List list; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clientes = read.get_ClienteRepository().FindVinculo(value, id); + Func u003cu003e9_21 = ClienteServico.u003cu003ec.u003cu003e9__2_1; + if (u003cu003e9_21 == null) + { + u003cu003e9_21 = (Cliente x) => x.get_Nome(); + ClienteServico.u003cu003ec.u003cu003e9__2_1 = u003cu003e9_21; + } + list = clientes.OrderBy(u003cu003e9_21).ToList(); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 29, num, value, true); + continue; + } + return list; + } + return new List(); + }); + } + else + { + clientes1 = new List(); + } + return clientes1; + } + + internal async Task> BuscarContatosAsync(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + observableCollection = new ObservableCollection(read.get_MaisContatoRepository().FindByCustomerId(id)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 35, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + internal async Task> BuscarEmailsAsync(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clienteEmails = read.get_ClienteEmailRepository().FindByClienteId(id); + Func u003cu003e9_71 = ClienteServico.u003cu003ec.u003cu003e9__7_1; + if (u003cu003e9_71 == null) + { + u003cu003e9_71 = (ClienteEmail mail) => mail.get_Ordem(); + ClienteServico.u003cu003ec.u003cu003e9__7_1 = u003cu003e9_71; + } + observableCollection = new ObservableCollection(clienteEmails.OrderBy(u003cu003e9_71)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 32, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + public async Task> BuscarEmailsPorCliente(List ids) + { + int num = 3; + List clienteEmails1 = await Task.Run>(() => { + List clienteEmails; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clienteEmails = read.get_ClienteEmailRepository().FindByCliente(ids); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 37, num, null, true); + continue; + } + return clienteEmails; + } + return new List(); + }); + return clienteEmails1; + } + + internal async Task> BuscarEnderecosAsync(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clienteEnderecos = read.get_ClienteEnderecoRepository().FindByClienteId(id); + Func u003cu003e9_91 = ClienteServico.u003cu003ec.u003cu003e9__9_1; + if (u003cu003e9_91 == null) + { + u003cu003e9_91 = (ClienteEndereco x) => x.get_Ordem(); + ClienteServico.u003cu003ec.u003cu003e9__9_1 = u003cu003e9_91; + } + observableCollection = new ObservableCollection(clienteEnderecos.OrderBy(u003cu003e9_91)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 34, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + public async Task> BuscarEnderecosPorCliente(List clientes) + { + List clienteEnderecos1; + int num = 3; + List clientes1 = clientes; + if (!clientes1.All((Cliente x) => x.get_Id() < (long)0)) + { + clienteEnderecos1 = await Task.Run>(() => { + List clienteEnderecos; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clienteEnderecos = read.get_ClienteEnderecoRepository().FindByCliente(clientes); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 38, num, null, true); + continue; + } + return clienteEnderecos; + } + return new List(); + }); + } + else + { + clienteEnderecos1 = new List(); + } + return clienteEnderecos1; + } + + public async Task BuscarLogAntigo(long id) + { + int num = 3; + string str1 = await Task.Run(() => { + string str; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + str = read.get_ClienteRepository().BuscarLogAntigo(id, Connection.GetConnectionString()); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 319, num, id, true); + continue; + } + return str; + } + return null; + }); + return str1; + } + + internal DateTime? BuscarNascimento(long id) + { + DateTime? nullable; + int num = 3; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + nullable = read.get_ClienteRepository().BuscaNascimeto(id); + } + } + catch (Exception exception1) + { + Exception exception = exception1; + num = base.Registrar(exception, 328, num, id, true); + continue; + } + return nullable; + } + return null; + } + + public async Task> BuscarObsCliente(string pesquisa) + { + int num = 3; + List clientes1 = await Task.Run>(() => { + List clientes; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientes = read.get_ClienteRepository().FindObsCliente(pesquisa, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 39, num, null, true); + continue; + } + return clientes; + } + return new List(); + }); + return clientes1; + } + + public async Task> BuscarOrigens(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + observableCollection = new ObservableCollection(read.get_ClienteRepository().BuscarOrigem(id)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 326, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + public async Task> BuscarPastaCliente(string pesquisa, bool busca) + { + int num = 3; + List clientes1 = await Task.Run>(() => { + List clientes; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientes = read.get_ClienteRepository().FindPastaCliente(pesquisa, busca, (long)0); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 40, num, null, true); + continue; + } + return clientes; + } + return new List(); + }); + return clientes1; + } + + public async Task> BuscarProspect(Filtros filtro) + { + int num = 3; + List prospectars1 = await Task.Run>(async () => { + List prospectars; + while (true) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + prospectars = await read.get_ClienteRepository().BuscaProspeccoes(filtro, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + return prospectars; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 324, num, null, true); + } + if (num <= 0) + { + break; + } + } + prospectars = new List(); + return prospectars; + }); + return prospectars1; + } + + internal ObservableCollection BuscarTelefones(long id) + { + ObservableCollection observableCollection; + int num = 3; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + observableCollection = new ObservableCollection( + from x in read.get_ClienteTelefoneRepository().FindByClienteId(id) + orderby x.get_Ordem() + select x); + } + } + catch (Exception exception1) + { + Exception exception = exception1; + num = base.Registrar(exception, 30, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + } + + internal async Task> BuscarTelefonesAsync(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clienteTelefones = read.get_ClienteTelefoneRepository().FindByClienteId(id); + Func u003cu003e9_41 = ClienteServico.u003cu003ec.u003cu003e9__4_1; + if (u003cu003e9_41 == null) + { + u003cu003e9_41 = (ClienteTelefone x) => x.get_Ordem(); + ClienteServico.u003cu003ec.u003cu003e9__4_1 = u003cu003e9_41; + } + observableCollection = new ObservableCollection(clienteTelefones.OrderBy(u003cu003e9_41)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 30, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + internal async Task> BuscarTelefonesClientes(string telefone) + { + int num = 3; + List clienteTelefones1 = await Task.Run>(() => { + List clienteTelefones; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clienteTelefones = read.get_ClienteTelefoneRepository().Find(telefone, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 31, num, telefone, true); + continue; + } + return clienteTelefones; + } + return new List(); + }); + return clienteTelefones1; + } + + public async Task> BuscarTodosClientes() + { + int num = 3; + List clientesAtivosInativos1 = await Task.Run>(() => { + List list; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + List clientesAtivosInativos = read.get_ClienteRepository().FindAllClientes(false, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + Func u003cu003e9_141 = ClienteServico.u003cu003ec.u003cu003e9__14_1; + if (u003cu003e9_141 == null) + { + u003cu003e9_141 = (ClientesAtivosInativos x) => x.get_Nome(); + ClienteServico.u003cu003ec.u003cu003e9__14_1 = u003cu003e9_141; + } + list = clientesAtivosInativos.OrderBy(u003cu003e9_141).ToList(); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 36, num, null, true); + continue; + } + return list; + } + return new List(); + }); + return clientesAtivosInativos1; + } + + public async Task> BuscarVencimentosCnh(Filtros filtro) + { + int num = 3; + List clientesAtivosInativos1 = await Task.Run>(() => { + List clientesAtivosInativos; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + clientesAtivosInativos = read.get_ClienteRepository().BuscarVencimentoCnh(filtro, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 42, num, null, true); + continue; + } + return clientesAtivosInativos; + } + return new List(); + }); + return clientesAtivosInativos1; + } + + internal async Task> BuscarVinculosAsync(long id) + { + int num = 3; + ObservableCollection observableCollection1 = await Task.Run>(() => { + ObservableCollection observableCollection; + while (num > 0) + { + try + { + using (UnitOfWork read = Instancia.Read) + { + observableCollection = new ObservableCollection(read.get_ClienteVinculoRepository().FindByCliente(id)); + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 33, num, id, true); + continue; + } + return observableCollection; + } + return new ObservableCollection(); + }); + return observableCollection1; + } + + public async Task Delete(Cliente cliente) + { + int num = 3; + bool flag1 = await Task.Run(() => { + bool flag; + while (num > 0) + { + List registroLogs = new List(); + try + { + using (UnitOfWork commited = Instancia.Commited) + { + registroLogs.Add(base.CreateLog(cliente.get_Id(), cliente.GetValorOriginal(), 1, 2)); + commited.get_ClienteRepository().Merge(cliente); + base.SaveLog(registroLogs, commited); + commited.Commit(); + flag = true; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 172, num, cliente, true); + continue; + } + return flag; + } + return false; + }); + return flag1; + } + + public async Task SalvarObservacoes(long id, string observacao) + { + int num = 3; + base.Sucesso = true; + Funcoes.GetNetworkTime(); + string str1 = await Task.Run(() => { + string str; + while (num > 0) + { + List registroLogs = new List(); + try + { + using (UnitOfWork commited = Instancia.Commited) + { + Cliente cliente = commited.get_ClienteRepository().FindById(id); + cliente.Initialize(); + cliente.set_Observacao(observacao); + registroLogs.Add(base.CreateLog(cliente.get_Id(), cliente, 1)); + commited.get_ClienteRepository().Merge(cliente); + base.SaveLog(registroLogs, commited); + commited.Commit(); + } + str = observacao; + } + catch (Exception exception) + { + num = base.Registrar(exception, 171, num, new { id = id, observacao = observacao }, true); + continue; + } + return str; + } + return ""; + }); + return str1; + } + + public async Task Save(Cliente cliente, bool salvando = false) + { + int num = 3; + base.Sucesso = true; + Cliente cliente1 = cliente; + Cliente cliente2 = await Task.Run(() => { + Cliente cliente3; + List list; + List clienteEnderecos; + List maisContatos; + List clienteEmails; + List clienteVinculos; + while (num > 0) + { + List registroLogs = new List(); + cliente = cliente1; + try + { + TipoAcao tipoAcao = (cliente.get_Id() == 0 ? 0 : 1); + ObservableCollection telefones = cliente.get_Telefones(); + if (telefones != null) + { + list = telefones.ToList(); + } + else + { + list = null; + } + List clienteTelefones = list; + ObservableCollection enderecos = cliente.get_Enderecos(); + if (enderecos != null) + { + clienteEnderecos = enderecos.ToList(); + } + else + { + clienteEnderecos = null; + } + List clienteEnderecos1 = clienteEnderecos; + ObservableCollection contatos = cliente.get_Contatos(); + if (contatos != null) + { + maisContatos = contatos.ToList(); + } + else + { + maisContatos = null; + } + List maisContatos1 = maisContatos; + ObservableCollection emails = cliente.get_Emails(); + if (emails != null) + { + clienteEmails = emails.ToList(); + } + else + { + clienteEmails = null; + } + List clienteEmails1 = clienteEmails; + ObservableCollection vinculos = cliente.get_Vinculos(); + if (vinculos != null) + { + clienteVinculos = vinculos.ToList(); + } + else + { + clienteVinculos = null; + } + List clienteVinculos1 = clienteVinculos; + List origens = cliente.get_Origens(); + cliente.set_Telefones(null); + cliente.set_Enderecos(null); + cliente.set_Contatos(null); + cliente.set_Emails(null); + cliente.set_Vinculos(null); + cliente.set_Contatos(null); + cliente.set_Origens(null); + using (UnitOfWork commited = Instancia.Commited) + { + bool id = cliente.get_Id() == (long)0; + if (cliente.get_Id() != (long)0 & salvando) + { + id = true; + tipoAcao = 0; + } + if (tipoAcao == 1) + { + List objs = new List() + { + clienteTelefones, + clienteEnderecos1, + maisContatos1, + clienteEmails1, + clienteVinculos1, + cliente + }; + registroLogs.Add(base.CreateDynamicLog(cliente.get_Id(), objs, 1)); + List clienteTelefones1 = commited.get_ClienteTelefoneRepository().DeleteFone(cliente.get_Id(), clienteTelefones); + if (clienteTelefones1 != null) + { + clienteTelefones1.ForEach((ClienteTelefone fone) => this.logs.Add(base.CreateLog(cliente.get_Id(), fone.GetValorOriginal(), 1, 2))); + } + else + { + } + List clienteEnderecos2 = commited.get_ClienteEnderecoRepository().DeleteEndereco(cliente.get_Id(), clienteEnderecos1); + if (clienteEnderecos2 != null) + { + clienteEnderecos2.ForEach((ClienteEndereco endereco) => this.logs.Add(base.CreateLog(cliente.get_Id(), endereco.GetValorOriginal(), 1, 2))); + } + else + { + } + List maisContatos2 = commited.get_MaisContatoRepository().DeleteContato(cliente.get_Id(), maisContatos1); + if (maisContatos2 != null) + { + maisContatos2.ForEach((MaisContato contato) => this.logs.Add(base.CreateLog(cliente.get_Id(), contato.GetValorOriginal(), 1, 2))); + } + else + { + } + List clienteEmails2 = commited.get_ClienteEmailRepository().DeleteMail(cliente.get_Id(), clienteEmails1); + if (clienteEmails2 != null) + { + clienteEmails2.ForEach((ClienteEmail mail) => this.logs.Add(base.CreateLog(cliente.get_Id(), mail.GetValorOriginal(), 1, 2))); + } + else + { + } + List clienteVinculos2 = commited.get_ClienteVinculoRepository().DeleteVinculo(cliente.get_Id(), clienteVinculos1); + if (clienteVinculos2 != null) + { + clienteVinculos2.ForEach((ClienteVinculo vinculo) => this.logs.Add(base.CreateLog(cliente.get_Id(), vinculo.GetValorOriginal(), 1, 2))); + } + else + { + } + } + if (!id) + { + if (clienteTelefones != null) + { + clienteTelefones = commited.get_ClienteTelefoneRepository().Merge(clienteTelefones, cliente); + } + if (clienteEnderecos1 != null) + { + clienteEnderecos1 = commited.get_ClienteEnderecoRepository().Merge(clienteEnderecos1, cliente); + } + if (maisContatos1 != null) + { + maisContatos1 = commited.get_MaisContatoRepository().Merge(maisContatos1, cliente); + } + if (clienteEmails1 != null) + { + clienteEmails1 = commited.get_ClienteEmailRepository().Merge(clienteEmails1, cliente); + } + if (clienteVinculos1 != null) + { + clienteVinculos1 = commited.get_ClienteVinculoRepository().Merge(clienteVinculos1, cliente); + } + origens = commited.get_ClienteRepository().Sincronize(origens, cliente.get_Id()); + cliente = commited.get_ClienteRepository().Merge(cliente); + } + else + { + cliente = commited.get_ClienteRepository().SaveOrUpdate(cliente); + if (clienteTelefones != null) + { + clienteTelefones = commited.get_ClienteTelefoneRepository().Inserir(clienteTelefones, cliente); + } + if (clienteEnderecos1 != null) + { + clienteEnderecos1 = commited.get_ClienteEnderecoRepository().Inserir(clienteEnderecos1, cliente); + } + if (maisContatos1 != null) + { + maisContatos1 = commited.get_MaisContatoRepository().Inserir(maisContatos1, cliente); + } + if (clienteEmails1 != null) + { + clienteEmails1 = commited.get_ClienteEmailRepository().Inserir(clienteEmails1, cliente); + } + if (clienteVinculos1 != null) + { + clienteVinculos1 = commited.get_ClienteVinculoRepository().Inserir(clienteVinculos1, cliente); + } + if (origens != null) + { + origens.ForEach((OrigemCliente x) => { + x.set_Cliente(cliente); + x = commited.get_ClienteRepository().SaveOrUpdate(x); + }); + } + } + cliente.set_Nome(cliente.get_Nome()); + cliente.set_Telefones((clienteTelefones == null ? null : new ObservableCollection(clienteTelefones))); + cliente.set_Enderecos((clienteEnderecos1 == null ? null : new ObservableCollection(clienteEnderecos1))); + cliente.set_Contatos((maisContatos1 == null ? null : new ObservableCollection(maisContatos1))); + cliente.set_Emails((clienteEmails1 == null ? null : new ObservableCollection(clienteEmails1))); + cliente.set_Vinculos((clienteVinculos1 == null ? null : new ObservableCollection(clienteVinculos1))); + cliente.set_Origens(origens); + if (tipoAcao == null) + { + registroLogs.Add(base.CreateLog(cliente.get_Id(), cliente.GetValorOriginal(), 1, 0)); + ObservableCollection observableCollection = cliente.get_Telefones(); + if (observableCollection != null) + { + observableCollection.ToList().ForEach((ClienteTelefone fone) => this.logs.Add(base.CreateLog(cliente.get_Id(), fone.GetValorOriginal(), 1, 0))); + } + else + { + } + ObservableCollection enderecos1 = cliente.get_Enderecos(); + if (enderecos1 != null) + { + enderecos1.ToList().ForEach((ClienteEndereco endereco) => this.logs.Add(base.CreateLog(cliente.get_Id(), endereco.GetValorOriginal(), 1, 0))); + } + else + { + } + ObservableCollection contatos1 = cliente.get_Contatos(); + if (contatos1 != null) + { + contatos1.ToList().ForEach((MaisContato contato) => this.logs.Add(base.CreateLog(cliente.get_Id(), contato.GetValorOriginal(), 1, 0))); + } + else + { + } + ObservableCollection emails1 = cliente.get_Emails(); + if (emails1 != null) + { + emails1.ToList().ForEach((ClienteEmail mail) => this.logs.Add(base.CreateLog(cliente.get_Id(), mail.GetValorOriginal(), 1, 0))); + } + else + { + } + ObservableCollection vinculos1 = cliente.get_Vinculos(); + if (vinculos1 != null) + { + vinculos1.ToList().ForEach((ClienteVinculo vinculo) => this.logs.Add(base.CreateLog(cliente.get_Id(), vinculo.GetValorOriginal(), 1, 0))); + } + else + { + } + } + base.SaveLog(registroLogs, commited); + commited.Commit(); + cliente3 = cliente; + } + } + catch (Exception exception) + { + num = base.Registrar(exception, 171, num, cliente, true); + continue; + } + return cliente3; + } + return cliente1; + }); + return cliente2; + } + } +} \ No newline at end of file -- cgit v1.2.3