summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Servicos/Ferramentas/EmpresaServico.cs
blob: 4d6d354b832b8dad2e873eac48b4d41199f0d76f (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
using ArquivoDigital.Infrastructure.Repository.Interface;
using ArquivoDigital.Infrastructure.UnitOfWork.Logic;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Generic;
using Gestor.Application.ViewModels;
using Gestor.Infrastructure.Repository.Interface;
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;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

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

		public async void AtualizarLogoId(long id, string idLogo)
		{
			await Task.Run(() => {
				try
				{
					using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork commited = Instancia.Commited)
					{
						Empresa empresa = commited.get_EmpresaRepository().FindById(id);
						empresa.set_LogoId(idLogo);
						commited.get_EmpresaRepository().Merge(empresa);
						commited.Commit();
					}
				}
				catch (Exception exception)
				{
				}
			});
		}

		internal async Task<Empresa> BuscarEmpresaPorId(long id)
		{
			int num = 3;
			Empresa empresa1 = await Task.Run<Empresa>(() => {
				Empresa empresa;
				while (num > 0)
				{
					try
					{
						using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork read = Instancia.Read)
						{
							empresa = read.get_EmpresaRepository().FindById(id);
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 114, num, id, true);
						continue;
					}
					return empresa;
				}
				return new Empresa();
			});
			return empresa1;
		}

		internal async Task<List<Empresa>> BuscarEmpresas()
		{
			int num = 3;
			List<Empresa> empresas1 = await Task.Run<List<Empresa>>(() => {
				List<Empresa> empresas;
				while (num > 0)
				{
					try
					{
						using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork read = Instancia.Read)
						{
							empresas = read.get_EmpresaRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa()));
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 113, num, null, true);
						continue;
					}
					return empresas;
				}
				return new List<Empresa>();
			});
			return empresas1;
		}

		public string BuscarSenhaAdm()
		{
			string str;
			int num = 3;
			while (num > 0)
			{
				try
				{
					using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork read = Instancia.Read)
					{
						str = read.get_EmpresaRepository().BuscarSenhaAdm((long)1);
					}
				}
				catch (Exception exception)
				{
					num = base.Registrar(exception, 115, num, null, true);
					continue;
				}
				return str;
			}
			return null;
		}

		public async Task<double> ConsultaEspacoBancoInGb()
		{
			double num3 = await Task.Run<double>(() => {
				double num;
				try
				{
					using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork read = Instancia.Read)
					{
						double num1 = read.get_EmpresaRepository().ConsultaEspacoBancoInGb();
						double num2 = 0;
						try
						{
							foreach (ControleArquivoDigital controleArquivoDigital in read.get_IndiceArquivoDigitalRepository().BuscarBancos())
							{
								if (controleArquivoDigital.get_Tabela().ToLower() == "arquivos")
								{
									continue;
								}
								try
								{
									Gestor.Application.Helpers.ArquivoDigital.SetConnection(controleArquivoDigital.get_Catalogo());
									using (ArquivoDigital.Infrastructure.UnitOfWork.Logic.UnitOfWork unitOfWork = Gestor.Application.Helpers.ArquivoDigital.Read)
									{
										num2 += unitOfWork.get_ArquivoDigitalRepository().ConsultaEspacoBancoInGb();
									}
								}
								catch
								{
								}
							}
						}
						catch
						{
						}
						num = num1 + num2;
					}
				}
				catch (Exception exception)
				{
					return 0;
				}
				return num;
			});
			return num3;
		}

		internal async Task<Customer> Save(Customer customer)
		{
			int num = 3;
			base.Sucesso = true;
			Customer customer1 = customer;
			Customer customer2 = await Task.Run<Customer>(() => {
				Customer customer3;
				while (num > 0)
				{
					customer = customer1;
					try
					{
						using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork commited = Instancia.Commited)
						{
							Empresa empresa = new Empresa();
							empresa.set_Nome(customer.get_Name());
							empresa.set_Documento(customer.get_Document());
							empresa.set_Bairro(customer.get_District());
							empresa.set_Cidade(customer.get_City());
							empresa.set_Complemento(customer.get_Adjunct());
							empresa.set_Numero(customer.get_Number());
							empresa.set_Cep(customer.get_PostCode());
							empresa.set_Estado(customer.get_State());
							empresa.set_Email(customer.get_Mail());
							empresa.set_PrimeiroPrefixo(customer.get_AreaCode());
							empresa.set_PrimeiroTelefone(customer.get_Phone());
							empresa.set_SegundoPrefixo(customer.get_SecondAreaCode());
							empresa.set_SegundoTelefone(customer.get_SecondPhone());
							empresa.set_Serial(ApplicationHelper.NumeroSerial);
							empresa.set_Site(customer.get_Site());
							commited.get_EmpresaRepository().SaveOrUpdate(empresa);
							commited.Commit();
							customer3 = customer;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 277, num, customer, true);
						continue;
					}
					return customer3;
				}
				return customer1;
			});
			return customer2;
		}

		public async Task<Empresa> Save(Empresa empresa)
		{
			int num = 3;
			base.Sucesso = true;
			Empresa empresa2 = empresa;
			Empresa empresa3 = await Task.Run<Empresa>(() => {
				Empresa empresa4;
				string str;
				while (num > 0)
				{
					empresa = empresa2;
					try
					{
						using (Gestor.Infrastructure.UnitOfWork.Logic.UnitOfWork commited = Instancia.Commited)
						{
							TipoAcao tipoAcao = (empresa.get_Id() == 0 ? 0 : 1);
							empresa = (empresa.get_Id() == 0 ? commited.get_EmpresaRepository().SaveOrUpdate(empresa) : commited.get_EmpresaRepository().Merge(empresa));
							IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
							if (Recursos.Usuario.get_Id() != 0)
							{
								RegistroLog registroLog = new RegistroLog();
								registroLog.set_Acao(tipoAcao);
								registroLog.set_Usuario(Recursos.Usuario);
								registroLog.set_DataHora(Funcoes.GetNetworkTime());
								Empresa empresa1 = empresa;
								JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings();
								jsonSerializerSetting.set_ReferenceLoopHandling(1);
								registroLog.set_Descricao(JsonConvert.SerializeObject(empresa1, jsonSerializerSetting));
								registroLog.set_EntidadeId(empresa.get_Id());
								registroLog.set_Tela(18);
								registroLog.set_Versao(LoginViewModel.VersaoAtual);
								registroLog.set_NomeMaquina(Environment.MachineName);
								registroLog.set_UsuarioMaquina(Environment.UserName);
								IPAddress[] addressList = hostEntry.AddressList;
								Func<IPAddress, bool> u003cu003e9_31 = EmpresaServico.u003cu003ec.u003cu003e9__3_1;
								if (u003cu003e9_31 == null)
								{
									u003cu003e9_31 = (IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork;
									EmpresaServico.u003cu003ec.u003cu003e9__3_1 = u003cu003e9_31;
								}
								IPAddress pAddress = ((IEnumerable<IPAddress>)addressList).FirstOrDefault<IPAddress>(u003cu003e9_31);
								if (pAddress != null)
								{
									str = pAddress.ToString();
								}
								else
								{
									str = null;
								}
								registroLog.set_Ip(str);
								base.SaveLog(registroLog, commited);
							}
							commited.Commit();
							empresa4 = empresa;
						}
					}
					catch (Exception exception)
					{
						num = base.Registrar(exception, 277, num, empresa, true);
						continue;
					}
					return empresa4;
				}
				return empresa2;
			});
			return empresa3;
		}
	}
}