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
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Ferramentas;
using Gestor.Application.Servicos.Generic;
using Gestor.Application.ViewModels.Generic;
using Gestor.Common.Validation;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
namespace Gestor.Application.ViewModels.Ferramentas;
public class EstipulanteViewModel : BaseSegurosViewModel
{
private readonly EstipulanteServico _servico;
public Estipulante CancelEstipulante;
private Estipulante _selectedEstipulante = new Estipulante();
private ObservableCollection<Estipulante> _estipulantesFiltrados = new ObservableCollection<Estipulante>();
private bool _isExpanded;
public List<Estipulante> Estipulantes { get; set; }
public Estipulante SelectedEstipulante
{
get
{
return _selectedEstipulante;
}
set
{
_selectedEstipulante = value;
WorkOnSelectedEstipulante(value);
VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null);
OnPropertyChanged("SelectedEstipulante");
if (value != null)
{
((DomainBase)SelectedEstipulante).Initialize();
}
}
}
public ObservableCollection<Estipulante> EstipulantesFiltrados
{
get
{
return _estipulantesFiltrados;
}
set
{
_estipulantesFiltrados = value;
IsExpanded = value != null && value.Count > 0;
OnPropertyChanged("EstipulantesFiltrados");
}
}
public bool IsExpanded
{
get
{
return _isExpanded;
}
set
{
_isExpanded = value;
OnPropertyChanged("IsExpanded");
}
}
public EstipulanteViewModel()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
_servico = new EstipulanteServico();
base.EnableMenu = true;
Seleciona();
}
private async void Seleciona()
{
Loading(isLoading: true);
await PermissaoTela((TipoTela)9);
await SelecionaEstipulantes();
Loading(isLoading: false);
}
private async Task SelecionaEstipulantes()
{
Loading(isLoading: true);
List<Estipulante> list = await new BaseServico().BuscarEstipulantesAsync();
Estipulantes = (from x in list
where Recursos.Usuario.IdEmpresa == 1 || Recursos.Usuario.IdEmpresa == x.IdEmpresa
orderby x.Ativo descending, x.Nome
select x).ToList();
EstipulantesFiltrados = new ObservableCollection<Estipulante>(Estipulantes);
if (EstipulantesFiltrados.Count > 0)
{
SelecionaEstipulante(EstipulantesFiltrados.First());
}
else
{
SelectedEstipulante = new Estipulante();
Alterar(alterar: false);
base.EnableMenu = false;
}
Recursos.Estipulantes = list;
Loading(isLoading: false);
}
public async Task<List<KeyValuePair<string, string>>> Validate()
{
List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();
bool valida = !string.IsNullOrEmpty(SelectedEstipulante.Nome);
List<Estipulante> list = ((!ValidationHelper.ValidateDocument(SelectedEstipulante.Documento)) ? new List<Estipulante>() : (await new BaseServico().BuscarEstipulante(SelectedEstipulante.Documento)));
List<Estipulante> list2 = list;
string nome = "";
if (list2.Count > 0)
{
list2.ForEach(delegate(Estipulante x)
{
if (((DomainBase)x).Id != ((DomainBase)SelectedEstipulante).Id && !string.IsNullOrEmpty(SelectedEstipulante.Documento) && x.Documento == SelectedEstipulante.Documento)
{
valida = false;
nome = x.Nome;
}
});
}
if (!valida)
{
errors.Add(new KeyValuePair<string, string>("Documento", "O DOCUMENTO ESTÁ CADASTRADO PARA O ESTIPULANTE " + nome + "."));
}
return errors;
}
public void Incluir()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
SelectedEstipulante = new Estipulante
{
IdEmpresa = Recursos.Usuario.IdEmpresa,
Ativo = true
};
Alterar(alterar: true);
}
public async Task<List<KeyValuePair<string, string>>> Salvar()
{
List<KeyValuePair<string, string>> errorMessages = SelectedEstipulante.Validate();
List<KeyValuePair<string, string>> list = errorMessages;
list.AddRange(await Validate());
if (errorMessages.Count > 0)
{
return errorMessages;
}
string acao = ((((DomainBase)SelectedEstipulante).Id == 0L) ? "INCLUIU" : "ALTEROU");
Estipulante value = await _servico.Save(SelectedEstipulante);
if (!_servico.Sucesso)
{
return null;
}
RegistrarAcao(acao + " ESTIPULANTE \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)9, $"ESTIPULANTE \"{value.Nome}\", ID: {((DomainBase)value).Id}");
if (Estipulantes.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id))
{
DomainBase.Copy<Estipulante, Estipulante>(Estipulantes.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value);
}
else
{
Estipulantes.Add(value);
}
if (EstipulantesFiltrados.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id))
{
DomainBase.Copy<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value);
}
else
{
EstipulantesFiltrados.Add(value);
}
EstipulantesFiltrados = new ObservableCollection<Estipulante>(EstipulantesFiltrados);
Recursos.Estipulantes = Estipulantes;
WorkOnSelectedEstipulante(value, registrar: false);
Alterar(alterar: false);
((DomainBase)SelectedEstipulante).Initialize();
ToggleSnackBar("ESTIPULANTE SALVO COM SUCESSO");
return null;
}
private void WorkOnSelectedEstipulante(Estipulante value, bool registrar = true)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Invalid comparison between Unknown and I4
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
CancelEstipulante = (Estipulante)((value == null || ((DomainBase)value).Id == 0L) ? ((object)CancelEstipulante) : ((object)(Estipulante)((DomainBase)value).Clone()));
if (value == null || ((DomainBase)value).Id == 0L || (LastAccessId == ((DomainBase)value).Id && (int)LastAccessTela == 9))
{
return;
}
if (registrar)
{
RegistrarAcao("ACESSOU ESTIPULANTE \"" + value.Nome + "\"", ((DomainBase)value).Id, (TipoTela)9, $"ID ESTIPULANTE: {((DomainBase)value).Id}");
}
LastAccessId = ((DomainBase)value).Id;
LastAccessTela = (TipoTela)9;
Estipulante selectedEstipulante = SelectedEstipulante;
if (((selectedEstipulante != null) ? new long?(((DomainBase)selectedEstipulante).Id) : null) != ((DomainBase)value).Id)
{
SelectedEstipulante = ((IEnumerable<Estipulante>)EstipulantesFiltrados).FirstOrDefault((Func<Estipulante, bool>)((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)value).Id));
}
}
public void CancelarAlteracao()
{
if (CancelEstipulante != null && Estipulantes.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id))
{
DomainBase.Copy<Estipulante, Estipulante>(Estipulantes.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id), CancelEstipulante);
if (EstipulantesFiltrados.Count > 0 && EstipulantesFiltrados.Any((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id))
{
DomainBase.Copy<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id), CancelEstipulante);
}
else
{
EstipulantesFiltrados.Add(CancelEstipulante);
}
EstipulantesFiltrados = new ObservableCollection<Estipulante>(EstipulantesFiltrados);
SelectedEstipulante = EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)CancelEstipulante).Id);
}
else
{
Incluir();
}
Alterar(alterar: false);
}
public async void Excluir()
{
if (SelectedEstipulante == null || ((DomainBase)SelectedEstipulante).Id == 0L)
{
return;
}
Loading(isLoading: true);
List<Documento> list = await new BaseServico().BuscarDocumentosPorEstipulante(((DomainBase)SelectedEstipulante).Id);
Loading(isLoading: false);
if (list.Count > 0)
{
string text = "ESTIPULANTE NÃO PODE SER EXCLUÍDO POIS ESTÁ VINCULADO AOS SEGUINTES DOCUMENTOS:";
foreach (Documento item in list)
{
text = ((!string.IsNullOrWhiteSpace(item.Apolice)) ? (text + $"{Environment.NewLine}DOCUMENTO {list.IndexOf(item) + 1} (NÚMERO DA PROPOSTA: {item.Proposta}, NÚMERO DA APÓLICE: {item.Apolice})") : (text + $"{Environment.NewLine}DOCUMENTO {list.IndexOf(item) + 1} (NÚMERO DA PROPOSTA: {item.Proposta})"));
}
await ShowMessage(text);
}
else
{
if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO")))
{
return;
}
Loading(isLoading: true);
if (!(await _servico.Delete(SelectedEstipulante)))
{
Loading(isLoading: false);
return;
}
RegistrarAcao("EXCLUIU ESTIPULANTE \"" + SelectedEstipulante.Nome + "\"", ((DomainBase)SelectedEstipulante).Id, (TipoTela)9, $"ESTIPULANTE \"{SelectedEstipulante.Nome}\", ID: {((DomainBase)SelectedEstipulante).Id}");
int num = EstipulantesFiltrados.IndexOf(SelectedEstipulante);
Estipulantes.Remove(SelectedEstipulante);
EstipulantesFiltrados.Remove(SelectedEstipulante);
EstipulantesFiltrados = new ObservableCollection<Estipulante>(EstipulantesFiltrados);
if (EstipulantesFiltrados.Count > 0)
{
SelectedEstipulante = ((num < EstipulantesFiltrados.Count) ? EstipulantesFiltrados.ElementAt(num) : EstipulantesFiltrados.Last());
}
else
{
SelectedEstipulante = new Estipulante();
Alterar(alterar: false);
base.EnableMenu = false;
}
Recursos.Estipulantes = await new BaseServico().BuscarEstipulantesAsync();
Loading(isLoading: false);
ToggleSnackBar("ESTIPULANTE EXCLUÍDO COM SUCESSO");
}
}
internal async Task<List<Estipulante>> Filtrar(string value)
{
return await Task.Run(() => FiltrarEstipulante(value));
}
public List<Estipulante> FiltrarEstipulante(string filter)
{
EstipulantesFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Estipulante>(Estipulantes) : new ObservableCollection<Estipulante>(from x in Estipulantes
where ValidationHelper.RemoveDiacritics(x.Nome.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
orderby x.Ativo descending, x.Nome
select x));
SelectedEstipulante = EstipulantesFiltrados.FirstOrDefault();
return EstipulantesFiltrados.ToList();
}
public async void SelecionaEstipulante(Estipulante estipulante)
{
Estipulante val = await _servico.BuscarEstipulantePorId(((DomainBase)estipulante).Id);
DomainBase.Copy<Estipulante, Estipulante>(EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id), val);
SelectedEstipulante = EstipulantesFiltrados.First((Estipulante x) => ((DomainBase)x).Id == ((DomainBase)estipulante).Id);
}
}
|