summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs
blob: ad8c5a576aa2f0d4764f768ea1001cc8081100bb (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
using Gestor.Application.Helpers;
using Gestor.Application.Servicos;
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.Generic
{
	public abstract class BaseTarefaViewModel : BaseSegurosViewModel
	{
		private ObservableCollection<ResponsavelTarefa> _responsaveis = new ObservableCollection<ResponsavelTarefa>();

		private bool _hasResponsaveis;

		public abstract bool EnableAlterarTarefa
		{
			get;
			set;
		}

		public bool HasResponsaveis
		{
			get
			{
				return this._hasResponsaveis;
			}
			set
			{
				this._hasResponsaveis = value;
				base.OnPropertyChanged("HasResponsaveis");
			}
		}

		public ObservableCollection<ResponsavelTarefa> Responsaveis
		{
			get
			{
				return this._responsaveis;
			}
			set
			{
				this._responsaveis = value;
				this.HasResponsaveis = (value != null ? value.Count > 0 : false);
				base.OnPropertyChanged("Responsaveis");
			}
		}

		public abstract Tarefa SelectedTarefa
		{
			get;
			set;
		}

		public TarefaServico Servico
		{
			get;
			set;
		}

		protected BaseTarefaViewModel()
		{
		}

		internal async Task<PermissaoUsuario> BuscaPermisaoUsuario()
		{
			return await (new PermissaoUsuarioServico()).VerificarPermissao(Recursos.Usuario, 38);
		}

		public void ListaUsuariosResponsaveis()
		{
			bool usuario;
			Tarefa selectedTarefa = this.SelectedTarefa;
			if (selectedTarefa != null)
			{
				usuario = selectedTarefa.get_Usuario();
			}
			else
			{
				usuario = false;
			}
			if (!usuario)
			{
				return;
			}
			if (!this.Responsaveis.Any<ResponsavelTarefa>((ResponsavelTarefa r) => r.get_Usuario().get_Id() == this.SelectedTarefa.get_Usuario().get_Id()))
			{
				ObservableCollection<ResponsavelTarefa> responsaveis = this.Responsaveis;
				ResponsavelTarefa responsavelTarefa = new ResponsavelTarefa();
				responsavelTarefa.set_IdTarefa(this.SelectedTarefa.get_Id());
				responsavelTarefa.set_Usuario(this.SelectedTarefa.get_Usuario());
				responsaveis.Insert(0, responsavelTarefa);
			}
		}

		public async Task<bool> ValidaPermissaoParaEditarTarefa()
		{
			bool flag;
			bool flag1;
			bool flag2;
			bool id;
			bool flag3;
			bool flag4 = false;
			if (this.SelectedTarefa != null)
			{
				PermissaoUsuario permissaoUsuario = await this.BuscaPermisaoUsuario();
				if (Recursos.Usuario.get_Administrador())
				{
					flag4 = true;
				}
				else if (permissaoUsuario == null && !this.SelectedTarefa.get_Restrito().GetValueOrDefault())
				{
					flag4 = true;
				}
				else if (permissaoUsuario != null && !permissaoUsuario.get_Alterar())
				{
					flag4 = false;
				}
				else if (!this.SelectedTarefa.get_Restrito().GetValueOrDefault())
				{
					flag4 = true;
				}
				else
				{
					if (this.SelectedTarefa.get_UsuarioCadastro().get_Id() != Recursos.Usuario.get_Id())
					{
						List<ResponsavelTarefa> responsaveis = this.SelectedTarefa.get_Responsaveis();
						if (responsaveis != null)
						{
							flag3 = responsaveis.Any<ResponsavelTarefa>((ResponsavelTarefa x) => x.get_Usuario().get_Id() == Recursos.Usuario.get_Id());
						}
						else
						{
							flag3 = false;
						}
						if (flag3)
						{
							goto Label1;
						}
						id = this.SelectedTarefa.get_Usuario().get_Id() == Recursos.Usuario.get_Id();
						goto Label0;
					}
				Label1:
					id = true;
				Label0:
					flag4 = id;
				}
				bool flag5 = flag4;
				bool flag6 = flag5;
				this.EnableAlterarTarefa = flag5;
				bool flag7 = flag6;
				flag2 = flag7;
				base.EnableExcluir = flag7;
				bool flag8 = flag2;
				flag1 = flag8;
				base.EnableAlterar = flag8;
				flag = flag1;
			}
			else
			{
				bool flag9 = flag4;
				flag2 = flag9;
				this.EnableAlterarTarefa = flag9;
				bool flag10 = flag2;
				flag1 = flag10;
				base.EnableExcluir = flag10;
				base.EnableAlterar = flag1;
				flag = flag4;
			}
			return flag;
		}

		public async Task<bool> ValidaPermissaoParaExcluirTarefa(Tarefa tarefa = null)
		{
			bool id;
			bool flag;
			if (tarefa != null)
			{
				this.SelectedTarefa = tarefa;
			}
			PermissaoUsuario permissaoUsuario = await this.BuscaPermisaoUsuario();
			bool flag1 = false;
			if (Recursos.Usuario.get_Administrador())
			{
				flag1 = true;
			}
			else if (permissaoUsuario == null && !this.SelectedTarefa.get_Restrito().GetValueOrDefault())
			{
				flag1 = true;
			}
			else if (permissaoUsuario != null && !permissaoUsuario.get_Excluir())
			{
				flag1 = false;
			}
			else if (!this.SelectedTarefa.get_Restrito().GetValueOrDefault())
			{
				flag1 = true;
			}
			else
			{
				if (this.SelectedTarefa.get_UsuarioCadastro().get_Id() != Recursos.Usuario.get_Id())
				{
					List<ResponsavelTarefa> responsaveis = this.SelectedTarefa.get_Responsaveis();
					if (responsaveis != null)
					{
						flag = responsaveis.Any<ResponsavelTarefa>((ResponsavelTarefa x) => x.get_Usuario().get_Id() == Recursos.Usuario.get_Id());
					}
					else
					{
						flag = false;
					}
					if (flag)
					{
						goto Label1;
					}
					id = this.SelectedTarefa.get_Usuario().get_Id() == Recursos.Usuario.get_Id();
					goto Label0;
				}
			Label1:
				id = true;
			Label0:
				flag1 = id;
			}
			return flag1;
		}
	}
}