summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Servicos/Ferramentas/ProdutoServico.cs
blob: 76fd16df48789a877e7c1a49f785423597dcc4ec (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
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Generic;
using Gestor.Infrastructure.Repository.Interface;
using Gestor.Infrastructure.UnitOfWork.Generic;
using Gestor.Infrastructure.UnitOfWork.Logic;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Gestor.Application.Servicos.Ferramentas
{
	internal class ProdutoServico : BaseServico
	{
		public ProdutoServico()
		{
		}

		internal async Task<Produto> BuscarProdutoPorId(long id)
		{
			int num = 3;
			Produto produto1 = await Task.Run<Produto>(() => {
				Produto produto;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							produto = read.get_ProdutoRepository().FindById(id);
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 116, num, id, true);
						continue;
					}
					return produto;
				}
				return new Produto();
			});
			return produto1;
		}

		public async Task<Produto> Save(Produto produto)
		{
			int num = 3;
			base.Sucesso = true;
			Produto produto1 = produto;
			Produto produto2 = await Task.Run<Produto>(() => {
				Produto produto3;
				bool flag;
				while (num > 0)
				{
					List<RegistroLog> registroLogs = new List<RegistroLog>();
					produto = produto1;
					try
					{
						using (UnitOfWork commited = Instancia.Commited)
						{
							flag = (produto.get_Id() == 0 ? false : true);
							if (flag)
							{
								registroLogs.Add(base.CreateLog(produto.get_Id(), produto, 10));
							}
							produto = (produto.get_Id() == 0 ? commited.get_ProdutoRepository().SaveOrUpdate(produto) : commited.get_ProdutoRepository().Merge(produto));
							if (!flag)
							{
								registroLogs.Add(base.CreateLog(produto.get_Id(), produto.GetValorOriginal(), 10, 0));
							}
							base.SaveLog(registroLogs, commited);
							commited.Commit();
							produto3 = produto;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 226, num, produto, true);
						continue;
					}
					return produto3;
				}
				return produto1;
			});
			return produto2;
		}
	}
}