summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs826
1 files changed, 826 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs
new file mode 100644
index 0000000..7f04040
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Ferramentas/UsuarioViewModel.cs
@@ -0,0 +1,826 @@
+using Agger.Registro;
+using Gestor.Application.Actions;
+using Gestor.Application.Drawers;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Helpers;
+using Gestor.Common.Security;
+using Gestor.Common.Validation;
+using Gestor.Model.API;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using MaterialDesignThemes.Wpf;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Net.Http;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Gestor.Application.ViewModels.Ferramentas
+{
+ public class UsuarioViewModel : BaseSegurosViewModel
+ {
+ private readonly UsuarioServico _servico;
+
+ private readonly PermissaoUsuarioServico _permissaoUsuarioServico;
+
+ public Usuario CancelUsuario;
+
+ private string _inicioAcesso;
+
+ private string _fimAcesso;
+
+ private Usuario _selectedUsuario;
+
+ private Empresa _selectedFilial;
+
+ private bool _cartaoCriado;
+
+ private ObservableCollection<Usuario> _usuariosFiltrados = new ObservableCollection<Usuario>();
+
+ private bool _isExpanded;
+
+ private bool _enableGrid = true;
+
+ private Visibility _horarioAcessoVisible;
+
+ private List<Empresa> _empresas = Recursos.Empresas;
+
+ private string _confirmaSenha;
+
+ private string _labelCartao;
+
+ public Visibility AddUsuarioCentralSeguradoVisibility { get; set; } = (string.IsNullOrEmpty(Connection.UrlCentralSegurado) ? Visibility.Collapsed : Visibility.Visible);
+
+ public bool CartaoCriado
+ {
+ get
+ {
+ return this._cartaoCriado;
+ }
+ set
+ {
+ this._cartaoCriado = value;
+ base.OnPropertyChanged("CartaoCriado");
+ }
+ }
+
+ public string ConfirmaSenha
+ {
+ get
+ {
+ return this._confirmaSenha;
+ }
+ set
+ {
+ this._confirmaSenha = value;
+ base.OnPropertyChanged("ConfirmaSenha");
+ }
+ }
+
+ public static DrawerHost Drawer
+ {
+ get;
+ set;
+ }
+
+ public List<Empresa> Empresas
+ {
+ get
+ {
+ return this._empresas;
+ }
+ set
+ {
+ this._empresas = value;
+ base.OnPropertyChanged("Empresas");
+ }
+ }
+
+ public bool EnableGrid
+ {
+ get
+ {
+ return this._enableGrid;
+ }
+ set
+ {
+ this._enableGrid = value;
+ base.OnPropertyChanged("EnableGrid");
+ }
+ }
+
+ public string FimAcesso
+ {
+ get
+ {
+ return this._fimAcesso;
+ }
+ set
+ {
+ this._fimAcesso = value;
+ base.OnPropertyChanged("FimAcesso");
+ }
+ }
+
+ public Visibility HorarioAcessoVisible
+ {
+ get
+ {
+ return this._horarioAcessoVisible;
+ }
+ set
+ {
+ this._horarioAcessoVisible = value;
+ base.OnPropertyChanged("HorarioAcessoVisible");
+ }
+ }
+
+ public string InicioAcesso
+ {
+ get
+ {
+ return this._inicioAcesso;
+ }
+ set
+ {
+ this._inicioAcesso = value;
+ base.OnPropertyChanged("InicioAcesso");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public string LabelCartao
+ {
+ get
+ {
+ return this._labelCartao;
+ }
+ set
+ {
+ this._labelCartao = value;
+ base.OnPropertyChanged("LabelCartao");
+ }
+ }
+
+ public List<Gestor.Model.Domain.Seguros.PermissaoUsuario> PermissaoUsuario
+ {
+ get;
+ set;
+ }
+
+ public Empresa SelectedFilial
+ {
+ get
+ {
+ return this._selectedFilial;
+ }
+ set
+ {
+ this._selectedFilial = value;
+ base.OnPropertyChanged("SelectedFilial");
+ }
+ }
+
+ public Usuario SelectedUsuario
+ {
+ get
+ {
+ return this._selectedUsuario;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedUsuario = value;
+ this.WorkOnSelectedUsuario(value, true);
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ base.OnPropertyChanged("SelectedUsuario");
+ }
+ }
+
+ private string SenhaOriginal
+ {
+ get;
+ set;
+ }
+
+ public List<Usuario> Usuarios
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Usuario> UsuariosFiltrados
+ {
+ get
+ {
+ return this._usuariosFiltrados;
+ }
+ set
+ {
+ this._usuariosFiltrados = value;
+ this.IsExpanded = (value != null ? value.Count > 0 : false);
+ base.OnPropertyChanged("UsuariosFiltrados");
+ }
+ }
+
+ public UsuarioViewModel()
+ {
+ this._servico = new UsuarioServico();
+ this._permissaoUsuarioServico = new PermissaoUsuarioServico();
+ base.EnableMenu = true;
+ }
+
+ public async Task AddUsuarioAdiministadorCentralSegurado()
+ {
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ string str4;
+ string str5;
+ string str6;
+ string str7;
+ if (this.SelectedUsuario != null)
+ {
+ base.Loading(true);
+ str7 = "USUÁRIO CADASTRADO/ALTERADO COM SUCESSO!";
+ try
+ {
+ str = (this.SelectedUsuario.get_Telefone() == null ? string.Empty : string.Concat("(", this.SelectedUsuario.get_Prefixo(), ") ", this.SelectedUsuario.get_Telefone()));
+ string str8 = str;
+ Token token = new Token();
+ UsuarioCentralSegurado usuarioCentralSegurado = new UsuarioCentralSegurado();
+ usuarioCentralSegurado.set_Id("");
+ usuarioCentralSegurado.set_Senha("");
+ usuarioCentralSegurado.set_Serial(token.Encrypt(Recursos.Empresa.get_Serial()));
+ usuarioCentralSegurado.set_FornecedorId(ApplicationHelper.IdFornecedor);
+ usuarioCentralSegurado.set_Nome(token.Encrypt(this.SelectedUsuario.get_Nome()));
+ usuarioCentralSegurado.set_Documento(token.Encrypt(this.SelectedUsuario.get_Documento().Clear()));
+ usuarioCentralSegurado.set_Email(token.Encrypt(this.SelectedUsuario.get_Email()));
+ usuarioCentralSegurado.set_IdEmpresa(this.SelectedUsuario.get_IdEmpresa());
+ usuarioCentralSegurado.set_Telefone(token.Encrypt(str8));
+ str1 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Endereco()) : string.Empty);
+ usuarioCentralSegurado.set_Rua(str1);
+ str2 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Numero()) : string.Empty);
+ usuarioCentralSegurado.set_Numero(str2);
+ str3 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Bairro()) : string.Empty);
+ usuarioCentralSegurado.set_Bairro(str3);
+ str4 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Cidade()) : string.Empty);
+ usuarioCentralSegurado.set_Cidade(str4);
+ str5 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Estado()) : string.Empty);
+ usuarioCentralSegurado.set_Estado(str5);
+ str6 = (this.SelectedUsuario.get_Cidade() != null ? token.Encrypt(this.SelectedUsuario.get_Cep()) : string.Empty);
+ usuarioCentralSegurado.set_Cep(str6);
+ usuarioCentralSegurado.set_Corretora(token.Encrypt(Recursos.Empresa.get_Nome()));
+ usuarioCentralSegurado.set_UriCorretora(token.Encrypt(Connection.UrlCentralSegurado));
+ usuarioCentralSegurado.set_Admin(this.SelectedUsuario.get_AdministradorCentralSegurado());
+ UsuarioCentralSegurado usuarioCentralSegurado1 = usuarioCentralSegurado;
+ using (HttpClient httpClient = new HttpClient())
+ {
+ StringContent stringContent = new StringContent(JsonConvert.SerializeObject(usuarioCentralSegurado1), Encoding.UTF8, "application/json");
+ Uri centralSegurado = Address.get_CentralSegurado();
+ string[] strArrays = new string[] { "Usuario" };
+ Uri uri = centralSegurado.Append(strArrays);
+ string[] strArrays1 = new string[] { "AddAggerApp" };
+ Uri uri1 = uri.Append(strArrays1);
+ HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(uri1, stringContent);
+ await this._servico.AddCentralSegurado(this.SelectedUsuario.get_Id(), httpResponseMessage.get_IsSuccessStatusCode());
+ if (!httpResponseMessage.get_IsSuccessStatusCode())
+ {
+ string str9 = await httpResponseMessage.get_Content().ReadAsStringAsync();
+ str7 = string.Concat("HOUVE(RAM) O(S) SEGUINTE(S) ERROS: ", str9.Replace(";", ", ").ToUpper());
+ }
+ httpResponseMessage = null;
+ }
+ httpClient = null;
+ }
+ catch
+ {
+ str7 = "HOUVERAM ERROS AO CADASTRAR/ALTERAR O USUÁRIO!";
+ }
+ base.Loading(false);
+ await base.ShowMessage(str7, "OK", "", false);
+ }
+ str7 = null;
+ }
+
+ public async Task AlterarUsuario()
+ {
+ if (this.SelectedUsuario != null)
+ {
+ Usuario usuario = await this._servico.BuscarUsuarioPorId(this.SelectedUsuario.get_Id());
+ this.SenhaOriginal = (new Token()).AggerDecrypt(usuario.get_Senha());
+ await this.SelecionaUsuario(this.SelectedUsuario);
+ }
+ }
+
+ public async void AtualizaUsuario()
+ {
+ if (!base.EnableFields)
+ {
+ await this.CarregarUsuarios();
+ }
+ }
+
+ private async Task<bool> BuscaAlteracaoUsuarios(long idUsuario)
+ {
+ bool flag;
+ bool valueOrDefault;
+ bool flag1;
+ bool? nullable;
+ Usuario usuario = await (new UsuarioServico()).BuscarUsuarioPorId(idUsuario);
+ if (usuario == null)
+ {
+ valueOrDefault = false;
+ }
+ else
+ {
+ if (usuario != null)
+ {
+ nullable = new bool?(usuario.get_AdministradorCentralSegurado());
+ }
+ else
+ {
+ nullable = null;
+ }
+ bool? nullable1 = nullable;
+ bool administradorCentralSegurado = this.SelectedUsuario.get_AdministradorCentralSegurado();
+ valueOrDefault = !(nullable1.GetValueOrDefault() == administradorCentralSegurado & nullable1.HasValue);
+ }
+ bool flag2 = valueOrDefault;
+ flag1 = (flag2 || !this.SelectedUsuario.get_AdministradorCentralSegurado() ? false : this.SelectedUsuario.get_Id() == (long)0);
+ bool flag3 = flag1;
+ List<Usuario> usuarios = this.Usuarios;
+ IEnumerable<Usuario> administradorCentralSegurado1 =
+ from x in usuarios
+ where x.get_AdministradorCentralSegurado()
+ select x;
+ List<Usuario> list = (
+ from x in administradorCentralSegurado1
+ orderby x.get_Nome()
+ select x).ToList<Usuario>();
+ if (flag2 && !flag3 && list.Count == 0)
+ {
+ if (!await base.ShowMessage("ESTE USUÁRIO É O ÚNICO ADM DA CENTRAL DO SEGURADO.\nTEM CERTEZA QUE DESEJA REMOVER?", "SIM", "CANCELAR", false))
+ {
+ this.CancelarAlteracao();
+ flag = false;
+ return flag;
+ }
+ }
+ if (!(flag3 | flag2) || !string.IsNullOrEmpty(Connection.UrlCentralSegurado))
+ {
+ flag = flag2 | flag3;
+ }
+ else
+ {
+ if (this.SelectedUsuario != null)
+ {
+ this.SelectedUsuario.set_AdministradorCentralSegurado(false);
+ }
+ await base.ShowMessage("NÃO FOI POSSÍVEL ADICIONAR UM USUÁRIO ADM CENTRAL SEGURADO, POR FAVOR ENTRE EM CONTATO COM O SUPORTE AGGER. \nURL AUSENTE!", "OK", "", false);
+ flag = false;
+ }
+ return flag;
+ }
+
+ private async Task BuscaPermissao()
+ {
+ this.PermissaoUsuario = await this._permissaoUsuarioServico.PermissUsuario(Recursos.Usuario);
+ }
+
+ public async Task CancelarAlteracao()
+ {
+ long id;
+ await this.CarregarUsuarios();
+ if (!this.UsuariosFiltrados.Any<Usuario>())
+ {
+ this.SelectedUsuario = new Usuario();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ Usuario cancelUsuario = this.CancelUsuario;
+ if (cancelUsuario != null)
+ {
+ id = cancelUsuario.get_Id();
+ }
+ else
+ {
+ id = (long)0;
+ }
+ long num = id;
+ this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault<Usuario>((Usuario x) => x.get_Id() == num);
+ }
+ base.Alterar(false);
+ this.ConfirmaSenha = "";
+ }
+
+ private async Task CarregarUsuarios()
+ {
+ List<Usuario> usuarios = await (new BaseServico()).CarregarUsuarios();
+ UsuarioViewModel list = this;
+ List<Usuario> usuarios1 = usuarios;
+ IEnumerable<Usuario> usuarios2 = usuarios1.Where<Usuario>((Usuario x) => {
+ if (x.get_Excluido())
+ {
+ return false;
+ }
+ long? permissaoAggilizador = x.get_PermissaoAggilizador();
+ long num = (long)4;
+ return !(permissaoAggilizador.GetValueOrDefault() == num & permissaoAggilizador.HasValue);
+ });
+ list.Usuarios = (
+ from x in usuarios2
+ orderby x.get_Nome()
+ select x).ToList<Usuario>();
+ this.UsuariosFiltrados = new ObservableCollection<Usuario>(this.Usuarios);
+ await this.BuscaPermissao();
+ }
+
+ public async Task CriarCartao(bool dadosUsuario)
+ {
+ await base.ShowMessage("CARTÃO CRIADO/ATUALIZADO COM SUCESSO", "OK", "", false);
+ }
+
+ public async Task Excluir()
+ {
+ if (this.SelectedUsuario != null && this.SelectedUsuario.get_Id() != 0)
+ {
+ if (await (new VendedorUsuarioServico()).FindVinculoByUsuario(this.SelectedUsuario.get_Id()))
+ {
+ await base.ShowMessage("O USUÁRIO POSSUI VÍNCULO DE VENDEDOR, REMOVA O VÍNCULO ANTES DE EXCLUIR.", "OK", "", false);
+ }
+ else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false))
+ {
+ base.Loading(true);
+ if (await this._servico.Delete(this.SelectedUsuario))
+ {
+ base.RegistrarAcao(string.Concat("EXCLUIU USUÁRIO \"", this.SelectedUsuario.get_Nome(), "\""), this.SelectedUsuario.get_Id(), new TipoTela?(16), string.Format("ID: {0}", this.SelectedUsuario.get_Id()));
+ await this.CarregarUsuarios();
+ if (!this.UsuariosFiltrados.Any<Usuario>())
+ {
+ this.SelectedUsuario = new Usuario();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault<Usuario>();
+ }
+ base.Loading(false);
+ base.ToggleSnackBar("USUÁRIO EXCLUÍDO COM SUCESSO", true);
+ }
+ else
+ {
+ base.Loading(false);
+ }
+ }
+ }
+ }
+
+ internal async Task<List<Usuario>> Filtrar(string value)
+ {
+ List<Usuario> usuarios = await Task.Run<List<Usuario>>(() => this.FiltrarUsuario(value));
+ return usuarios;
+ }
+
+ public List<Usuario> FiltrarUsuario(string filter)
+ {
+ this.UsuariosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Usuario>(this.Usuarios) : new ObservableCollection<Usuario>(
+ from x in this.Usuarios
+ where ValidationHelper.RemoveDiacritics(x.get_Nome().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ orderby !x.get_Excluido() descending, x.get_Nome()
+ select x));
+ return this.UsuariosFiltrados.ToList<Usuario>();
+ }
+
+ public void Incluir()
+ {
+ Usuario usuario = new Usuario();
+ usuario.set_IdEmpresa(Recursos.Usuario.get_IdEmpresa());
+ usuario.set_Segunda(new bool?(true));
+ usuario.set_Terca(new bool?(true));
+ usuario.set_Quarta(new bool?(true));
+ usuario.set_Quinta(new bool?(true));
+ usuario.set_Sexta(new bool?(true));
+ usuario.set_Sabado(new bool?(true));
+ usuario.set_Domingo(new bool?(true));
+ usuario.set_Excluido(false);
+ usuario.set_FiltroInicial(new TipoFiltroCliente?(0));
+ this.SelectedUsuario = usuario;
+ this.SenhaOriginal = null;
+ base.Alterar(true);
+ }
+
+ public async Task OpenPermissao()
+ {
+ bool selectedUsuario = this.SelectedUsuario == null;
+ if (selectedUsuario)
+ {
+ selectedUsuario = await base.ShowMessage("É NECESSÁRIO SELECIONAR UM USUÁRIO!", "OK", "", false);
+ }
+ if (!selectedUsuario)
+ {
+ Gestor.Application.Actions.Actions.AtualizaUsuario = (Action)Delegate.Remove(Gestor.Application.Actions.Actions.AtualizaUsuario, new Action(this.AtualizaUsuario));
+ Gestor.Application.Actions.Actions.AtualizaUsuario = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.AtualizaUsuario, new Action(this.AtualizaUsuario));
+ base.ShowDrawer(new PermissaoUsuarioDrawer(this.SelectedUsuario), 0, false);
+ }
+ }
+
+ public async Task OpenVinculo()
+ {
+ bool selectedUsuario = this.SelectedUsuario == null;
+ if (selectedUsuario)
+ {
+ selectedUsuario = await base.ShowMessage("É NECESSÁRIO SELECIONAR UM USUÁRIO!", "OK", "", false);
+ }
+ if (!selectedUsuario)
+ {
+ base.ShowDrawer(new VinculoVendedorDrawer(this.SelectedUsuario), 0, true);
+ }
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ DateTime dateTime;
+ DateTime dateTime1;
+ string str;
+ long num;
+ string str1;
+ string str2;
+ if (!DateTime.TryParse(this.InicioAcesso, out dateTime) || !DateTime.TryParse(this.FimAcesso, out dateTime1))
+ {
+ DateTime? nullable = null;
+ this.SelectedUsuario.set_InicioAcesso(nullable);
+ nullable = null;
+ this.SelectedUsuario.set_FimAcesso(nullable);
+ }
+ else
+ {
+ this.SelectedUsuario.set_InicioAcesso(new DateTime?(dateTime));
+ this.SelectedUsuario.set_FimAcesso(new DateTime?(dateTime1));
+ }
+ Usuario selectedUsuario = this.SelectedUsuario;
+ str = (!string.IsNullOrEmpty(this.SelectedUsuario.get_Senha()) ? this.SelectedUsuario.get_Senha() : this.SenhaOriginal);
+ selectedUsuario.set_Senha(str);
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedUsuario.Validate();
+ List<KeyValuePair<string, string>> keyValuePairs2 = keyValuePairs1;
+ keyValuePairs2.AddRange(await this.Validate());
+ keyValuePairs2 = null;
+ if (keyValuePairs1.Count <= 0)
+ {
+ this.SelectedUsuario.set_Senha((new Token()).AggerEncrypt(this.SelectedUsuario.get_Senha()));
+ Usuario usuario = this.SelectedUsuario;
+ num = (this.SelectedUsuario.get_IdEmpresa() == 0 ? Recursos.Usuario.get_IdEmpresa() : this.SelectedUsuario.get_IdEmpresa());
+ usuario.set_IdEmpresa(num);
+ bool flag = await this.BuscaAlteracaoUsuarios(this.SelectedUsuario.get_Id());
+ str1 = (this.SelectedUsuario.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ str2 = str1;
+ Usuario usuario1 = await this._servico.Save(this.SelectedUsuario);
+ if (this._servico.Sucesso)
+ {
+ base.RegistrarAcao(string.Concat(str2, " USUÁRIO \"", usuario1.get_Nome(), "\""), usuario1.get_Id(), new TipoTela?(16), string.Format("ID: {0}", usuario1.get_Id()));
+ if (flag)
+ {
+ await this.AddUsuarioAdiministadorCentralSegurado();
+ }
+ await this.CarregarUsuarios();
+ this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault<Usuario>((Usuario x) => x.get_Id() == usuario1.get_Id());
+ Recursos.Usuarios = this.Usuarios;
+ this.ConfirmaSenha = "";
+ base.Alterar(false);
+ base.ToggleSnackBar("USUÁRIO SALVO COM SUCESSO", true);
+ this.IsExpanded = true;
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ keyValuePairs1 = null;
+ str2 = null;
+ return keyValuePairs;
+ }
+
+ public async Task Seleciona()
+ {
+ Visibility visibility;
+ UsuarioViewModel usuarioViewModel = this;
+ visibility = (base.Restricao(94) ? Visibility.Collapsed : Visibility.Visible);
+ usuarioViewModel.HorarioAcessoVisible = visibility;
+ await base.PermissaoTela(16);
+ await this.SelecionaUsuarios();
+ }
+
+ public async Task SelecionaUsuario(Usuario usuario)
+ {
+ Usuario usuario1 = await this._servico.BuscarUsuarioPorId(usuario.get_Id());
+ bool? segunda = usuario1.get_Segunda();
+ usuario1.set_Segunda(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Terca();
+ usuario1.set_Terca(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Quarta();
+ usuario1.set_Quarta(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Quinta();
+ usuario1.set_Quinta(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Sexta();
+ usuario1.set_Sexta(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Sabado();
+ usuario1.set_Sabado(new bool?(segunda.GetValueOrDefault(true)));
+ segunda = usuario1.get_Domingo();
+ usuario1.set_Domingo(new bool?(segunda.GetValueOrDefault(true)));
+ if (Recursos.Usuario.get_Id() == usuario.get_Id())
+ {
+ usuario1.set_Senha((new Token()).AggerDecrypt(usuario1.get_Senha()));
+ this.SenhaOriginal = usuario1.get_Senha();
+ this.ConfirmaSenha = "";
+ DomainBase.Copy<Usuario, Usuario>(this.UsuariosFiltrados.First<Usuario>((Usuario x) => x.get_Id() == usuario.get_Id()), usuario1);
+ }
+ this.SelectedUsuario = this.UsuariosFiltrados.First<Usuario>((Usuario x) => x.get_Id() == usuario.get_Id());
+ }
+
+ private async Task SelecionaUsuarios()
+ {
+ this.EnableGrid = false;
+ base.Loading(true);
+ await this.CarregarUsuarios();
+ if (this.UsuariosFiltrados.Count <= 0)
+ {
+ Usuario usuario = new Usuario();
+ usuario.set_Segunda(new bool?(true));
+ usuario.set_Terca(new bool?(true));
+ usuario.set_Quarta(new bool?(true));
+ usuario.set_Quinta(new bool?(true));
+ usuario.set_Sexta(new bool?(true));
+ usuario.set_Sabado(new bool?(true));
+ usuario.set_Domingo(new bool?(true));
+ this.SelectedUsuario = usuario;
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ await this.SelecionaUsuario(this.UsuariosFiltrados.First<Usuario>());
+ }
+ base.Loading(false);
+ this.EnableGrid = true;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<Usuario> usuarios;
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (this.SenhaOriginal == null || this.SenhaOriginal != this.SelectedUsuario.get_Senha())
+ {
+ string senha = (new Token()).Decrypt(this.SelectedUsuario.get_Senha());
+ if (senha == null)
+ {
+ senha = this.SelectedUsuario.get_Senha();
+ }
+ string str = senha;
+ if (string.IsNullOrWhiteSpace(this.ConfirmaSenha))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("ConfirmaSenha|CONFIRMAÇÃO SENHA", "OBRIGATÓRIO"));
+ }
+ else if (!string.Equals(this.ConfirmaSenha, str))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("ConfirmaSenha|CONFIRMAÇÃO SENHA", "INVÁLIDO"));
+ }
+ }
+ if (string.IsNullOrWhiteSpace(this.SelectedUsuario.get_Login()))
+ {
+ usuarios = new List<Usuario>();
+ }
+ else
+ {
+ usuarios = await (new BaseServico()).BuscarUsuarioPorLoginInteiro(this.SelectedUsuario.get_Login());
+ }
+ foreach (Usuario usuario in usuarios)
+ {
+ if (usuario.get_Id() == this.SelectedUsuario.get_Id())
+ {
+ continue;
+ }
+ keyValuePairs.Add(new KeyValuePair<string, string>("Login", string.Concat("O LOGIN JÁ ESTÁ CADASTRADO PARA O USUÁRIO \"", usuario.get_Nome(), "\".")));
+ }
+ if (this.SelectedUsuario.get_InicioAcesso().HasValue && !this.SelectedUsuario.get_FimAcesso().HasValue)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("FIM DO ACESSO", "NECESSÁRIO PREENCHER O CAMPO FIM DO ACESSO!"));
+ }
+ if (!this.SelectedUsuario.get_InicioAcesso().HasValue && this.SelectedUsuario.get_FimAcesso().HasValue)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("INÍCIO DO ACESSO", "NECESSÁRIO PREENCHER O CAMPO INÍCIO DO ACESSO!"));
+ }
+ bool flag = !string.IsNullOrWhiteSpace(this.SelectedUsuario.get_Documento());
+ if (flag)
+ {
+ flag = await (new BaseServico()).BuscarUsuarioMesmoDocumento(ValidationHelper.OnlyNumber(this.SelectedUsuario.get_Documento()), this.SelectedUsuario.get_Id(), this.SelectedUsuario.get_IdEmpresa());
+ }
+ if (flag)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("Documento", "O DOCUMENTO JÁ ESTÁ SENDO USADO EM OUTRO USUÁRIO"));
+ }
+ List<KeyValuePair<string, string>> keyValuePairs1 = keyValuePairs;
+ keyValuePairs = null;
+ return keyValuePairs1;
+ }
+
+ public async Task VerificaUsuarioAdmCentralSegurado()
+ {
+ await this.BuscaAlteracaoUsuarios(this.SelectedUsuario.get_Id());
+ }
+
+ private void WorkOnSelectedUsuario(Usuario value, bool registrar = true)
+ {
+ long? nullable;
+ this.CartaoCriado = false;
+ this.CancelUsuario = (value == null || value.get_Id() == 0 ? this.CancelUsuario : (Usuario)value.Clone());
+ if (value == null || value.get_Id() == 0)
+ {
+ return;
+ }
+ value.set_Senha(EncryptionHelper.Decrypt(value.get_Senha()));
+ if (this.LastAccessId == value.get_Id() && this.LastAccessTela == 16)
+ {
+ return;
+ }
+ if (registrar)
+ {
+ base.RegistrarAcao(string.Concat("ACESSOU USUÁRIO \"", value.get_Nome(), "\""), value.get_Id(), new TipoTela?(16), string.Format("ID USUÁRIO: {0}", value.get_Id()));
+ }
+ this.LastAccessId = value.get_Id();
+ this.LastAccessTela = 16;
+ Usuario selectedUsuario = this.SelectedUsuario;
+ if (selectedUsuario != null)
+ {
+ nullable = new long?(selectedUsuario.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ long? nullable1 = nullable;
+ long id = value.get_Id();
+ if (nullable1.GetValueOrDefault() != id | !nullable1.HasValue)
+ {
+ this.SelectedUsuario = this.UsuariosFiltrados.FirstOrDefault<Usuario>((Usuario x) => x.get_Id() == value.get_Id());
+ }
+ if (this.SelectedUsuario.get_InicioAcesso().HasValue && this.SelectedUsuario.get_FimAcesso().HasValue)
+ {
+ DateTime? inicioAcesso = this.SelectedUsuario.get_InicioAcesso();
+ DateTime dateTime = inicioAcesso.Value;
+ this.InicioAcesso = dateTime.ToString("HH:mm");
+ inicioAcesso = this.SelectedUsuario.get_FimAcesso();
+ dateTime = inicioAcesso.Value;
+ this.FimAcesso = dateTime.ToString("HH:mm");
+ }
+ if (!this.SelectedUsuario.get_InicioAcesso().HasValue && !this.SelectedUsuario.get_FimAcesso().HasValue)
+ {
+ this.InicioAcesso = null;
+ this.FimAcesso = null;
+ }
+ this.CartaoCriado = !string.IsNullOrEmpty(value.get_Visita());
+ this.LabelCartao = (this.CartaoCriado ? "ATUALIZAR CARTÃO" : "CRIAR CARTÃO");
+ }
+ }
+} \ No newline at end of file