diff options
Diffstat (limited to 'Decompiler/Gestor.Application.Servicos/VendedorUsuarioServico.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.Servicos/VendedorUsuarioServico.cs | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Servicos/VendedorUsuarioServico.cs b/Decompiler/Gestor.Application.Servicos/VendedorUsuarioServico.cs new file mode 100644 index 0000000..b73e0aa --- /dev/null +++ b/Decompiler/Gestor.Application.Servicos/VendedorUsuarioServico.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Generic; +using Gestor.Infrastructure.UnitOfWork.Generic; +using Gestor.Infrastructure.UnitOfWork.Logic; +using Gestor.Model.API; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.Servicos; + +public class VendedorUsuarioServico : BaseServico +{ + public async Task<List<VendedorUsuario>> FindByVinculo(Usuario usuario) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.VendedorUsuarioRepository.FindByVinculo(((DomainBase)usuario).Id).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)106, tries, usuario); + } + } + return new List<VendedorUsuario>(); + }); + } + + public async Task<List<VendedorUsuario>> SaveOrUpdate(List<VendedorUsuario> vinculo) + { + int tries = 3; + base.Sucesso = true; + List<VendedorUsuario> vinculoOriginal = vinculo; + return await Task.Run(delegate + { + while (tries > 0) + { + vinculo = vinculoOriginal; + try + { + UnitOfWork unitOfWork = Instancia.Commited; + try + { + vinculo.ForEach(delegate(VendedorUsuario x) + { + unitOfWork.VendedorUsuarioRepository.SaveOrUpdate(x); + }); + ((GenericUnitOfWork)unitOfWork).Commit(); + } + finally + { + if (unitOfWork != null) + { + ((IDisposable)unitOfWork).Dispose(); + } + } + return vinculo; + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)271, tries, vinculo); + } + } + return vinculoOriginal; + }); + } + + public async Task<bool> Delete(List<VendedorUsuario> vinculo) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork unitOfWork = Instancia.Commited; + try + { + vinculo.ForEach(delegate(VendedorUsuario x) + { + unitOfWork.VendedorUsuarioRepository.Delete(((DomainBase)x).Id); + }); + ((GenericUnitOfWork)unitOfWork).Commit(); + } + finally + { + if (unitOfWork != null) + { + ((IDisposable)unitOfWork).Dispose(); + } + } + return true; + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)272, tries, vinculo); + } + } + return false; + }); + } + + public async Task<bool> FindVinculo(Vendedor vendedor) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.VendedorUsuarioRepository.Exist(((DomainBase)vendedor).Id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)271, tries, vendedor); + } + } + return false; + }); + } + + public async Task<bool> FindVinculoByUsuario(long idusuario) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.VendedorUsuarioRepository.ExistVinculoUsuario(idusuario); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)106, tries); + } + } + return false; + }); + } +} |