summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos.Ferramentas/EmailServico.cs
blob: 1a9c528147dea138484bda67d1d15261109608cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Generic;
using Gestor.Common.Helpers;
using Gestor.Infrastructure.UnitOfWork.Generic;
using Gestor.Infrastructure.UnitOfWork.Logic;
using Gestor.Model.API;
using Gestor.Model.Common;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;

namespace Gestor.Application.Servicos.Ferramentas;

internal class EmailServico : BaseServico
{
	public async Task<Credencial> Save(Credencial credencial)
	{
		int tries = 3;
		base.Sucesso = true;
		Credencial credencialOriginal = credencial;
		return await Task.Run((Func<Credencial>)delegate
		{
			List<RegistroLog> list = new List<RegistroLog>();
			credencial = credencialOriginal;
			while (tries > 0)
			{
				credencial = credencialOriginal;
				try
				{
					UnitOfWork commited = Instancia.Commited;
					try
					{
						bool num = ((DomainBase)credencial).Id != 0L;
						credencial.Senha = EncryptionHelper.Encrypt(credencial.Senha);
						if (num)
						{
							list.Add(CreateLog(((DomainBase)credencial).Id, credencial, (TipoTela)17));
						}
						credencial = ((((DomainBase)credencial).Id == 0L) ? commited.CredencialRepository.SaveOrUpdate(credencial) : commited.CredencialRepository.Merge(credencial));
						if (!num)
						{
							list.Add(CreateLog(((DomainBase)credencial).Id, ((DomainBase)credencial).GetValorOriginal(), (TipoTela)17, (TipoAcao)0));
						}
						SaveLog(list, commited);
						((GenericUnitOfWork)commited).Commit();
						return credencial;
					}
					finally
					{
						((IDisposable)commited)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)217, tries, credencial);
				}
			}
			return credencialOriginal;
		});
	}

	public async Task<bool> Delete(Credencial email)
	{
		int tries = 3;
		return await Task.Run(delegate
		{
			while (tries > 0)
			{
				List<RegistroLog> list = new List<RegistroLog>();
				try
				{
					UnitOfWork commited = Instancia.Commited;
					try
					{
						list.Add(CreateLog(((DomainBase)email).Id, ((DomainBase)email).GetValorOriginal(), (TipoTela)17, (TipoAcao)2));
						commited.CredencialRepository.Delete(((DomainBase)email).Id);
						SaveLog(list, commited);
						((GenericUnitOfWork)commited).Commit();
						return true;
					}
					finally
					{
						((IDisposable)commited)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)218, tries, email);
				}
			}
			return false;
		});
	}

	internal async Task<List<ClienteEmail>> BuscarEmail(string email)
	{
		int tries = 3;
		return await Task.Run(delegate
		{
			while (tries > 0)
			{
				try
				{
					UnitOfWork read = Instancia.Read;
					try
					{
						return read.ClienteEmailRepository.FindEmailCliente(email, (Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa);
					}
					finally
					{
						((IDisposable)read)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)109, tries, email);
				}
			}
			return new List<ClienteEmail>();
		});
	}
}