diff options
Diffstat (limited to 'Codemerx/Gestor.Application/Servicos/Financeiro/FinanceiroServico.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/Servicos/Financeiro/FinanceiroServico.cs | 738 |
1 files changed, 738 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Servicos/Financeiro/FinanceiroServico.cs b/Codemerx/Gestor.Application/Servicos/Financeiro/FinanceiroServico.cs new file mode 100644 index 0000000..817dca0 --- /dev/null +++ b/Codemerx/Gestor.Application/Servicos/Financeiro/FinanceiroServico.cs @@ -0,0 +1,738 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Generic;
+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.Financeiro;
+using Gestor.Model.Domain.Financeiro.Relatorios;
+using Gestor.Model.Domain.Generic;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.Servicos.Financeiro
+{
+ public class FinanceiroServico : BaseServico
+ {
+ public FinanceiroServico()
+ {
+ }
+
+ public async Task<List<Lancamento>> AddRange(List<Lancamento> lancamentos)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ List<Lancamento> lancamentos1 = lancamentos;
+ List<Lancamento> lancamentos2 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> lancamentos3;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ lancamentos = lancamentos1;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ ControleFinanceiro controle = lancamentos.First<Lancamento>().get_Controle();
+ controle = (controle.get_Id() == 0 ? commited.get_ControleFinanceiroRepository().SaveOrUpdate(controle) : commited.get_ControleFinanceiroRepository().Merge(controle));
+ lancamentos.ForEach((Lancamento x) => {
+ x.set_Controle(controle);
+ x.set_DataLancamento(new DateTime?(networkTime));
+ });
+ lancamentos = commited.get_LancamentoRepository().AddRange(lancamentos);
+ lancamentos.ForEach((Lancamento x) => this.logs.Add(base.CreateLog(x.get_Id(), x.GetValorOriginal(), 25, 0)));
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ lancamentos3 = lancamentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 279, num, lancamentos, true);
+ continue;
+ }
+ return lancamentos3;
+ }
+ return lancamentos1;
+ });
+ return lancamentos2;
+ }
+
+ public async Task<List<Lancamento>> Atualizar(List<Lancamento> lancamentos)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ Funcoes.GetNetworkTime();
+ List<Lancamento> lancamentos1 = lancamentos;
+ List<Lancamento> lancamentos2 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> lancamentos3;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ lancamentos = lancamentos1;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ lancamentos.ForEach((Lancamento lancamento) => {
+ registroLogs.Add(base.CreateLog(lancamento.get_Id(), lancamento, 25));
+ lancamento.set_Controle(commited.get_ControleFinanceiroRepository().Merge(lancamento.get_Controle()));
+ lancamento = commited.get_LancamentoRepository().Merge(lancamento);
+ });
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ lancamentos3 = lancamentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 280, num, lancamentos, true);
+ continue;
+ }
+ return lancamentos3;
+ }
+ return lancamentos1;
+ });
+ return lancamentos2;
+ }
+
+ public async Task<List<Lancamento>> BuscarFechamento(FiltroFinanceiro filtro)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> lancamentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ lancamentos = read.get_LancamentoRepository().Fechamento(filtro);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 294, num, filtro, true);
+ continue;
+ }
+ return lancamentos;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<Lancamento> BuscarLancamento(long id, int parcela)
+ {
+ int num = 3;
+ Lancamento lancamento1 = await Task.Run<Lancamento>(() => {
+ Lancamento lancamento;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ lancamento = read.get_LancamentoRepository().FindByControle(id, parcela);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 163, num, new { id = id, parcela = parcela }, true);
+ continue;
+ }
+ return lancamento;
+ }
+ return new Lancamento();
+ });
+ return lancamento1;
+ }
+
+ public async Task<Lancamento> BuscarLancamento(long id)
+ {
+ int num = 3;
+ Lancamento lancamento1 = await Task.Run<Lancamento>(() => {
+ Lancamento lancamento;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ lancamento = read.get_LancamentoRepository().FindById(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 164, num, id, true);
+ continue;
+ }
+ return lancamento;
+ }
+ return new Lancamento();
+ });
+ return lancamento1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentos(DateTime inicio, DateTime fim, StatusLancamento status)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().Find(inicio, fim, status);
+ Func<Lancamento, DateTime> u003cu003e9_41 = FinanceiroServico.u003cu003ec.u003cu003e9__4_1;
+ if (u003cu003e9_41 == null)
+ {
+ u003cu003e9_41 = (Lancamento x) => x.get_Vencimento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__4_1 = u003cu003e9_41;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime>(u003cu003e9_41).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 160, num, new { inicio = inicio, fim = fim, status = status }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentos(DateTime inicio, DateTime fim, long conta)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindLancamentosByConta(inicio, fim, conta);
+ Func<Lancamento, DateTime> u003cu003e9_61 = FinanceiroServico.u003cu003ec.u003cu003e9__6_1;
+ if (u003cu003e9_61 == null)
+ {
+ u003cu003e9_61 = (Lancamento x) => x.get_Vencimento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__6_1 = u003cu003e9_61;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime>(u003cu003e9_61).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 165, num, new { inicio = inicio, fim = fim, conta = conta }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPersonalizados(DateTime inicio, DateTime fim, StatusLancamento status, FiltroLancamentoData filtrodata)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindPersonalizado(inicio, fim, status, filtrodata);
+ Func<Lancamento, DateTime> u003cu003e9_71 = FinanceiroServico.u003cu003ec.u003cu003e9__7_1;
+ if (u003cu003e9_71 == null)
+ {
+ u003cu003e9_71 = (Lancamento x) => x.get_Vencimento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__7_1 = u003cu003e9_71;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime>(u003cu003e9_71).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 160, num, new { inicio = inicio, fim = fim, status = status }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorBaixa(DateTime inicio, DateTime fim)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindByBaixa(inicio, fim);
+ Func<Lancamento, DateTime?> u003cu003e9_81 = FinanceiroServico.u003cu003ec.u003cu003e9__8_1;
+ if (u003cu003e9_81 == null)
+ {
+ u003cu003e9_81 = (Lancamento x) => x.get_Baixa();
+ FinanceiroServico.u003cu003ec.u003cu003e9__8_1 = u003cu003e9_81;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime?>(u003cu003e9_81).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 161, num, new { inicio = inicio, fim = fim }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<ExtratoConta>> BuscarLancamentosPorConta(DateTime inicio, DateTime fim, long id)
+ {
+ int num = 3;
+ List<ExtratoConta> extratoContas1 = await Task.Run<List<ExtratoConta>>(() => {
+ List<ExtratoConta> extratoContas;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ extratoContas = read.get_LancamentoRepository().FindByConta(inicio, fim, id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 165, num, new { inicio = inicio, fim = fim, id = id }, true);
+ continue;
+ }
+ return extratoContas;
+ }
+ return new List<ExtratoConta>();
+ });
+ return extratoContas1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorControle(long id)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> lancamentos;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ lancamentos = read.get_LancamentoRepository().FindByControle(id, 2);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 158, num, new { id = id }, true);
+ continue;
+ }
+ return lancamentos;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorFornecedor(long id, StatusLancamento status)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindByFornecedor(id, status);
+ Func<Lancamento, DateTime> u003cu003e9_11 = FinanceiroServico.u003cu003ec.u003cu003e9__1_1;
+ if (u003cu003e9_11 == null)
+ {
+ u003cu003e9_11 = (Lancamento x) => x.get_Vencimento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__1_1 = u003cu003e9_11;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime>(u003cu003e9_11).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 157, num, new { id = id, status = status }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorFornecedor(long id, DateTime date, Sinal sinal)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindByFornecedor(id, date, sinal);
+ Func<Lancamento, DateTime> u003cu003e9_21 = FinanceiroServico.u003cu003ec.u003cu003e9__2_1;
+ if (u003cu003e9_21 == null)
+ {
+ u003cu003e9_21 = (Lancamento x) => x.get_Vencimento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__2_1 = u003cu003e9_21;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime>(u003cu003e9_21).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 157, num, new { id = id, date = date }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorLancamento(DateTime inicio, DateTime fim, StatusLancamento status)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindByLancamento(inicio, fim, status);
+ Func<Lancamento, DateTime?> u003cu003e9_51 = FinanceiroServico.u003cu003ec.u003cu003e9__5_1;
+ if (u003cu003e9_51 == null)
+ {
+ u003cu003e9_51 = (Lancamento x) => x.get_DataLancamento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__5_1 = u003cu003e9_51;
+ }
+ list = lancamentos.OrderByDescending<Lancamento, DateTime?>(u003cu003e9_51).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 329, num, new { inicio = inicio, fim = fim, status = status }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<List<Lancamento>> BuscarLancamentosPorPagamento(DateTime inicio, DateTime fim)
+ {
+ int num = 3;
+ List<Lancamento> lancamentos1 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> list;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ List<Lancamento> lancamentos = read.get_LancamentoRepository().FindByPagamento(inicio, fim);
+ Func<Lancamento, DateTime?> u003cu003e9_91 = FinanceiroServico.u003cu003ec.u003cu003e9__9_1;
+ if (u003cu003e9_91 == null)
+ {
+ u003cu003e9_91 = (Lancamento x) => x.get_Pagamento();
+ FinanceiroServico.u003cu003ec.u003cu003e9__9_1 = u003cu003e9_91;
+ }
+ list = lancamentos.OrderBy<Lancamento, DateTime?>(u003cu003e9_91).ToList<Lancamento>();
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 162, num, new { inicio = inicio, fim = fim }, true);
+ continue;
+ }
+ return list;
+ }
+ return new List<Lancamento>();
+ });
+ return lancamentos1;
+ }
+
+ public async Task<bool> Excluir(List<Lancamento> lancamentos)
+ {
+ int num = 3;
+ Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ lancamentos.ForEach((Lancamento x) => {
+ registroLogs.Add(base.CreateLog(x.get_Id(), x.GetValorOriginal(), 25, 2));
+ if (commited.get_LancamentoRepository().FindByControle(x.get_Controle().get_Id(), 2).Count == 1)
+ {
+ commited.get_ControleFinanceiroRepository().Delete(x.get_Controle().get_Id());
+ return;
+ }
+ x.get_Controle().set_Parcelas(x.get_Controle().get_Parcelas() - 1);
+ commited.get_ControleFinanceiroRepository().Merge(x.get_Controle());
+ commited.get_LancamentoRepository().Delete(x.get_Id());
+ });
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ }
+ flag = true;
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 282, num, lancamentos, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> Excluir(Lancamento lancamento)
+ {
+ int num = 3;
+ Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ registroLogs.Add(base.CreateLog(lancamento.get_Id(), lancamento.GetValorOriginal(), 25, 2));
+ if (commited.get_LancamentoRepository().FindByControle(lancamento.get_Controle().get_Id(), 2).Count != 1)
+ {
+ lancamento.get_Controle().set_Parcelas(lancamento.get_Controle().get_Parcelas() - 1);
+ commited.get_ControleFinanceiroRepository().Merge(lancamento.get_Controle());
+ commited.get_LancamentoRepository().Delete(lancamento.get_Id());
+ }
+ else
+ {
+ commited.get_ControleFinanceiroRepository().Delete(lancamento.get_Controle().get_Id());
+ }
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 282, num, lancamento, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<List<Lancamento>> IncluirRange(List<Lancamento> lancamentos)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ Funcoes.GetNetworkTime();
+ List<Lancamento> lancamentos1 = lancamentos;
+ List<Lancamento> lancamentos2 = await Task.Run<List<Lancamento>>(() => {
+ List<Lancamento> lancamentos3;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ lancamentos = lancamentos1;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ lancamentos.ForEach((Lancamento lancamento) => {
+ lancamento.set_Controle(commited.get_ControleFinanceiroRepository().Merge(lancamento.get_Controle()));
+ lancamento = commited.get_LancamentoRepository().SaveOrUpdate(lancamento);
+ registroLogs.Add(base.CreateLog(lancamento.get_Id(), lancamento.GetValorOriginal(), 25, 0));
+ });
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ lancamentos3 = lancamentos;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 281, num, lancamentos, true);
+ continue;
+ }
+ return lancamentos3;
+ }
+ return lancamentos1;
+ });
+ return lancamentos2;
+ }
+
+ public async Task<Lancamento> Save(Lancamento lancamento)
+ {
+ int num = 3;
+ base.Sucesso = true;
+ DateTime networkTime = Funcoes.GetNetworkTime();
+ Lancamento lancamento1 = lancamento;
+ Lancamento lancamento2 = await Task.Run<Lancamento>(() => {
+ Lancamento lancamento3;
+ bool flag;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ lancamento = lancamento1;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ flag = (lancamento.get_Id() == 0 ? false : true);
+ if (!flag)
+ {
+ lancamento.set_DataLancamento(new DateTime?(networkTime));
+ }
+ if (flag)
+ {
+ registroLogs.Add(base.CreateLog(lancamento.get_Id(), lancamento, 25));
+ }
+ ControleFinanceiro controle = lancamento.get_Controle();
+ controle = (controle.get_Id() == 0 ? commited.get_ControleFinanceiroRepository().SaveOrUpdate(controle) : commited.get_ControleFinanceiroRepository().Merge(controle));
+ lancamento.set_Controle(controle);
+ lancamento = (lancamento.get_Id() == 0 ? commited.get_LancamentoRepository().SaveOrUpdate(lancamento) : commited.get_LancamentoRepository().Merge(lancamento));
+ if (!flag)
+ {
+ registroLogs.Add(base.CreateLog(lancamento.get_Id(), lancamento.GetValorOriginal(), 25, 0));
+ }
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ lancamento3 = lancamento;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 279, num, lancamento, true);
+ continue;
+ }
+ return lancamento3;
+ }
+ return lancamento1;
+ });
+ return lancamento2;
+ }
+
+ public async Task<bool> TemLancamentosPorFornecedor(long id)
+ {
+ int num = 3;
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ try
+ {
+ using (UnitOfWork read = Instancia.Read)
+ {
+ flag = read.get_LancamentoRepository().HasByFornecedor(id);
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 154, num, id, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+
+ public async Task<bool> Transferir(Lancamento lancamentoOrigem, Lancamento lancamentoDestino)
+ {
+ int num = 3;
+ Lancamento lancamento = lancamentoOrigem;
+ Lancamento lancamento1 = lancamentoDestino;
+ Funcoes.GetNetworkTime();
+ bool flag1 = await Task.Run<bool>(() => {
+ bool flag;
+ while (num > 0)
+ {
+ List<RegistroLog> registroLogs = new List<RegistroLog>();
+ lancamentoOrigem = lancamento;
+ lancamentoDestino = lancamento1;
+ try
+ {
+ using (UnitOfWork commited = Instancia.Commited)
+ {
+ ControleFinanceiro controle = lancamentoOrigem.get_Controle();
+ controle = commited.get_ControleFinanceiroRepository().SaveOrUpdate(controle);
+ lancamentoOrigem.set_Controle(controle);
+ lancamentoDestino.set_Controle(controle);
+ lancamentoOrigem = commited.get_LancamentoRepository().SaveOrUpdate(lancamentoOrigem);
+ lancamentoDestino = commited.get_LancamentoRepository().SaveOrUpdate(lancamentoDestino);
+ registroLogs.Add(base.CreateLog(lancamentoOrigem.get_Id(), lancamentoOrigem.GetValorOriginal(), 25, 0));
+ registroLogs.Add(base.CreateLog(lancamentoDestino.get_Id(), lancamentoDestino.GetValorOriginal(), 25, 0));
+ base.SaveLog(registroLogs, commited);
+ commited.Commit();
+ flag = true;
+ }
+ }
+ catch (Exception exception)
+ {
+ num = base.Registrar(exception, 283, num, new { lancamentoOrigem = lancamentoOrigem, lancamentoDestino = lancamentoDestino }, true);
+ continue;
+ }
+ return flag;
+ }
+ return false;
+ });
+ return flag1;
+ }
+ }
+}
\ No newline at end of file |