diff options
Diffstat (limited to 'Codemerx/Gestor.Application/Servicos/ParcelaServico.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/Servicos/ParcelaServico.cs | 1006 |
1 files changed, 1006 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Servicos/ParcelaServico.cs b/Codemerx/Gestor.Application/Servicos/ParcelaServico.cs new file mode 100644 index 0000000..fcb987e --- /dev/null +++ b/Codemerx/Gestor.Application/Servicos/ParcelaServico.cs @@ -0,0 +1,1006 @@ +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.Domain.Common;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Relatorios;
+using Gestor.Model.Domain.Relatorios.PrevisaoPagamentoComissao;
+using Gestor.Model.Domain.Seguros;
+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
+{
+ internal class ParcelaServico : BaseServico
+ {
+ public ParcelaServico()
+ {
+ }
+
+ public async Task<Documento> BuscarApolice(long id)
+ {
+ int num = 3;
+ Documento documento1 = await Task.Run<Documento>(() => {
+ Documento documento;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documento = read.get_ParcelaRepository().BuscarApolice(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 3, num, id, true);
+ continue;
+ }
+ return documento;
+ }
+ return new Documento();
+ });
+ return documento1;
+ }
+
+ public async Task<List<Documento>> BuscarFatura(string numero)
+ {
+ 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_ParcelaRepository().FindNumFatura(numero);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 322, num, numero, true);
+ continue;
+ }
+ return documentos;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Documento>> BuscarFaturas(Filtros filtro, bool buscaAssinaturas = 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_ParcelaRepository().BuscaDocumentosPorVigencia(filtro, buscaAssinaturas, painelBi);
+ return documentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 76, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ documentos = new List<Documento>();
+ return documentos;
+ });
+ 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_ParcelaRepository().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<VendedorParcela>> BuscarPagamentoVendedor(Filtros filtro, bool reciboPagamento, bool segundaViaReciboPagamento)
+ {
+ int num = 3;
+ List<VendedorParcela> vendedorParcelas1 = await Task.Run<List<VendedorParcela>>(() => {
+ List<VendedorParcela> vendedorParcelas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ IParcelaRepository parcelaRepository = read.get_ParcelaRepository();
+ Filtros filtro1 = filtro;
+ bool flag = reciboPagamento;
+ bool flag1 = segundaViaReciboPagamento;
+ List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ Func<ConfiguracaoSistema, bool> u003cu003e9_201 = ParcelaServico.u003cu003ec.u003cu003e9__20_1;
+ if (u003cu003e9_201 == null)
+ {
+ u003cu003e9_201 = (ConfiguracaoSistema x) => x.get_Configuracao() == 34;
+ ParcelaServico.u003cu003ec.u003cu003e9__20_1 = u003cu003e9_201;
+ }
+ vendedorParcelas = parcelaRepository.FindByPagamento(filtro1, flag, flag1, configuracoes.Any<ConfiguracaoSistema>(u003cu003e9_201));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 80, num, filtro, true);
+ continue;
+ }
+ return vendedorParcelas;
+ }
+ return new List<VendedorParcela>();
+ });
+ return vendedorParcelas1;
+ }
+
+ public async Task<Parcela> BuscarParcela(long id)
+ {
+ int num = 3;
+ Parcela parcela1 = await Task.Run<Parcela>(() => {
+ Parcela parcela;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcela = read.get_ParcelaRepository().FindById(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 74, num, id, true);
+ continue;
+ }
+ return parcela;
+ }
+ return new Parcela();
+ });
+ return parcela1;
+ }
+
+ internal async Task<List<Parcela>> BuscarParcelas(long id)
+ {
+ int num = 3;
+ List<Parcela> parcelas1 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Parcela> parcelas = read.get_ParcelaRepository().FindByDocumentId(id);
+ Func<Parcela, int> u003cu003e9_31 = ParcelaServico.u003cu003ec.u003cu003e9__3_1;
+ if (u003cu003e9_31 == null)
+ {
+ u003cu003e9_31 = (Parcela x) => x.get_NumeroParcela();
+ ParcelaServico.u003cu003ec.u003cu003e9__3_1 = u003cu003e9_31;
+ }
+ list = parcelas.OrderBy<Parcela, int>(u003cu003e9_31).ToList<Parcela>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 73, num, id, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Parcela>();
+ });
+ return parcelas1;
+ }
+
+ internal async Task<List<Documento>> BuscarParcelas(string ids, List<Documento> documentos)
+ {
+ int num = 3;
+ List<Documento> documentos1 = await Task.Run<List<Documento>>(() => {
+ List<Documento> documentos2;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ documentos2 = read.get_ParcelaRepository().FindByDocumentIds(ids, documentos);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 75, num, null, true);
+ continue;
+ }
+ return documentos2;
+ }
+ return new List<Documento>();
+ });
+ return documentos1;
+ }
+
+ public async Task<List<Parcela>> BuscarParcelas(Filtros filtro, bool somenteAtivos = false)
+ {
+ int num = 3;
+ List<Parcela> parcelas1 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> parcelas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcelas = read.get_ParcelaRepository().FindByPendente(filtro, false, somenteAtivos);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 79, num, filtro, true);
+ continue;
+ }
+ return parcelas;
+ }
+ return new List<Parcela>();
+ });
+ return parcelas1;
+ }
+
+ internal async Task<ObservableCollection<Parcela>> BuscarParcelasAsync(long id)
+ {
+ int num = 3;
+ ObservableCollection<Parcela> observableCollection1 = await Task.Run<ObservableCollection<Parcela>>(() => {
+ ObservableCollection<Parcela> observableCollection;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Parcela> parcelas = read.get_ParcelaRepository().FindByDocumentId(id);
+ Func<Parcela, int> u003cu003e9_01 = ParcelaServico.u003cu003ec.u003cu003e9__0_1;
+ if (u003cu003e9_01 == null)
+ {
+ u003cu003e9_01 = (Parcela x) => x.get_NumeroParcela();
+ ParcelaServico.u003cu003ec.u003cu003e9__0_1 = u003cu003e9_01;
+ }
+ observableCollection = new ObservableCollection<Parcela>(parcelas.OrderBy<Parcela, int>(u003cu003e9_01));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 73, num, id, true);
+ continue;
+ }
+ return observableCollection;
+ }
+ return new ObservableCollection<Parcela>();
+ });
+ return observableCollection1;
+ }
+
+ public async Task<List<Parcela>> BuscarParcelasPendentes(Filtros filtro, bool somenteAtivos = false)
+ {
+ int num = 3;
+ List<Parcela> parcelas1 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> parcelas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcelas = read.get_ParcelaRepository().FindByPendente(filtro, true, somenteAtivos);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 78, num, filtro, true);
+ continue;
+ }
+ return parcelas;
+ }
+ return new List<Parcela>();
+ });
+ return parcelas1;
+ }
+
+ internal async Task<ObservableCollection<Parcela>> BuscarParcelasPorDocumento(Documento documento)
+ {
+ int num = 3;
+ ObservableCollection<Parcela> observableCollection1 = await Task.Run<ObservableCollection<Parcela>>(() => {
+ ObservableCollection<Parcela> observableCollection;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Parcela> parcelas = read.get_ParcelaRepository().FindByDocumento(documento);
+ Func<Parcela, int> u003cu003e9_11 = ParcelaServico.u003cu003ec.u003cu003e9__1_1;
+ if (u003cu003e9_11 == null)
+ {
+ u003cu003e9_11 = (Parcela x) => x.get_NumeroParcela();
+ ParcelaServico.u003cu003ec.u003cu003e9__1_1 = u003cu003e9_11;
+ }
+ observableCollection = new ObservableCollection<Parcela>(parcelas.OrderBy<Parcela, int>(u003cu003e9_11));
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 73, num, documento.get_Id(), true);
+ continue;
+ }
+ return observableCollection;
+ }
+ return new ObservableCollection<Parcela>();
+ });
+ return observableCollection1;
+ }
+
+ public async Task<List<Parcela>> BuscarParcelasRecebimento(Filtros filtro)
+ {
+ int num = 3;
+ List<Parcela> parcelas1 = await Task.Run<List<Parcela>>(async () => {
+ List<Parcela> parcelas;
+ while (true)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcelas = await read.get_ParcelaRepository().FindByRecebimento(filtro);
+ return parcelas;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 77, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ parcelas = new List<Parcela>();
+ return parcelas;
+ });
+ return parcelas1;
+ }
+
+ public async Task<List<PrevisaoPagamento>> BuscarPrevisaoPagamentoComissao(Filtros filtro)
+ {
+ int num = 3;
+ List<PrevisaoPagamento> previsaoPagamentos1 = await Task.Run<List<PrevisaoPagamento>>(() => {
+ List<PrevisaoPagamento> previsaoPagamentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ previsaoPagamentos = read.get_ParcelaRepository().PrevisaoPagamentoComissao(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 316, num, filtro, true);
+ continue;
+ }
+ return previsaoPagamentos;
+ }
+ return new List<PrevisaoPagamento>();
+ });
+ return previsaoPagamentos1;
+ }
+
+ internal async Task<List<Parcela>> BuscarTodasParcelas(List<long> ids)
+ {
+ int num = 3;
+ List<Parcela> parcelas1 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> parcelas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ parcelas = read.get_ParcelaRepository().FindByDocumentId(ids);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 73, num, ids, true);
+ continue;
+ }
+ return parcelas;
+ }
+ return new List<Parcela>();
+ });
+ return parcelas1;
+ }
+
+ internal async Task<List<Vendedor>> BuscarVendedores(long id)
+ {
+ int num = 3;
+ List<Vendedor> vendedors = await Task.Run<List<Vendedor>>(() => {
+ List<Vendedor> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<VendedorParcela> vendedorParcelas = read.get_VendedorParcelaRepository().FindByDocumentId(id);
+ Func<VendedorParcela, long> u003cu003e9_51 = ParcelaServico.u003cu003ec.u003cu003e9__5_1;
+ if (u003cu003e9_51 == null)
+ {
+ u003cu003e9_51 = (VendedorParcela x) => x.get_Vendedor().get_Id();
+ ParcelaServico.u003cu003ec.u003cu003e9__5_1 = u003cu003e9_51;
+ }
+ IEnumerable<IGrouping<long, VendedorParcela>> groupings = vendedorParcelas.GroupBy<VendedorParcela, long>(u003cu003e9_51);
+ Func<IGrouping<long, VendedorParcela>, Vendedor> u003cu003e9_52 = ParcelaServico.u003cu003ec.u003cu003e9__5_2;
+ if (u003cu003e9_52 == null)
+ {
+ u003cu003e9_52 = (IGrouping<long, VendedorParcela> x) => x.First<VendedorParcela>().get_Vendedor();
+ ParcelaServico.u003cu003ec.u003cu003e9__5_2 = u003cu003e9_52;
+ }
+ list = groupings.Select<IGrouping<long, VendedorParcela>, Vendedor>(u003cu003e9_52).ToList<Vendedor>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 140, num, null, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Vendedor>();
+ });
+ return vendedors;
+ }
+
+ public async Task<bool> Delete(Parcela parcela, List<Parcela> todas)
+ {
+ int num = 3;
+ Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_ParcelaRepository().Delete(parcela.get_Id());
+ List<RegistroLog> registroLogs = new List<RegistroLog>()
+ {
+ base.CreateLog(parcela.get_Id(), parcela.GetValorOriginal(), 5, 2)
+ };
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 190, num, parcela, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> DeletePagamentoRange(List<VendedorParcela> repasses)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ commited.get_VendedorParcelaRepository().DeleteRange(repasses);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 21, num, repasses, false);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<List<Documento>> FaturaPendente(Filtros filtro)
+ {
+ 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_ParcelaRepository().FaturaPendente(filtro);
+ return documentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 83, num, filtro, true);
+ }
+ if (num <= 0)
+ {
+ break;
+ }
+ }
+ documentos = new List<Documento>();
+ return documentos;
+ });
+ return documentos1;
+ }
+
+ public async Task<bool> GerarPagamento(List<VendedorParcela> pagamentos)
+ {
+ int num = 3;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ IVendedorParcelaRepository vendedorParcelaRepository = commited.get_VendedorParcelaRepository();
+ List<VendedorParcela> vendedorParcelas = pagamentos;
+ Func<VendedorParcela, long> u003cu003e9_221 = ParcelaServico.u003cu003ec.u003cu003e9__22_1;
+ if (u003cu003e9_221 == null)
+ {
+ u003cu003e9_221 = (VendedorParcela x) => x.get_Id();
+ ParcelaServico.u003cu003ec.u003cu003e9__22_1 = u003cu003e9_221;
+ }
+ if (vendedorParcelaRepository.GerarPagamento(vendedorParcelas.Select<VendedorParcela, long>(u003cu003e9_221).ToList<long>(), networkTime))
+ {
+ commited.Commit();
+ flag = true;
+ }
+ else
+ {
+ flag = false;
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 193, num, pagamentos, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<string> SalvarObservacoes(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)
+ {
+ Parcela parcela = commited.get_ParcelaRepository().FindById(id);
+ parcela.Initialize();
+ parcela.set_Observacao(observacao);
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), parcela, 5));
+ commited.get_ParcelaRepository().Merge(parcela);
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ }
+ str = observacao;
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 24, num, new { id = id, observacao = observacao }, true);
+ continue;
+ }
+ return str;
+ }
+ return "";
+ });
+ return str1;
+ }
+
+ public async Task<Parcela> Save(Parcela parcela, List<Parcela> todas, List<VendedorParcela> repasses = null, bool abrirTela = true)
+ {
+ Func<Parcela, bool> func1 = null;
+ int num = 3;
+ base.Sucesso = true;
+ Parcela parcela2 = parcela;
+ List<VendedorParcela> vendedorParcelas = repasses;
+ Funcoes.GetNetworkTime();
+ ObservableCollection<Parcela> observableCollection1 = await this.BuscarParcelasAsync(parcela.get_Documento().get_Id());
+ ObservableCollection<Parcela> observableCollection2 = observableCollection1;
+ Parcela parcela3 = await Task.Run<Parcela>(async () => {
+ Parcela parcela4;
+ while (num > 0)
+ {
+ try
+ {
+ ObservableCollection<Parcela> observableCollection = observableCollection2;
+ Func<Parcela, bool> u003cu003e9_1 = func1;
+ if (u003cu003e9_1 == null)
+ {
+ Func<Parcela, bool> id = (Parcela x) => x.get_Id() == parcela.get_Id();
+ Func<Parcela, bool> func = id;
+ func1 = id;
+ u003cu003e9_1 = func;
+ }
+ Parcela parcela1 = observableCollection.FirstOrDefault<Parcela>(u003cu003e9_1);
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ bool flag = parcela.get_Id() == (long)0;
+ parcela.set_IdEmpresa(parcela.get_Documento().get_Controle().get_IdEmpresa());
+ parcela = (flag ? commited.get_ParcelaRepository().SaveOrUpdate(parcela) : commited.get_ParcelaRepository().Merge(parcela));
+ if (repasses != null)
+ {
+ foreach (VendedorParcela repass in repasses)
+ {
+ repass.set_Documento(parcela.get_Documento());
+ repass.set_Parcela(parcela);
+ if (repass.get_Id() != 0)
+ {
+ commited.get_VendedorParcelaRepository().Merge(repass);
+ }
+ else
+ {
+ commited.get_VendedorParcelaRepository().SaveOrUpdate(repass);
+ }
+ }
+ parcela.set_Vendedores(new ObservableCollection<VendedorParcela>(repasses));
+ }
+ if (!flag)
+ {
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), parcela.Compare(parcela1.GetValorOriginal()), 5, 1));
+ }
+ else
+ {
+ registroLogs.Add(base.CreateLog(parcela.get_Id(), parcela.GetValorOriginal(), 5, 0));
+ }
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ parcela4 = parcela;
+ return parcela4;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 24, num, parcela2, abrirTela);
+ }
+ }
+ parcela2.set_Vendedores((vendedorParcelas != null ? new ObservableCollection<VendedorParcela>(vendedorParcelas) : null));
+ parcela4 = parcela2;
+ return parcela4;
+ });
+ return parcela3;
+ }
+
+ public async Task<VendedorParcela> Save(VendedorParcela pagamento)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ Funcoes.GetNetworkTime();
+ VendedorParcela vendedorParcela2 = await Task.Run<VendedorParcela>(() => {
+ VendedorParcela vendedorParcela;
+ while (num > 0)
+ {
+ VendedorParcela vendedorParcela1 = pagamento;
+ try
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ vendedorParcela1 = (vendedorParcela1.get_Id() == 0 ? commited.get_VendedorParcelaRepository().SaveOrUpdate(vendedorParcela1) : commited.get_VendedorParcelaRepository().Merge(vendedorParcela1));
+ if (pagamento.get_Id() != 0)
+ {
+ registroLogs.Add(base.CreateLog(vendedorParcela1.get_Id(), vendedorParcela1.Compare(vendedorParcela1.GetValorOriginal()), 37, 1));
+ }
+ else
+ {
+ registroLogs.Add(base.CreateLog(vendedorParcela1.get_Id(), vendedorParcela1.GetValorOriginal(), 37, 0));
+ }
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ vendedorParcela = vendedorParcela1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 189, num, pagamento, true);
+ continue;
+ }
+ return vendedorParcela;
+ }
+ return pagamento;
+ });
+ return vendedorParcela2;
+ }
+
+ public async Task<List<Parcela>> SaveRange(List<Parcela> parcela)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ List<Parcela> parcelas2 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> parcelas;
+ while (num > 0)
+ {
+ List<Parcela> parcelas1 = parcela;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ foreach (Parcela parcela1 in parcelas1)
+ {
+ if (parcela1.get_Id() != 0)
+ {
+ commited.get_ParcelaRepository().Merge(parcela1);
+ }
+ else
+ {
+ parcela1.set_IdEmpresa(parcela1.get_Documento().get_Controle().get_IdEmpresa());
+ commited.get_ParcelaRepository().SaveOrUpdate(parcela1);
+ }
+ }
+ commited.Commit();
+ parcelas = parcelas1;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 24, num, parcela, true);
+ continue;
+ }
+ return parcelas;
+ }
+ return parcela;
+ });
+ return parcelas2;
+ }
+
+ public async Task<bool> SaveRange(List<VendedorParcela> repasses)
+ {
+ int num = 3;
+ List<VendedorParcela> vendedorParcelas1 = repasses;
+ Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ repasses = vendedorParcelas1;
+ try
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ List<VendedorParcela> vendedorParcelas = repasses;
+ if (vendedorParcelas != null)
+ {
+ vendedorParcelas.ForEach((VendedorParcela x) => {
+ x.get_Id();
+ x = (x.get_Id() == 0 ? commited.get_VendedorParcelaRepository().SaveOrUpdate(x) : commited.get_VendedorParcelaRepository().Merge(x));
+ if (x.get_Id() == 0)
+ {
+ registroLogs.Add(base.CreateLog(x.get_Id(), x.GetValorOriginal(), 37, 0));
+ return;
+ }
+ registroLogs.Add(base.CreateLog(x.get_Id(), x.Compare(x.GetValorOriginal()), 37, 1));
+ });
+ }
+ else
+ {
+ }
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 189, num, repasses, false);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> TemPagamento(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().TemPagamentoParcela(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 82, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> UpdateDetalhes(List<DetalheExtrato> detalhes)
+ {
+ int num = 3;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ bool flag3 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ Func<ConfiguracaoSistema, bool> u003cu003e9_141 = ParcelaServico.u003cu003ec.u003cu003e9__14_1;
+ if (u003cu003e9_141 == null)
+ {
+ u003cu003e9_141 = (ConfiguracaoSistema x) => x.get_Configuracao() == 51;
+ ParcelaServico.u003cu003ec.u003cu003e9__14_1 = u003cu003e9_141;
+ }
+ bool flag1 = configuracoes.Any<ConfiguracaoSistema>(u003cu003e9_141);
+ bool flag2 = commited.get_ParcelaRepository().Update(detalhes, flag1);
+ IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
+ detalhes.ForEach((DetalheExtrato x) => {
+ string str;
+ 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(23);
+ registroLog.set_Versao(LoginViewModel.VersaoAtual);
+ registroLog.set_NomeMaquina(Environment.MachineName);
+ registroLog.set_UsuarioMaquina(Environment.UserName);
+ IPAddress[] addressList = hostEntry.AddressList;
+ Func<IPAddress, bool> u003cu003e9_143 = ParcelaServico.u003cu003ec.u003cu003e9__14_3;
+ if (u003cu003e9_143 == null)
+ {
+ u003cu003e9_143 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
+ ParcelaServico.u003cu003ec.u003cu003e9__14_3 = u003cu003e9_143;
+ }
+ IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_143);
+ str = (pAddress != null ? pAddress.ToString() : null);
+ registroLog.set_Ip(str);
+ base.SaveLog(registroLog, commited);
+ });
+ commited.Commit();
+ flag = flag2;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 192, num, detalhes, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag3;
+ }
+
+ public async Task<List<Parcela>> UpdateRange(List<Parcela> parcelas)
+ {
+ base.Sucesso = true;
+ int num = 3;
+ List<Parcela> parcelas1 = parcelas;
+ Funcoes.GetNetworkTime();
+ List<Parcela> parcelas2 = await Task.Run<List<Parcela>>(() => {
+ List<Parcela> parcelas3;
+ while (num > 0)
+ {
+ parcelas = parcelas1;
+ try
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ parcelas = commited.get_ParcelaRepository().UpdateRange(parcelas);
+ parcelas.ForEach((Parcela x) => {
+ registroLogs.Add(base.CreateLog(x.get_Id(), x.Compare(x.GetValorOriginal()), 5, 1));
+ base.SaveLog(registroLogs, commited);
+ });
+ commited.Commit();
+ parcelas3 = parcelas;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 24, num, parcelas, false);
+ continue;
+ }
+ return parcelas3;
+ }
+ return parcelas1;
+ });
+ return parcelas2;
+ }
+ }
+}
\ No newline at end of file |