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
|
using Gestor.Application.Actions;
using Gestor.Application.Helpers;
using Gestor.Application.Servicos;
using Gestor.Application.Servicos.Generic;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Domain.Configuracoes;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Gestor.Application.ViewModels
{
public class TrilhaViewModel : BaseSegurosViewModel
{
private ObservableCollection<Trilha> _trilhas = new ObservableCollection<Trilha>();
private ObservableCollection<Fase> _fases = new ObservableCollection<Fase>();
private Trilha _selectedTrilha = new Trilha();
private Tarefa _selectedTarefa;
private ObservableCollection<Usuario> _usuarios;
private Usuario _selectedUsuario = new Usuario();
public ObservableCollection<Fase> Fases
{
get
{
return this._fases;
}
set
{
this._fases = value;
base.OnPropertyChanged("Fases");
}
}
public Tarefa SelectedTarefa
{
get
{
return this._selectedTarefa;
}
set
{
this._selectedTarefa = value;
base.OnPropertyChanged("SelectedTarefa");
}
}
public Trilha SelectedTrilha
{
get
{
return this._selectedTrilha;
}
set
{
this._selectedTrilha = value;
base.OnPropertyChanged("SelectedTrilha");
}
}
public Usuario SelectedUsuario
{
get
{
return this._selectedUsuario;
}
set
{
this._selectedUsuario = value;
base.OnPropertyChanged("SelectedUsuario");
}
}
private TarefaServico Servico
{
get;
}
public ObservableCollection<Trilha> Trilhas
{
get
{
return this._trilhas;
}
set
{
this._trilhas = value;
base.OnPropertyChanged("Trilhas");
}
}
public ObservableCollection<Usuario> Usuarios
{
get
{
return this._usuarios;
}
set
{
this._usuarios = value;
base.OnPropertyChanged("Usuarios");
}
}
public TrilhaViewModel()
{
this.Servico = new TarefaServico();
List<Usuario> usuarios = new List<Usuario>();
Usuario usuario = new Usuario();
usuario.set_Id((long)0);
usuario.set_Nome("TODOS OS USUÁRIOS");
usuarios.Add(usuario);
List<Usuario> usuarios1 = usuarios;
usuarios1.AddRange(Recursos.Usuarios.Where<Usuario>((Usuario x) => {
if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa())
{
return false;
}
return !x.get_Excluido();
}).OrderBy<Usuario, string>((Usuario x) => x.get_Nome()).ToList<Usuario>());
this.Usuarios = new ObservableCollection<Usuario>(usuarios1);
this.SelectedUsuario = this.Usuarios.First<Usuario>();
Gestor.Application.Actions.Actions.AtualizaTrilhas = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.AtualizaTrilhas, new Action(this.AtualizarTrilhas));
this.CarregaTrilhas();
}
public void AtualizarTrilhas()
{
this.CarregaTrilhas();
}
public async Task Cancelar()
{
await this.CarregarTrilha(this.SelectedTrilha);
base.Alterar(false);
}
public async Task CarregarTrilha(Trilha trilha)
{
if (trilha != null && trilha.get_Id() != 0)
{
this.SelectedTrilha = trilha;
List<Tarefa> tarefas = await this.Servico.BuscarTarefas(trilha.get_Id());
List<Tarefa> tarefas1 = tarefas;
List<Fase> fases = await this.Servico.BuscarFases(trilha.get_Id());
this.Fases = new ObservableCollection<Fase>();
fases.ForEach((Fase x) => {
x.set_Tarefas(tarefas1.Where<Tarefa>((Tarefa t) => {
if (this.SelectedUsuario != null && this.SelectedUsuario.get_Id() != 0 && this.SelectedUsuario.get_Id() != t.get_Usuario().get_Id() || t.get_Fase().get_Id() != x.get_Id())
{
return false;
}
return t.get_Status() != 2;
}).ToList<Tarefa>());
this.Fases.Add(x);
});
}
}
public async Task CarregarTrilhas(Trilha trilha = null)
{
Trilha trilha1;
List<Trilha> trilhas = await this.Servico.BuscarTrilhas();
this.Trilhas = new ObservableCollection<Trilha>(trilhas);
TrilhaViewModel trilhaViewModel = this;
trilha1 = (trilha != null ? this.Trilhas.FirstOrDefault<Trilha>((Trilha x) => x.get_Id() == trilha.get_Id()) : trilhas.FirstOrDefault<Trilha>());
await trilhaViewModel.CarregarTrilha(trilha1);
}
public async void CarregaTrilhas()
{
await this.CarregarTrilhas(null);
}
public void Excluir(Fase origem, Tarefa data)
{
Tarefa tarefa = this.Fases.First<Fase>((Fase x) => x.get_Id() == origem.get_Id()).get_Tarefas().First<Tarefa>((Tarefa x) => x.get_Id() == data.get_Id());
this.Fases.First<Fase>((Fase x) => x.get_Id() == origem.get_Id()).get_Tarefas().Remove(tarefa);
}
public async Task Excluir(Tarefa tarefa)
{
if (tarefa.get_Id() != 0)
{
string[] titulo = new string[] { "DESEJA REALMENTE EXCLUIR A TAREFA ", tarefa.get_Titulo(), "?", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL" };
if (await base.ShowMessage(string.Concat(titulo), "SIM", "NÃO", false))
{
if (await this.Servico.Excluir(tarefa.get_Id()))
{
await this.CarregarTrilha(this.SelectedTrilha);
base.Alterar(false);
}
else
{
base.Alterar(false);
}
}
}
}
public void Inserir(Fase origem, Tarefa data, int index, bool aberto = false)
{
data.set_Aberto(aberto);
data.set_Fase(origem);
this.Fases.First<Fase>((Fase x) => x.get_Id() == origem.get_Id()).get_Tarefas().Insert((index == -1 ? 0 : index), data);
this.TrocarFase(data);
}
public async Task<List<KeyValuePair<string, string>>> Salvar(Tarefa destino)
{
List<KeyValuePair<string, string>> keyValuePairs;
Tarefa tarefa = destino;
List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
tarefa.set_AgendamentoRetroativo(configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 45));
List<KeyValuePair<string, string>> keyValuePairs1 = destino.Validate();
if (keyValuePairs1.Count <= 0)
{
await this.Servico.Salvar(destino);
if (this.Servico.Sucesso)
{
await this.CarregarTrilha(this.SelectedTrilha);
keyValuePairs = null;
}
else
{
keyValuePairs = null;
}
}
else
{
keyValuePairs = keyValuePairs1;
}
return keyValuePairs;
}
public async Task Salvar(Trilha destino)
{
TrilhaViewModel.u003cu003ec__DisplayClass37_0 variable;
this.SelectedTrilha = null;
this.Fases = null;
List<Fase> fases = destino.get_Fases();
Trilha trilha = await this.Servico.Salvar(destino);
if (this.Servico.Sucesso)
{
if (fases != null)
{
fases.ForEach((Fase x) => x.set_Trilha(trilha));
await this.Servico.Salvar(fases);
if (!this.Servico.Sucesso)
{
variable = null;
fases = null;
return;
}
}
await this.CarregarTrilhas(trilha);
}
variable = null;
fases = null;
}
private async void TrocarFase(Tarefa tarefa)
{
await this.Servico.Salvar(tarefa);
}
public void Update()
{
this.Fases = new ObservableCollection<Fase>(this.Fases);
}
}
}
|