summaryrefslogtreecommitdiff
path: root/Gestor.Application/Servicos/Financeiro/PlanosServico.cs
blob: b00efbec4e2c4bbc4bac5974575c5af34306eb4b (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
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.Financeiro;
using Gestor.Model.Domain.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Gestor.Application.Servicos.Financeiro
{
	internal class PlanosServico : BaseServico
	{
		public PlanosServico()
		{
		}

		internal async Task<ObservableCollection<Planos>> BuscarPlanos()
		{
			int num = 3;
			ObservableCollection<Planos> observableCollection1 = await Task.Run<ObservableCollection<Planos>>(() => {
				ObservableCollection<Planos> observableCollection;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							observableCollection = new ObservableCollection<Planos>(read.get_PlanosRepository().Find());
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 168, num, null, true);
						continue;
					}
					return observableCollection;
				}
				return new ObservableCollection<Planos>();
			});
			return observableCollection1;
		}

		public async Task<Planos> Save(Planos planos)
		{
			int num = 3;
			base.Sucesso = true;
			Planos plano1 = planos;
			Planos plano2 = await Task.Run<Planos>(() => {
				Planos plano;
				bool flag;
				while (num > 0)
				{
					List<RegistroLog> registroLogs = new List<RegistroLog>();
					planos = plano1;
					try
					{
						using (UnitOfWork commited = Instancia.Commited)
						{
							flag = (planos.get_Id() == 0 ? false : true);
							if (flag)
							{
								registroLogs.Add(base.CreateLog(planos.get_Id(), planos, 28));
							}
							planos = (planos.get_Id() == 0 ? commited.get_PlanosRepository().SaveOrUpdate(planos) : commited.get_PlanosRepository().Merge(planos));
							if (!flag)
							{
								registroLogs.Add(base.CreateLog(planos.get_Id(), planos.GetValorOriginal(), 28, 0));
							}
							base.SaveLog(registroLogs, commited);
							commited.Commit();
							plano = planos;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 251, num, planos, true);
						continue;
					}
					return plano;
				}
				return plano1;
			});
			return plano2;
		}
	}
}