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.Domain.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Gestor.Application.Servicos.Ferramentas { internal class EstipulanteServico : BaseServico { public EstipulanteServico() { } internal async Task BuscarEstipulantePorId(long id) { int num = 3; Estipulante estipulante1 = await Task.Run(() => { Estipulante estipulante; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { estipulante = read.get_EstipulanteRepository().FindById(id); } } catch (Exception exception) { num = base.Registrar(exception, 110, num, id, true); continue; } return estipulante; } return new Estipulante(); }); return estipulante1; } public async Task Delete(Estipulante estipulante) { 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(estipulante.get_Id(), estipulante.GetValorOriginal(), 9, 2)); commited.get_EstipulanteRepository().Delete(estipulante.get_Id()); base.SaveLog(registroLogs, commited); commited.Commit(); flag = true; } } catch (Exception exception) { num = base.Registrar(exception, 220, num, estipulante, true); continue; } return flag; } return false; }); return flag1; } public async Task Save(Estipulante estipulante) { int num = 3; base.Sucesso = true; Estipulante estipulante1 = estipulante; Estipulante estipulante2 = await Task.Run(() => { Estipulante estipulante3; bool flag; while (num > 0) { List registroLogs = new List(); estipulante = estipulante1; try { using (UnitOfWork commited = Instancia.Commited) { estipulante.set_IdEmpresa(Recursos.Empresa.get_Id()); flag = (estipulante.get_Id() == 0 ? false : true); if (flag) { registroLogs.Add(base.CreateLog(estipulante.get_Id(), estipulante, 9)); } estipulante = (estipulante.get_Id() == 0 ? commited.get_EstipulanteRepository().SaveOrUpdate(estipulante) : commited.get_EstipulanteRepository().Merge(estipulante)); if (!flag) { registroLogs.Add(base.CreateLog(estipulante.get_Id(), estipulante.GetValorOriginal(), 9, 0)); } base.SaveLog(registroLogs, commited); commited.Commit(); estipulante3 = estipulante; } } catch (Exception exception) { num = base.Registrar(exception, 219, num, estipulante, true); continue; } return estipulante3; } return estipulante1; }); return estipulante2; } } }