summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Seguros/PerfilEmpresaViewModel.cs
blob: a119dd32781b3601b5617e609cb9cca0dcd4243b (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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Seguros;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;

namespace Gestor.Application.ViewModels.Seguros;

public class PerfilEmpresaViewModel : BaseViewModel
{
	private readonly PerfilEmpresaServico _servico;

	private readonly Controle _controle;

	private Visibility _ativaCampos = (Visibility)2;

	private string _equipamentoSeguranca = "";

	private string _equipamentoIncendio = "";

	private bool _enableIncluirPerfil;

	private string _dataConstrucao;

	public long CancelPerfil;

	private PerfilEmpresa _selectedPerfilEmpresa = new PerfilEmpresa();

	public Visibility AtivaCampos
	{
		get
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return _ativaCampos;
		}
		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)
			_ativaCampos = value;
			OnPropertyChanged("AtivaCampos");
		}
	}

	public string EquipamentoSeguranca
	{
		get
		{
			return _equipamentoSeguranca;
		}
		set
		{
			_equipamentoSeguranca = value;
			OnPropertyChanged("EquipamentoSeguranca");
		}
	}

	public string EquipamentoIncendio
	{
		get
		{
			return _equipamentoIncendio;
		}
		set
		{
			_equipamentoIncendio = value;
			OnPropertyChanged("EquipamentoIncendio");
		}
	}

	public bool EnableIncluirPerfil
	{
		get
		{
			return _enableIncluirPerfil;
		}
		set
		{
			_enableIncluirPerfil = value;
			OnPropertyChanged("EnableIncluirPerfil");
		}
	}

	public string DataConstrucao
	{
		get
		{
			return _dataConstrucao;
		}
		set
		{
			_dataConstrucao = value?.Replace(" ", "");
			OnPropertyChanged("DataConstrucao");
		}
	}

	public PerfilEmpresa SelectedPerfilEmpresa
	{
		get
		{
			return _selectedPerfilEmpresa;
		}
		set
		{
			_selectedPerfilEmpresa = value;
			if (value != null && ((DomainBase)value).Id > 0)
			{
				CancelPerfil = ((DomainBase)value).Id;
			}
			VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null);
			OnPropertyChanged("SelectedPerfilEmpresa");
		}
	}

	public PerfilEmpresaViewModel(Controle controle)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		_servico = new PerfilEmpresaServico();
		_controle = controle;
		Seleciona(((DomainBase)controle).Id);
	}

	private async void Seleciona(long id)
	{
		Loading(isLoading: true);
		await PermissaoTela((TipoTela)32);
		await SelecionaPerfil(id);
		Loading(isLoading: false);
	}

	private async Task SelecionaPerfil(long id)
	{
		Loading(isLoading: true);
		SelectedPerfilEmpresa = await _servico.BuscarPerfis(id);
		if (SelectedPerfilEmpresa != null)
		{
			EquipamentoSeguranca = BindingEnumHelper.ConcatenarDescricoesEnum<EquipamentoSeguranca>(SelectedPerfilEmpresa.EquipamentoSeguranca);
			EquipamentoIncendio = BindingEnumHelper.ConcatenarDescricoesEnum<EquipamentoIncendio>(SelectedPerfilEmpresa.EquipamentoIncendio);
			if (SelectedPerfilEmpresa.AnoConstrucao.HasValue)
			{
				DataConstrucao = SelectedPerfilEmpresa.AnoConstrucao.Value.Year.ToString();
			}
		}
		else
		{
			EnableIncluirPerfil = true;
			EquipamentoSeguranca = "";
			EquipamentoIncendio = "";
		}
		Loading(isLoading: false);
	}

	public void Incluir()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		PerfilEmpresa selectedPerfilEmpresa = new PerfilEmpresa
		{
			Controle = _controle,
			Cliente = _controle.Cliente,
			ExclusivoDeposito = false,
			DivisaTerrenoBaldio = false,
			PatrimonioHistorio = false,
			PossuiTelhado = false,
			CaixasEletronicos = false,
			Isopainel = false,
			ConstrucaoReforma = false
		};
		SelectedPerfilEmpresa = selectedPerfilEmpresa;
		Alterar(alterar: true);
	}

	public async Task<List<KeyValuePair<string, string>>> Salvar()
	{
		List<KeyValuePair<string, string>> errorMessages = SelectedPerfilEmpresa.Validate();
		errorMessages = ValidateCampos(errorMessages);
		if (errorMessages.Count > 0)
		{
			return errorMessages;
		}
		if (DataConstrucao != null && DataConstrucao != "")
		{
			SelectedPerfilEmpresa.AnoConstrucao = DateTime.Parse("01/01/" + DataConstrucao);
		}
		SelectedPerfilEmpresa = await _servico.Save(SelectedPerfilEmpresa);
		if (!_servico.Sucesso)
		{
			return null;
		}
		await SelecionaPerfil(((DomainBase)_controle).Id);
		ToggleSnackBar("PERFIL SALVO COM SUCESSO");
		Alterar(alterar: false);
		return null;
	}

	private List<KeyValuePair<string, string>> ValidateCampos(List<KeyValuePair<string, string>> errorMessages)
	{
		if (DataConstrucao == null)
		{
			ValidationHelper.AddValue<string, string>(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true);
		}
		if (!int.TryParse(DataConstrucao, out var _))
		{
			ValidationHelper.AddValue<string, string>(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true);
		}
		if (DataConstrucao != null && int.TryParse(DataConstrucao, out var _) && (int.Parse(DataConstrucao) <= 1755 || int.Parse(DataConstrucao) >= 9999))
		{
			ValidationHelper.AddValue<string, string>(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true);
		}
		return errorMessages;
	}

	public void CancelarAlteracao()
	{
		Loading(isLoading: true);
		Alterar(alterar: false);
		Loading(isLoading: false);
	}

	public async Task Excluir()
	{
		if (SelectedPerfilEmpresa != null && ((DomainBase)SelectedPerfilEmpresa).Id != 0L && await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO"))
		{
			Loading(isLoading: true);
			if (!(await _servico.Delete(SelectedPerfilEmpresa)))
			{
				Loading(isLoading: false);
				return;
			}
			await SelecionaPerfil(((DomainBase)_controle).Id);
			Loading(isLoading: false);
			EnableIncluirPerfil = true;
			AtivaCampos = (Visibility)2;
			DataConstrucao = null;
			ToggleSnackBar("PERFIL EXCLUÍDO COM SUCESSO");
		}
	}
}