summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs')
-rw-r--r--Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs281
1 files changed, 281 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs b/Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs
new file mode 100644
index 0000000..8ee9f0b
--- /dev/null
+++ b/Gestor.Application/ViewModels/Drawer/Ajuda/InstalacaoViewModel.cs
@@ -0,0 +1,281 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Model.Ajuda;
+using Gestor.Application.Servicos.Ajuda;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using Gestor.Model.License;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+
+namespace Gestor.Application.ViewModels.Drawer.Ajuda
+{
+ public class InstalacaoViewModel : BaseViewModel
+ {
+ private readonly AjudaServico _ajudaServico;
+
+ private bool _enableExclusao;
+
+ private bool _mostrarAggilizador;
+
+ private string _infoGestor;
+
+ private string _infoAggilizador;
+
+ private bool _carregando;
+
+ private List<Gestor.Application.Model.Ajuda.Instalacao> _agger;
+
+ private ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao> _aggerFiltrado;
+
+ private List<Gestor.Application.Model.Ajuda.Instalacao> _aggilizador;
+
+ public List<Gestor.Application.Model.Ajuda.Instalacao> Agger
+ {
+ get
+ {
+ return this._agger;
+ }
+ set
+ {
+ this._agger = value;
+ base.OnPropertyChanged("Agger");
+ }
+ }
+
+ public ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao> AggerFiltrado
+ {
+ get
+ {
+ return this._aggerFiltrado;
+ }
+ set
+ {
+ this._aggerFiltrado = value;
+ base.OnPropertyChanged("AggerFiltrado");
+ }
+ }
+
+ public List<Gestor.Application.Model.Ajuda.Instalacao> Aggilizador
+ {
+ get
+ {
+ return this._aggilizador;
+ }
+ set
+ {
+ this._aggilizador = value;
+ base.OnPropertyChanged("Aggilizador");
+ }
+ }
+
+ public bool Carregando
+ {
+ get
+ {
+ return this._carregando;
+ }
+ set
+ {
+ this._carregando = value;
+ base.IsEnabled = !value;
+ base.EnableMenu = !value;
+ base.OnPropertyChanged("Carregando");
+ }
+ }
+
+ public bool EnableExclusao
+ {
+ get
+ {
+ return this._enableExclusao;
+ }
+ set
+ {
+ this._enableExclusao = value;
+ base.OnPropertyChanged("EnableExclusao");
+ }
+ }
+
+ public string InfoAggilizador
+ {
+ get
+ {
+ return this._infoAggilizador;
+ }
+ set
+ {
+ this._infoAggilizador = value;
+ base.OnPropertyChanged("InfoAggilizador");
+ }
+ }
+
+ public string InfoGestor
+ {
+ get
+ {
+ return this._infoGestor;
+ }
+ set
+ {
+ this._infoGestor = value;
+ base.OnPropertyChanged("InfoGestor");
+ }
+ }
+
+ public AutoCompleteFilterPredicate<object> InstalacaoItemFilter
+ {
+ get
+ {
+ AutoCompleteFilterPredicate<object> u003cu003e9_370 = InstalacaoViewModel.u003cu003ec.u003cu003e9__37_0;
+ if (u003cu003e9_370 == null)
+ {
+ u003cu003e9_370 = new AutoCompleteFilterPredicate<object>(InstalacaoViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => {
+ if (((Gestor.Application.Model.Ajuda.Instalacao)obj).Maquina.ToUpper().Contains(searchText.ToUpper()) || ((Gestor.Application.Model.Ajuda.Instalacao)obj).Usuario.ToUpper().Contains(searchText.ToUpper()))
+ {
+ return true;
+ }
+ return ((Gestor.Application.Model.Ajuda.Instalacao)obj).DataIntalacao.ToString().Contains(searchText.ToUpper());
+ });
+ InstalacaoViewModel.u003cu003ec.u003cu003e9__37_0 = u003cu003e9_370;
+ }
+ return u003cu003e9_370;
+ }
+ }
+
+ public bool MostrarAggilizador
+ {
+ get
+ {
+ return this._mostrarAggilizador;
+ }
+ set
+ {
+ this._mostrarAggilizador = value;
+ base.OnPropertyChanged("MostrarAggilizador");
+ }
+ }
+
+ public InstalacaoViewModel()
+ {
+ Usuario usuario = Recursos.Usuario;
+ if (usuario != null)
+ {
+ id = usuario.get_Id() > (long)0;
+ }
+ else
+ {
+ id = false;
+ }
+ this._enableExclusao = id;
+ base();
+ bool id;
+ this._ajudaServico = new AjudaServico();
+ this.LoadInstalacoes();
+ }
+
+ public async void Excluir(long id)
+ {
+ if (await this._ajudaServico.ExcluirInstalacao(id))
+ {
+ this.LoadInstalacoes();
+ }
+ }
+
+ internal async Task<List<Gestor.Application.Model.Ajuda.Instalacao>> Filtrar(string value)
+ {
+ List<Gestor.Application.Model.Ajuda.Instalacao> instalacaos = await Task.Run<List<Gestor.Application.Model.Ajuda.Instalacao>>(() => this.FiltrarInstalacao(value));
+ return instalacaos;
+ }
+
+ public List<Gestor.Application.Model.Ajuda.Instalacao> FiltrarInstalacao(string filter)
+ {
+ this.AggerFiltrado = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao>(this.Agger) : new ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao>(this.Agger.Where<Gestor.Application.Model.Ajuda.Instalacao>((Gestor.Application.Model.Ajuda.Instalacao x) => {
+ if (ValidationHelper.RemoveDiacritics(x.Maquina.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || ValidationHelper.RemoveDiacritics(x.Usuario.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)))
+ {
+ return true;
+ }
+ return x.DataIntalacao.ToString().Contains(ValidationHelper.RemoveDiacritics(filter));
+ })));
+ return this.AggerFiltrado.ToList<Gestor.Application.Model.Ajuda.Instalacao>();
+ }
+
+ private async void LoadInstalacoes()
+ {
+ int? nullable;
+ List<Gestor.Application.Model.Ajuda.Instalacao> instalacaos;
+ int? nullable1;
+ int? nullable2;
+ string str;
+ this.Carregando = true;
+ ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao> observableCollection = await this._ajudaServico.BuscarLicencas();
+ InstalacaoViewModel list = this;
+ ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao> observableCollection1 = observableCollection;
+ list.Agger = (
+ from x in observableCollection1
+ where !string.IsNullOrEmpty(x.IdGerenciador)
+ select x).ToList<Gestor.Application.Model.Ajuda.Instalacao>();
+ this.AggerFiltrado = new ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao>(this.Agger);
+ InstalacaoViewModel instalacaoViewModel = this;
+ List<Licenca> produtos = LicenseHelper.Produtos;
+ if (produtos.Any<Licenca>((Licenca x) => x.get_Produto() == 81))
+ {
+ instalacaos = new List<Gestor.Application.Model.Ajuda.Instalacao>();
+ }
+ else
+ {
+ ObservableCollection<Gestor.Application.Model.Ajuda.Instalacao> observableCollection2 = observableCollection;
+ instalacaos = (
+ from x in observableCollection2
+ where !string.IsNullOrEmpty(x.IdAggilizador)
+ select x).ToList<Gestor.Application.Model.Ajuda.Instalacao>();
+ }
+ instalacaoViewModel.Aggilizador = instalacaos;
+ InstalacaoViewModel instalacaoViewModel1 = this;
+ object count = this.Agger.Count;
+ List<Licenca> licencas = LicenseHelper.Produtos;
+ Licenca licenca = licencas.FirstOrDefault<Licenca>((Licenca x) => x.get_Produto() == 1);
+ if (licenca != null)
+ {
+ nullable1 = new int?(licenca.get_Quantidade());
+ }
+ else
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ instalacaoViewModel1.InfoGestor = string.Format("{0} LICENÇAS INSTALADAS DE {1} LICENÇAS CONTRATADAS.", count, nullable1);
+ InstalacaoViewModel instalacaoViewModel2 = this;
+ if (this.Aggilizador.Count > 0)
+ {
+ object obj = this.Aggilizador.Count;
+ List<Licenca> produtos1 = LicenseHelper.Produtos;
+ Licenca licenca1 = produtos1.FirstOrDefault<Licenca>((Licenca x) => x.get_Produto() == 81);
+ if (licenca1 != null)
+ {
+ nullable2 = new int?(licenca1.get_Quantidade());
+ }
+ else
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ str = string.Format("{0} LICENÇAS INSTALADAS DE {1} LICENÇAS CONTRATADAS.", obj, nullable2);
+ }
+ else
+ {
+ str = "";
+ }
+ instalacaoViewModel2.InfoAggilizador = str;
+ this.MostrarAggilizador = this.Aggilizador.Count > 0;
+ this.Carregando = false;
+ }
+ }
+} \ No newline at end of file