summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos.Ferramentas/SocioServico.cs
blob: 1b3a52c8414518a99e38cc7f495bcb647c149915 (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
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.Generic;

namespace Gestor.Application.Servicos.Ferramentas;

internal class SocioServico : BaseServico
{
	public async Task<Socio> Save(Socio socio)
	{
		int tries = 3;
		base.Sucesso = true;
		Socio socioOriginal = socio;
		return await Task.Run((Func<Socio>)delegate
		{
			List<RegistroLog> list = new List<RegistroLog>();
			socio = socioOriginal;
			while (tries > 0)
			{
				socio = socioOriginal;
				try
				{
					UnitOfWork commited = Instancia.Commited;
					try
					{
						bool num = ((DomainBase)socio).Id != 0L;
						if (num)
						{
							list.Add(CreateLog(((DomainBase)socio).Id, socio, (TipoTela)19));
						}
						socio = ((((DomainBase)socio).Id == 0L) ? commited.SocioRepository.SaveOrUpdate(socio) : commited.SocioRepository.Merge(socio));
						if (!num)
						{
							list.Add(CreateLog(((DomainBase)socio).Id, ((DomainBase)socio).GetValorOriginal(), (TipoTela)19, (TipoAcao)0));
						}
						SaveLog(list, commited);
						((GenericUnitOfWork)commited).Commit();
						return socio;
					}
					finally
					{
						((IDisposable)commited)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)235, tries, socio);
				}
			}
			return socioOriginal;
		});
	}

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