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
|
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;
namespace Gestor.Application.Servicos.Ferramentas;
internal class ReciboServico : BaseServico
{
internal async Task<List<Recibo>> BuscarRecibos()
{
int tries = 3;
return await Task.Run(delegate
{
while (tries > 0)
{
try
{
UnitOfWork read = Instancia.Read;
try
{
return read.ReciboRepository.BuscarRecibos();
}
finally
{
((IDisposable)read)?.Dispose();
}
}
catch (Exception e)
{
tries = Registrar(e, (TipoErro)123, tries);
}
}
return new List<Recibo>();
});
}
public async Task<Recibo> Save(Recibo recibo)
{
int tries = 3;
base.Sucesso = true;
Recibo reciboOriginal = recibo;
return await Task.Run((Func<Recibo>)delegate
{
while (tries > 0)
{
List<RegistroLog> list = new List<RegistroLog>();
recibo = reciboOriginal;
try
{
UnitOfWork commited = Instancia.Commited;
try
{
bool num = ((DomainBase)recibo).Id != 0L;
if (num)
{
list.Add(CreateLog(((DomainBase)recibo).Id, recibo, (TipoTela)42));
}
recibo = ((((DomainBase)recibo).Id == 0L) ? commited.ReciboRepository.SaveOrUpdate(recibo) : commited.ReciboRepository.Merge(recibo));
if (!num)
{
list.Add(CreateLog(((DomainBase)recibo).Id, ((DomainBase)recibo).GetValorOriginal(), (TipoTela)42, (TipoAcao)0));
}
SaveLog(list, commited);
((GenericUnitOfWork)commited).Commit();
return recibo;
}
finally
{
((IDisposable)commited)?.Dispose();
}
}
catch (Exception e)
{
tries = Registrar(e, (TipoErro)231, tries, recibo);
}
}
return reciboOriginal;
});
}
public async Task<bool> Delete(Recibo recibo)
{
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)recibo).Id, ((DomainBase)recibo).GetValorOriginal(), (TipoTela)42, (TipoAcao)2));
commited.ReciboRepository.Delete(((DomainBase)recibo).Id);
SaveLog(list, commited);
((GenericUnitOfWork)commited).Commit();
return true;
}
finally
{
((IDisposable)commited)?.Dispose();
}
}
catch (Exception e)
{
tries = Registrar(e, (TipoErro)232, tries, recibo);
}
}
return false;
});
}
}
|