summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos.Ferramentas/NotaFiscalServico.cs
blob: eede45d8e1db4d4271003bdd12b71f05ed937079 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
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.Common;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Relatorios;

namespace Gestor.Application.Servicos.Ferramentas;

internal class NotaFiscalServico : BaseServico
{
	internal async Task<List<NotaFiscal>> BuscarNotasFiscais()
	{
		int tries = 3;
		return await Task.Run(delegate
		{
			while (tries > 0)
			{
				try
				{
					UnitOfWork read = Instancia.Read;
					try
					{
						return read.NotaFiscalRepository.FindAll();
					}
					finally
					{
						((IDisposable)read)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)312, tries);
				}
			}
			return new List<NotaFiscal>();
		});
	}

	internal async Task<NotaFiscal> Save(NotaFiscal notaFiscal)
	{
		int tries = 3;
		base.Sucesso = true;
		NotaFiscal notaFiscalOriginal = notaFiscal;
		return await Task.Run((Func<NotaFiscal>)delegate
		{
			while (tries > 0)
			{
				List<RegistroLog> list = new List<RegistroLog>();
				notaFiscal = notaFiscalOriginal;
				try
				{
					UnitOfWork commited = Instancia.Commited;
					try
					{
						bool num = ((DomainBase)notaFiscal).Id != 0L;
						if (num)
						{
							list.Add(CreateLog(((DomainBase)notaFiscal).Id, notaFiscal, (TipoTela)55));
						}
						notaFiscal = ((((DomainBase)notaFiscal).Id == 0L) ? commited.NotaFiscalRepository.SaveOrUpdate(notaFiscal) : commited.NotaFiscalRepository.Merge(notaFiscal));
						if (!num)
						{
							list.Add(CreateLog(((DomainBase)notaFiscal).Id, ((DomainBase)notaFiscal).GetValorOriginal(), (TipoTela)55, (TipoAcao)0));
						}
						SaveLog(list, commited);
						((GenericUnitOfWork)commited).Commit();
						return notaFiscal;
					}
					finally
					{
						((IDisposable)commited)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)313, tries, notaFiscal);
				}
			}
			return notaFiscalOriginal;
		});
	}

	public async Task<bool> Delete(NotaFiscal notaFiscal)
	{
		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)notaFiscal).Id, ((DomainBase)notaFiscal).GetValorOriginal(), (TipoTela)55, (TipoAcao)2));
						commited.NotaFiscalRepository.Delete(((DomainBase)notaFiscal).Id);
						SaveLog(list, commited);
						((GenericUnitOfWork)commited).Commit();
						return true;
					}
					finally
					{
						((IDisposable)commited)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)314, tries, notaFiscal);
				}
			}
			return false;
		});
	}

	internal async Task<bool> Cadatrada(long idExtrato)
	{
		int tries = 3;
		return await Task.Run(delegate
		{
			while (tries > 0)
			{
				try
				{
					UnitOfWork read = Instancia.Read;
					try
					{
						return read.NotaFiscalRepository.FindByExtrato(idExtrato);
					}
					finally
					{
						((IDisposable)read)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)315, tries, idExtrato);
				}
			}
			return false;
		});
	}

	public async Task<List<NotaFiscal>> BuscarNotasFiscais(Filtros filtro)
	{
		int tries = 3;
		return await Task.Run(delegate
		{
			while (tries > 0)
			{
				try
				{
					UnitOfWork read = Instancia.Read;
					try
					{
						return read.NotaFiscalRepository.FindByDatas(filtro);
					}
					finally
					{
						((IDisposable)read)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)315, tries, filtro);
				}
			}
			return new List<NotaFiscal>();
		});
	}
}