diff options
Diffstat (limited to 'Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs b/Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs new file mode 100644 index 0000000..ad8c5a5 --- /dev/null +++ b/Gestor.Application/ViewModels/Generic/BaseTarefaViewModel.cs @@ -0,0 +1,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;
+ }
+ }
+}
\ No newline at end of file |