summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Servicos/ServicoExtrato.cs
blob: a2742e4bf4a7e07b874281dfdf6f83f1099effbf (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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.Common;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Relatorios;
using Gestor.Model.Domain.Seguros;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

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

		internal async Task<ObservableCollection<DetalheExtrato>> BuscarDetalhes(long id)
		{
			int num = 3;
			ObservableCollection<DetalheExtrato> observableCollection1 = await Task.Run<ObservableCollection<DetalheExtrato>>(() => {
				ObservableCollection<DetalheExtrato> observableCollection;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							List<DetalheExtrato> detalheExtratos = read.get_DetalheExtratoRepository().Find(id);
							Func<DetalheExtrato, string> u003cu003e9_01 = ServicoExtrato.u003cu003ec.u003cu003e9__0_1;
							if (u003cu003e9_01 == null)
							{
								u003cu003e9_01 = (DetalheExtrato x) => x.get_Cliente();
								ServicoExtrato.u003cu003ec.u003cu003e9__0_1 = u003cu003e9_01;
							}
							IOrderedEnumerable<DetalheExtrato> detalheExtratos1 = detalheExtratos.OrderBy<DetalheExtrato, string>(u003cu003e9_01);
							Func<DetalheExtrato, string> u003cu003e9_02 = ServicoExtrato.u003cu003ec.u003cu003e9__0_2;
							if (u003cu003e9_02 == null)
							{
								u003cu003e9_02 = (DetalheExtrato x) => x.get_Apolice();
								ServicoExtrato.u003cu003ec.u003cu003e9__0_2 = u003cu003e9_02;
							}
							IOrderedEnumerable<DetalheExtrato> detalheExtratos2 = detalheExtratos1.ThenBy<DetalheExtrato, string>(u003cu003e9_02);
							Func<DetalheExtrato, string> u003cu003e9_03 = ServicoExtrato.u003cu003ec.u003cu003e9__0_3;
							if (u003cu003e9_03 == null)
							{
								u003cu003e9_03 = (DetalheExtrato x) => x.get_Endosso();
								ServicoExtrato.u003cu003ec.u003cu003e9__0_3 = u003cu003e9_03;
							}
							IOrderedEnumerable<DetalheExtrato> detalheExtratos3 = detalheExtratos2.ThenBy<DetalheExtrato, string>(u003cu003e9_03);
							Func<DetalheExtrato, string> u003cu003e9_04 = ServicoExtrato.u003cu003ec.u003cu003e9__0_4;
							if (u003cu003e9_04 == null)
							{
								u003cu003e9_04 = (DetalheExtrato x) => x.get_NumeroParcela();
								ServicoExtrato.u003cu003ec.u003cu003e9__0_4 = u003cu003e9_04;
							}
							observableCollection = new ObservableCollection<DetalheExtrato>(detalheExtratos3.ThenBy<DetalheExtrato, string>(u003cu003e9_04));
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 91, num, id, true);
						continue;
					}
					return observableCollection;
				}
				return new ObservableCollection<DetalheExtrato>();
			});
			return observableCollection1;
		}

		public async Task<List<Extrato>> BuscarExtrato(long id, long idusuario, StatusExtrato status, DateTime inicio, DateTime fim)
		{
			int num = 3;
			List<Extrato> extratos2 = await Task.Run<List<Extrato>>(() => {
				List<Extrato> list;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							List<Extrato> extratos = read.get_ExtratoRepository().FindBySeguradora(id, idusuario, Recursos.Empresa.get_Id(), inicio, fim, new StatusExtrato?(status));
							Func<Extrato, string> u003cu003e9_21 = ServicoExtrato.u003cu003ec.u003cu003e9__2_1;
							if (u003cu003e9_21 == null)
							{
								u003cu003e9_21 = (Extrato x) => x.get_Numero();
								ServicoExtrato.u003cu003ec.u003cu003e9__2_1 = u003cu003e9_21;
							}
							IOrderedEnumerable<Extrato> extratos1 = extratos.OrderBy<Extrato, string>(u003cu003e9_21);
							Func<Extrato, DateTime?> u003cu003e9_22 = ServicoExtrato.u003cu003ec.u003cu003e9__2_2;
							if (u003cu003e9_22 == null)
							{
								u003cu003e9_22 = (Extrato x) => x.get_Data();
								ServicoExtrato.u003cu003ec.u003cu003e9__2_2 = u003cu003e9_22;
							}
							list = extratos1.ThenByDescending<Extrato, DateTime?>(u003cu003e9_22).ToList<Extrato>();
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 92, num, new { id = id, status = status, inicio = inicio, fim = fim }, true);
						continue;
					}
					return list;
				}
				return new List<Extrato>();
			});
			return extratos2;
		}

		public async Task<List<Extrato>> BuscarExtratoPorData(Filtros filtros)
		{
			int num = 3;
			List<Extrato> extratos1 = await Task.Run<List<Extrato>>(() => {
				List<Extrato> list;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							List<Extrato> extratos = read.get_ExtratoRepository().FindByData(filtros);
							Func<Extrato, DateTime?> u003cu003e9_31 = ServicoExtrato.u003cu003ec.u003cu003e9__3_1;
							if (u003cu003e9_31 == null)
							{
								u003cu003e9_31 = (Extrato x) => x.get_Data();
								ServicoExtrato.u003cu003ec.u003cu003e9__3_1 = u003cu003e9_31;
							}
							list = extratos.OrderBy<Extrato, DateTime?>(u003cu003e9_31).ToList<Extrato>();
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 93, num, filtros, true);
						continue;
					}
					return list;
				}
				return new List<Extrato>();
			});
			return extratos1;
		}

		internal async Task<string> BuscarNumExtrato(long? id)
		{
			string str1;
			if (id.HasValue)
			{
				long? nullable = id;
				long num = (long)0;
				if (!(nullable.GetValueOrDefault() <= num & nullable.HasValue))
				{
					string str2 = "";
					int num1 = 3;
					str1 = await Task.Run<string>(() => {
						string str;
						while (num1 > 0)
						{
							try
							{
								using (UnitOfWork read = Instancia.Read)
								{
									DetalheExtrato detalheExtrato = read.get_DetalheExtratoRepository().FindByLongId(id).FirstOrDefault<DetalheExtrato>();
									str2 = (detalheExtrato == null || detalheExtrato.get_Id() <= (long)0 ? "" : detalheExtrato.get_Extrato().get_Numero());
									str = str2;
								}
							}
							catch (Exception exception)
							{
								num1 = base.Registrar(exception, 91, num1, id, true);
								continue;
							}
							return str;
						}
						return "";
					});
					return str1;
				}
			}
			str1 = "";
			return str1;
		}

		public async Task<bool> Delete(Extrato extrato)
		{
			int num = 3;
			bool flag1 = await Task.Run<bool>(() => {
				bool flag;
				while (num > 0)
				{
					try
					{
						List<RegistroLog> registroLogs = new List<RegistroLog>();
						using (UnitOfWork commited = Instancia.Commited)
						{
							commited.get_ExtratoRepository().Delete(extrato.get_Id());
							registroLogs.Add(base.CreateLog(extrato.get_Id(), extrato.GetValorOriginal(), 1, 2));
							base.SaveLog(registroLogs, commited);
							commited.Commit();
							flag = true;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 264, num, extrato, true);
						continue;
					}
					return flag;
				}
				return false;
			});
			return flag1;
		}

		public async Task<DetalheExtrato> FindByParcelaId(long id)
		{
			int num = 3;
			DetalheExtrato detalheExtrato1 = await Task.Run<DetalheExtrato>(() => {
				DetalheExtrato detalheExtrato;
				while (num > 0)
				{
					try
					{
						using (UnitOfWork read = Instancia.Read)
						{
							detalheExtrato = read.get_DetalheExtratoRepository().FindByParcelaId(id);
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 74, num, id, true);
						continue;
					}
					return detalheExtrato;
				}
				return new DetalheExtrato();
			});
			return detalheExtrato1;
		}

		public async Task<DetalheExtrato> Save(DetalheExtrato detalhe)
		{
			int num = 3;
			base.Sucesso = true;
			DetalheExtrato detalheExtrato1 = detalhe;
			DetalheExtrato detalheExtrato2 = await Task.Run<DetalheExtrato>(() => {
				DetalheExtrato detalheExtrato;
				while (num > 0)
				{
					detalhe = detalheExtrato1;
					try
					{
						List<RegistroLog> registroLogs = new List<RegistroLog>();
						using (UnitOfWork commited = Instancia.Commited)
						{
							TipoAcao tipoAcao = (detalhe.get_Id() == 0 ? 0 : 1);
							commited.get_DetalheExtratoRepository().Merge(detalhe);
							if (tipoAcao != 1)
							{
								registroLogs.Add(base.CreateLog(detalhe.get_Id(), detalhe.Compare(detalheExtrato1.GetValorOriginal()), 23, tipoAcao));
							}
							else
							{
								registroLogs.Add(base.CreateLog(detalhe.get_Id(), detalhe.GetValorOriginal(), 23, tipoAcao));
							}
							base.SaveLog(registroLogs, commited);
							commited.Commit();
							detalheExtrato = detalhe;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 262, num, detalhe, true);
						continue;
					}
					return detalheExtrato;
				}
				return detalheExtrato1;
			});
			return detalheExtrato2;
		}

		public async Task<Extrato> Save(Extrato extrato)
		{
			int num = 3;
			base.Sucesso = true;
			Extrato extrato1 = extrato;
			Extrato extrato2 = await Task.Run<Extrato>(() => {
				Extrato extrato3;
				while (num > 0)
				{
					extrato = extrato1;
					try
					{
						List<RegistroLog> registroLogs = new List<RegistroLog>();
						using (UnitOfWork commited = Instancia.Commited)
						{
							TipoAcao tipoAcao = (extrato.get_Id() == 0 ? 0 : 1);
							commited.get_ExtratoRepository().Merge(extrato);
							if (tipoAcao != 1)
							{
								registroLogs.Add(base.CreateLog(extrato.get_Id(), extrato.Compare(extrato1.GetValorOriginal()), 23, tipoAcao));
							}
							else
							{
								registroLogs.Add(base.CreateLog(extrato.get_Id(), extrato.GetValorOriginal(), 23, tipoAcao));
							}
							base.SaveLog(registroLogs, commited);
							commited.Commit();
						}
						extrato3 = extrato;
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 263, num, extrato, true);
						continue;
					}
					return extrato3;
				}
				return extrato1;
			});
			return extrato2;
		}
	}
}