summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos.Ferramentas/ProdutoServico.cs
blob: 4289f600bda60655b87c513854c7b26d05479593 (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
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;
using Gestor.Model.Domain.Seguros;

namespace Gestor.Application.Servicos.Ferramentas;

internal class ProdutoServico : BaseServico
{
	internal async Task<Produto> BuscarProdutoPorId(long id)
	{
		int tries = 3;
		return await Task.Run((Func<Produto>)delegate
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			while (tries > 0)
			{
				try
				{
					UnitOfWork read = Instancia.Read;
					try
					{
						return read.ProdutoRepository.FindById(id);
					}
					finally
					{
						((IDisposable)read)?.Dispose();
					}
				}
				catch (Exception e)
				{
					tries = Registrar(e, (TipoErro)116, tries, id);
				}
			}
			return new Produto();
		});
	}

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