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.Generic; using Gestor.Model.Domain.Seguros; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Gestor.Application.Servicos { public class VendedorUsuarioServico : BaseServico { public VendedorUsuarioServico() { } public async Task Delete(List vinculo) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork commited = Instancia.Commited) { vinculo.ForEach((VendedorUsuario x) => commited.get_VendedorUsuarioRepository().Delete(x.get_Id())); commited.Commit(); } flag = true; } catch (Exception exception) { num = base.Registrar(exception, 272, num, vinculo, true); continue; } return flag; } return false; }); return flag1; } public async Task> FindByVinculo(Usuario usuario) { int num = 3; List vendedorUsuarios = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { list = read.get_VendedorUsuarioRepository().FindByVinculo(usuario.get_Id()).ToList(); } } catch (Exception exception) { num = base.Registrar(exception, 106, num, usuario, true); continue; } return list; } return new List(); }); return vendedorUsuarios; } public async Task FindVinculo(Vendedor vendedor) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_VendedorUsuarioRepository().Exist(vendedor.get_Id()); } } catch (Exception exception) { num = base.Registrar(exception, 271, num, vendedor, true); continue; } return flag; } return false; }); return flag1; } public async Task FindVinculoByUsuario(long idusuario) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_VendedorUsuarioRepository().ExistVinculoUsuario(idusuario); } } catch (Exception exception) { num = base.Registrar(exception, 106, num, null, true); continue; } return flag; } return false; }); return flag1; } public async Task> SaveOrUpdate(List vinculo) { int num = 3; base.Sucesso = true; List vendedorUsuarios1 = vinculo; List vendedorUsuarios2 = await Task.Run>(() => { List vendedorUsuarios; while (num > 0) { vinculo = vendedorUsuarios1; try { using (UnitOfWork commited = Instancia.Commited) { vinculo.ForEach((VendedorUsuario x) => commited.get_VendedorUsuarioRepository().SaveOrUpdate(x)); commited.Commit(); } vendedorUsuarios = vinculo; } catch (Exception exception) { num = base.Registrar(exception, 271, num, vinculo, true); continue; } return vendedorUsuarios; } return vendedorUsuarios1; }); return vendedorUsuarios2; } } }