summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.BI/NotasViewModel.cs
blob: 7023c98a6eda6d2812ba3efa09618f86c35df129 (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
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;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Configuracoes;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;

namespace Gestor.Application.ViewModels.BI;

public class NotasViewModel : BaseSegurosViewModel
{
	private readonly TarefaServico _servico;

	private bool _enableIncluirNota = true;

	private bool _ocultarUsuarios;

	private ObservableCollection<Usuario> _usuarios;

	private Usuario _selectedUsuario;

	private Tarefa _tarefa;

	private ObservableCollection<Tarefa> _notas;

	private ObservableCollection<Tarefa> _notasConcluidas;

	private Tarefa _selectedNota;

	private bool _ocultarNotasConcluidas = true;

	public bool EnableIncluirNota
	{
		get
		{
			return _enableIncluirNota;
		}
		set
		{
			_enableIncluirNota = value;
			OnPropertyChanged("EnableIncluirNota");
		}
	}

	public bool OcultarUsuarios
	{
		get
		{
			return _ocultarUsuarios;
		}
		set
		{
			_ocultarUsuarios = value;
			OnPropertyChanged("OcultarUsuarios");
		}
	}

	public ObservableCollection<Usuario> Usuarios
	{
		get
		{
			return _usuarios;
		}
		set
		{
			_usuarios = value;
			OnPropertyChanged("Usuarios");
		}
	}

	public Usuario SelectedUsuario
	{
		get
		{
			return _selectedUsuario;
		}
		set
		{
			_selectedUsuario = value;
			Carregar();
			OnPropertyChanged("SelectedUsuario");
		}
	}

	public Tarefa Tarefa
	{
		get
		{
			return _tarefa;
		}
		set
		{
			_tarefa = value;
			OnPropertyChanged("Tarefa");
		}
	}

	public ObservableCollection<Tarefa> Notas
	{
		get
		{
			return _notas;
		}
		set
		{
			_notas = value;
			OnPropertyChanged("Notas");
		}
	}

	public ObservableCollection<Tarefa> NotasConcluidas
	{
		get
		{
			return _notasConcluidas;
		}
		set
		{
			_notasConcluidas = value;
			OnPropertyChanged("NotasConcluidas");
		}
	}

	public Tarefa SelectedNota
	{
		get
		{
			return _selectedNota;
		}
		set
		{
			_selectedNota = value;
			OnPropertyChanged("SelectedNota");
		}
	}

	public bool OcultarNotasConcluidas
	{
		get
		{
			return _ocultarNotasConcluidas;
		}
		set
		{
			_ocultarNotasConcluidas = value;
			OnPropertyChanged("OcultarNotasConcluidas");
		}
	}

	public NotasViewModel()
	{
		_servico = new TarefaServico();
		Usuarios = new ObservableCollection<Usuario>((from x in Recursos.Usuarios
			where (Recursos.Usuario.IdEmpresa == 1 || x.IdEmpresa == Recursos.Usuario.IdEmpresa) && !x.Excluido
			orderby x.Nome
			select x).ToList());
		SelectedUsuario = ((IEnumerable<Usuario>)Usuarios).FirstOrDefault((Func<Usuario, bool>)((Usuario x) => ((DomainBase)x).Id == ((DomainBase)Recursos.Usuario).Id));
		Usuario usuario = Recursos.Usuario;
		OcultarUsuarios = usuario != null && usuario.Administrador;
		Usuario usuario2 = Recursos.Usuario;
		EnableIncluirNota = usuario2 != null && ((DomainBase)usuario2).Id > 0;
	}

	public async void Carregar()
	{
		await CarregarNotas();
	}

	public async Task CarregarNotas()
	{
		if (SelectedUsuario == null)
		{
			return;
		}
		List<Tarefa> list = await _servico.BuscarNotas(((DomainBase)SelectedUsuario).Id);
		list.ForEach(delegate(Tarefa x)
		{
			if (x.Titulo == "TÍTULO" && x.Descricao == "DESCRIÇÃO")
			{
				x.HabilitarPublica = true;
			}
		});
		Notas = new ObservableCollection<Tarefa>(list);
		NotasConcluidas = new ObservableCollection<Tarefa>(await _servico.BuscarNotasConcluidas(((DomainBase)SelectedUsuario).Id));
	}

	public async Task AdicionarNota()
	{
		if (Notas != null && Notas.Any((Tarefa x) => x.Titulo == "TÍTULO" && x.Descricao == "DESCRIÇÃO"))
		{
			await ShowMessage("PARA ADICIONAR OUTRA NOTA, INSERIR TÍTULO E DESCRIÇÃO DA NOTA JÁ ADICIONADA");
			return;
		}
		Tarefa nota2 = new Tarefa
		{
			Agendamento = Funcoes.GetNetworkTime(),
			Titulo = "TÍTULO",
			Anotacoes = "DESCRIÇÃO",
			Usuario = Usuarios.First((Usuario x) => ((DomainBase)x).Id == ((DomainBase)SelectedUsuario).Id),
			UsuarioCadastro = Recursos.Usuario,
			Entidade = (TipoTarefa)1,
			Status = (StatusTarefa)0
		};
		nota2 = await _servico.Salvar(nota2);
		await CarregarNotas();
		SelectedNota = nota2;
	}

	public async Task<Tarefa> SalvarNota(Tarefa nota)
	{
		return await _servico.Salvar(nota);
	}

	public async Task<List<KeyValuePair<string, string>>> Salvar(Tarefa destino)
	{
		destino.AgendamentoRetroativo = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 45);
		List<KeyValuePair<string, string>> list = destino.Validate();
		if (list.Count > 0)
		{
			return list;
		}
		bool publica = destino.Publica;
		await _servico.Salvar(destino);
		if (!_servico.Sucesso)
		{
			return null;
		}
		if (publica)
		{
			long id = ((DomainBase)destino.Usuario).Id;
			List<Usuario> usuarios = Recursos.Usuarios;
			List<Task> list2 = new List<Task>();
			foreach (Usuario item in usuarios)
			{
				if (id != ((DomainBase)item).Id)
				{
					Tarefa val = (Tarefa)((DomainBase)destino).Clone();
					((DomainBase)val).Id = 0L;
					val.Usuario = item;
					list2.Add(_servico.Salvar(val));
				}
			}
			await Task.WhenAll(list2);
		}
		await CarregarNotas();
		return null;
	}

	public void ToggleNotasConcluidas()
	{
		OcultarNotasConcluidas = !OcultarNotasConcluidas;
	}

	public async Task ExcluirNota(Tarefa nota)
	{
		await _servico.Excluir(((DomainBase)nota).Id);
	}
}