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
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Assinador.Infrastructure.Helpers;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos.Ferramentas;
using Gestor.Application.Servicos.Generic;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
namespace Gestor.Application.ViewModels.Drawer;
public class MetaSeguradoraViewModel : BaseSegurosViewModel
{
private readonly MetaSeguradoraServico _servico;
private readonly Seguradora _selectedSeguradora;
private MetaSeguradora _selectedMetaSeguradora = new MetaSeguradora();
private ObservableCollection<MetaSeguradora> _metasSeguradora = new ObservableCollection<MetaSeguradora>();
private bool _carregando;
public MetaSeguradora CancelMetaSeguradora;
public MetaSeguradora SelectedMetaSeguradora
{
get
{
return _selectedMetaSeguradora;
}
set
{
_selectedMetaSeguradora = value;
CancelMetaSeguradora = ((value != null && ((DomainBase)value).Id > 0) ? value : CancelMetaSeguradora);
VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null);
OnPropertyChanged("SelectedMetaSeguradora");
}
}
public ObservableCollection<MetaSeguradora> MetasSeguradora
{
get
{
return _metasSeguradora;
}
set
{
_metasSeguradora = value;
OnPropertyChanged("MetasSeguradora");
}
}
public bool Carregando
{
get
{
return _carregando;
}
set
{
_carregando = value;
base.IsEnabled = !value;
base.EnableMenu = !value;
OnPropertyChanged("Carregando");
}
}
public MetaSeguradoraViewModel(Seguradora seguradora)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
_servico = new MetaSeguradoraServico();
Seleciona(seguradora);
_selectedSeguradora = seguradora;
}
private async void Seleciona(Seguradora seguradora)
{
Loading(isLoading: true);
await PermissaoTela((TipoTela)31);
await SelecionaMetasSeguradora(seguradora);
Loading(isLoading: false);
}
public void SelecionaMetaSeguradora(MetaSeguradora metaSeguradora)
{
SelectedMetaSeguradora = metaSeguradora;
}
private async Task SelecionaMetasSeguradora(Seguradora seguradora)
{
Carregando = true;
await CarregarMetas(seguradora);
if (MetasSeguradora.Count > 0)
{
SelecionaMetaSeguradora(MetasSeguradora.First());
}
else
{
SelectedMetaSeguradora = new MetaSeguradora();
Alterar(alterar: false);
base.EnableMenu = false;
base.EnableAlterar = false;
base.EnableExcluir = false;
}
Carregando = false;
}
public void Incluir()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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_0034: Expected O, but got Unknown
DateTime date = Funcoes.GetNetworkTime().Date;
SelectedMetaSeguradora = new MetaSeguradora
{
Ano = date.Year,
Mes = (Mes)date.Month
};
Alterar(alterar: true);
}
public async Task<List<KeyValuePair<string, string>>> Salvar()
{
SelectedMetaSeguradora.Seguradora = _selectedSeguradora;
string acao = ((((DomainBase)SelectedMetaSeguradora).Id == 0L) ? "INCLUIU" : "ALTEROU");
MetaSeguradora value = await _servico.Save(SelectedMetaSeguradora);
if (!_servico.Sucesso)
{
return null;
}
RegistrarAcao(acao + " META DA SEGURADORA \"" + value.Seguradora.Nome + "\"", ((DomainBase)value).Id, (TipoTela)31, $"ID: {((DomainBase)value).Id}\nVALOR: {value.Valor:C}\nMÊS: {Functions.GetDescription((Enum)(object)value.Mes)}\nANO: {value.Ano}");
if (MetasSeguradora.Any((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id))
{
DomainBase.Copy<MetaSeguradora, MetaSeguradora>(MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value);
}
else
{
MetasSeguradora.Add(value);
}
MetasSeguradora = new ObservableCollection<MetaSeguradora>(MetasSeguradora);
SelectedMetaSeguradora = MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)value).Id);
Alterar(alterar: false);
return null;
}
public async Task<bool> Excluir()
{
if (SelectedMetaSeguradora == null || ((DomainBase)SelectedMetaSeguradora).Id == 0L)
{
return false;
}
if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO")))
{
return false;
}
Carregando = true;
if (!(await _servico.Delete(SelectedMetaSeguradora)))
{
Carregando = false;
Alterar(alterar: false);
return false;
}
MetaSeguradoraViewModel metaSeguradoraViewModel = this;
Seguradora seguradora = SelectedMetaSeguradora.Seguradora;
metaSeguradoraViewModel.RegistrarAcao("EXCLUIU META DA SEGURADORA \"" + ((seguradora != null) ? seguradora.Nome : null) + "\"", ((DomainBase)SelectedMetaSeguradora).Id, (TipoTela)31, $"ID: {((DomainBase)SelectedMetaSeguradora).Id}\nVALOR: {SelectedMetaSeguradora.Valor:C}\nMÊS: {Functions.GetDescription((Enum)(object)SelectedMetaSeguradora.Mes)}\nANO: {SelectedMetaSeguradora.Ano}");
int num = MetasSeguradora.IndexOf(SelectedMetaSeguradora);
MetasSeguradora.Remove(SelectedMetaSeguradora);
MetasSeguradora.Remove(SelectedMetaSeguradora);
MetasSeguradora = new ObservableCollection<MetaSeguradora>(MetasSeguradora);
if (MetasSeguradora.Count > 0)
{
SelectedMetaSeguradora = ((num < MetasSeguradora.Count) ? MetasSeguradora.ElementAt(num) : MetasSeguradora.Last());
}
else
{
SelectedMetaSeguradora = new MetaSeguradora();
Alterar(alterar: false);
base.EnableMenu = false;
base.EnableAlterar = false;
base.EnableExcluir = false;
}
Carregando = false;
return true;
}
public void CancelarAlteracao()
{
Carregando = true;
if (CancelMetaSeguradora != null && MetasSeguradora.Any((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id))
{
DomainBase.Copy<MetaSeguradora, MetaSeguradora>(MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id), CancelMetaSeguradora);
SelectedMetaSeguradora = MetasSeguradora.First((MetaSeguradora x) => ((DomainBase)x).Id == ((DomainBase)CancelMetaSeguradora).Id);
}
Alterar(alterar: false);
Carregando = false;
}
private async Task CarregarMetas(Seguradora seguradora)
{
MetasSeguradora = new ObservableCollection<MetaSeguradora>(from x in await new BaseServico().BuscarMetaSeguradoraAsync(seguradora)
orderby x.Mes, x.Valor
select x);
}
}
|