blob: ed83d061b4de57fc0d3b118cf145dfb684d1bcf7 (
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
|
using System;
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.Common;
using Gestor.Model.Domain.Generic;
namespace Gestor.Application.Servicos.Seguros;
internal class ProfissaoServico : BaseServico
{
public async Task<Profissao> Save(Profissao profissao)
{
int tries = 3;
base.Sucesso = true;
Profissao profissaoOriginal = profissao;
return await Task.Run((Func<Profissao>)delegate
{
while (tries > 0)
{
profissao = profissaoOriginal;
try
{
UnitOfWork commited = Instancia.Commited;
try
{
bool flag = ((DomainBase)profissao).Id == 0;
profissao = (flag ? commited.ProfissaoRepository.SaveOrUpdate(profissao) : commited.ProfissaoRepository.Merge(profissao));
((GenericUnitOfWork)commited).Commit();
return profissao;
}
finally
{
((IDisposable)commited)?.Dispose();
}
}
catch (Exception e)
{
tries = Registrar(e, (TipoErro)214, tries, profissao);
}
}
return profissaoOriginal;
});
}
public async Task<long> FindLastId()
{
int tries = 3;
return await Task.Run(delegate
{
while (tries > 0)
{
try
{
UnitOfWork read = Instancia.Read;
try
{
return read.ProfissaoRepository.FindLastId();
}
finally
{
((IDisposable)read)?.Dispose();
}
}
catch (Exception e)
{
tries = Registrar(e, (TipoErro)17, tries);
}
}
return 0L;
});
}
}
|