summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Drawer.Ajuda/AtendimentosViewModel.cs
blob: 05ffe121ca61dda8f83f0d542b1eaff86cf37d4f (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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Gestor.Application.Helpers;
using Gestor.Application.Model.Ajuda;
using Gestor.Application.Servicos.Ajuda;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.API;
using Gestor.Model.Domain.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Newtonsoft.Json;

namespace Gestor.Application.ViewModels.Drawer.Ajuda;

public class AtendimentosViewModel : BaseViewModel
{
	private readonly AjudaServico _ajudaServico;

	private List<string> _status;

	private string _webbody;

	private Visibility _envioEmailVisibility = (Visibility)2;

	private Visibility _atendimentoVisibility;

	private ObservableCollection<Atendimento> _atendimentos;

	private Atendimento _selectedAtendimento;

	private string _nome;

	private string _ddd;

	private string _telefone;

	private string _email;

	private string _assunto;

	private string _idacesso;

	private string _corpo;

	private string _senhaacesso;

	private ObservableCollection<ArquivoDigital> _arquivosAnexados = new ObservableCollection<ArquivoDigital>();

	private ArquivoDigital _selectedAnexado = new ArquivoDigital();

	private string _head;

	public HorarioAtendimento HorarioAtendimento { get; set; }

	public List<string> Status
	{
		get
		{
			return _status;
		}
		set
		{
			_status = value;
			OnPropertyChanged("Status");
		}
	}

	public string WebBody
	{
		get
		{
			return _webbody?.ToUpper().Trim();
		}
		set
		{
			_webbody = value;
			OnPropertyChanged("WebBody");
		}
	}

	public Visibility EnvioEmailVisibility
	{
		get
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return _envioEmailVisibility;
		}
		set
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			_envioEmailVisibility = value;
			OnPropertyChanged("EnvioEmailVisibility");
		}
	}

	public Visibility AtendimentoVisibility
	{
		get
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return _atendimentoVisibility;
		}
		set
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			_atendimentoVisibility = value;
			OnPropertyChanged("AtendimentoVisibility");
		}
	}

	public ObservableCollection<Atendimento> Atendimentos
	{
		get
		{
			return _atendimentos;
		}
		set
		{
			_atendimentos = value;
			OnPropertyChanged("Atendimentos");
		}
	}

	public Atendimento SelectedAtendimento
	{
		get
		{
			return _selectedAtendimento;
		}
		set
		{
			_selectedAtendimento = value;
			WorkOnSelectedAtendimento(value);
			OnPropertyChanged("SelectedAtendimento");
		}
	}

	public string Nome
	{
		get
		{
			return _nome;
		}
		set
		{
			_nome = value;
			OnPropertyChanged("Nome");
		}
	}

	public string Ddd
	{
		get
		{
			return _ddd;
		}
		set
		{
			_ddd = value;
			OnPropertyChanged("Ddd");
		}
	}

	public string Telefone
	{
		get
		{
			return _telefone;
		}
		set
		{
			_telefone = value;
			OnPropertyChanged("Telefone");
		}
	}

	public string Email
	{
		get
		{
			return _email;
		}
		set
		{
			_email = value;
			OnPropertyChanged("Email");
		}
	}

	public string Assunto
	{
		get
		{
			return _assunto;
		}
		set
		{
			_assunto = value;
			OnPropertyChanged("Assunto");
		}
	}

	public string IdAcesso
	{
		get
		{
			return _idacesso;
		}
		set
		{
			_idacesso = value;
			OnPropertyChanged("IdAcesso");
		}
	}

	public string Corpo
	{
		get
		{
			return _corpo;
		}
		set
		{
			_corpo = value;
			OnPropertyChanged("Corpo");
		}
	}

	public string SenhaAcesso
	{
		get
		{
			return _senhaacesso;
		}
		set
		{
			_senhaacesso = value;
			OnPropertyChanged("SenhaAcesso");
		}
	}

	public ObservableCollection<ArquivoDigital> ArquivosAnexados
	{
		get
		{
			return _arquivosAnexados;
		}
		set
		{
			_arquivosAnexados = value;
			OnPropertyChanged("ArquivosAnexados");
		}
	}

	public ArquivoDigital SelectedAnexado
	{
		get
		{
			return _selectedAnexado;
		}
		set
		{
			_selectedAnexado = value;
			OnPropertyChanged("SelectedAnexado");
		}
	}

	public string Head
	{
		get
		{
			return _head;
		}
		set
		{
			_head = value;
			OnPropertyChanged("Head");
		}
	}

	private async void HabilitarAtendimento(HorarioAtendimento horario)
	{
		if (horario == null || horario.Autorizado)
		{
			AtendimentosViewModel atendimentosViewModel = this;
			Usuario usuario = Recursos.Usuario;
			atendimentosViewModel.EnableButtons = usuario != null && ((DomainBase)usuario).Id > 0;
			return;
		}
		base.EnableButtons = false;
		string text = (horario.InicioDia.HasValue ? (" de " + horario.InicioDia.DiaDaSemana() + " à " + horario.FimDia.DiaDaSemana() + ", das " + horario.InicioHora + "hs às " + horario.FimHora + "hs") : (" das " + horario.InicioHora + "hs às " + horario.FimHora + "hs"));
		await ShowMessage("Prezado Cliente," + Environment.NewLine + Environment.NewLine + "Informamos Nosso horário de atendimento e recepção dos mesmos é " + text + "." + Environment.NewLine + "Infelizmente não realizamos agendamento de data/hora de atendimento, por gentileza realize a solicitação dentro do horário comercial que retornaremos a você.");
	}

	public AtendimentosViewModel()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		base.EnableButtons = true;
		_ajudaServico = new AjudaServico();
		LoadCombo();
		InitialLoad();
	}

	private async void InitialLoad()
	{
		base.IsEnabled = false;
		HorarioAtendimento = await Connection.Get<HorarioAtendimento>("Attendance");
		HabilitarAtendimento(HorarioAtendimento);
		base.IsEnabled = true;
	}

	private void LoadCombo()
	{
		Status = new List<string> { "PENDENTES", "FINALIZADOS" };
	}

	public async void WorkOnSelectedStatus(string value)
	{
		Atendimentos = await _ajudaServico.BuscarAtendimentos(value);
		SelecionaAtendimento();
	}

	public void SelecionaAtendimento()
	{
		if (Atendimentos != null && Atendimentos.Count > 0)
		{
			SelectedAtendimento = Atendimentos[0];
		}
		AtendimentoVisibility = (Visibility)0;
		EnvioEmailVisibility = (Visibility)2;
	}

	private async void WorkOnSelectedAtendimento(Atendimento value)
	{
		if (value != null)
		{
			WebBody = await _ajudaServico.BuscarCorpoAtendimentos(value.IdAtendimento);
		}
	}

	public async void Anexar()
	{
		List<ArquivoDigital> list = await AddAttachments(new List<ArquivoDigital>(), new List<ArquivoDigital>());
		if (list != null)
		{
			list.AddRange(ArquivosAnexados);
			ArquivosAnexados = new ObservableCollection<ArquivoDigital>(list);
		}
	}

	public async Task<List<KeyValuePair<string, string>>> Enviar()
	{
		try
		{
			List<KeyValuePair<string, string>> list = Validate();
			if (list.Count > 0)
			{
				return list;
			}
			CustomerData val = new CustomerData
			{
				Corretora = Recursos.Empresa.Nome,
				Name = Nome,
				AreaCode = Ddd,
				Number = Telefone,
				Email = Email
			};
			string body = $"{Corpo}<hr><p><b>ID Acesso:</b> {IdAcesso}<br><b>Senha Acesso:</b> {SenhaAcesso}</p><p>VERSÃO DO SISTEMA: {ApplicationHelper.Versao}<br />USUÁRIO SISTEMA:{((DomainBase)Recursos.Usuario).Id} {Recursos.Usuario.Login}</p><p>{JsonConvert.SerializeObject((object)val)}</p>";
			CustomerAttendance keyValues = new CustomerAttendance
			{
				CustomerData = val,
				Subject = Assunto,
				Body = body,
				Attachments = ((IEnumerable<ArquivoDigital>)ArquivosAnexados).Select((Func<ArquivoDigital, Attachment>)((ArquivoDigital x) => new Attachment
				{
					Description = x.Descricao,
					Extension = x.Extensao,
					File = x.Arquivo
				})).ToList()
			};
			bool num = await Connection.Post<CustomerAttendance>("Attendance/Send", keyValues) == null;
			LimparComponentes();
			SelecionaAtendimento();
			return num ? null : new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("fail", "")
			};
		}
		catch (Exception)
		{
			return new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("fail", "")
			};
		}
	}

	public void LimparComponentes()
	{
		Nome = Recursos.Usuario.Nome;
		Ddd = Recursos.Usuario.Prefixo;
		Telefone = Recursos.Usuario.Telefone;
		Email = Recursos.Usuario.Email;
		Assunto = null;
		IdAcesso = null;
		SenhaAcesso = null;
		Corpo = string.Empty;
		ArquivosAnexados = new ObservableCollection<ArquivoDigital>();
	}

	public List<KeyValuePair<string, string>> Validate()
	{
		List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
		if (string.IsNullOrWhiteSpace(Nome))
		{
			ValidationHelper.AddValue<string, string>(list, "Nome", Messages.Obrigatorio, true);
		}
		if (string.IsNullOrWhiteSpace(Ddd))
		{
			ValidationHelper.AddValue<string, string>(list, "Ddd", Messages.Obrigatorio, true);
		}
		else if (!ValidationHelper.ValidacaoPrefixo(Ddd))
		{
			ValidationHelper.AddValue<string, string>(list, "Ddd", Messages.Invalido, true);
		}
		if (string.IsNullOrWhiteSpace(Telefone))
		{
			ValidationHelper.AddValue<string, string>(list, "Telefone", Messages.Obrigatorio, true);
		}
		else if (!ValidationHelper.ValidacaoTelefone(Telefone))
		{
			ValidationHelper.AddValue<string, string>(list, "Telefone", Messages.Invalido, true);
		}
		if (string.IsNullOrWhiteSpace(Email))
		{
			ValidationHelper.AddValue<string, string>(list, "Email", Messages.Obrigatorio, true);
		}
		else if (!ValidationHelper.ValidacaoEmail(Email))
		{
			ValidationHelper.AddValue<string, string>(list, "Email", Messages.Invalido, true);
		}
		if (string.IsNullOrWhiteSpace(Corpo))
		{
			ValidationHelper.AddValue<string, string>(list, "Corpo", Messages.Obrigatorio, true);
		}
		if (string.IsNullOrWhiteSpace(Assunto))
		{
			ValidationHelper.AddValue<string, string>(list, "Assunto", Messages.Obrigatorio, true);
		}
		return list;
	}

	public void Delete(ArquivoDigital arquivo)
	{
		if (SelectedAnexado != null)
		{
			ArquivoDigital item = ArquivosAnexados.First((ArquivoDigital x) => x.Descricao == arquivo.Descricao);
			ArquivosAnexados.Remove(item);
			ArquivosAnexados = new ObservableCollection<ArquivoDigital>(ArquivosAnexados);
		}
	}
}