private async void OnEntrar() { if (IsBusy) { return; } IsBusy = true; try { if (!ValidationHelper.IsFormValid(Credencial, page)) { return; } if (await UsuarioDao.EntrarComEmailESenha(Credencial.Email, Credencial.Senha)) { if (Credencial.Lembrar) { Properties.SaveLogin(Credencial.Email, Credencial.Senha); } switch (App.UsuarioLogado.Tipo) { case Model.Tipo.NaoDefinido: _ = Application.Current.MainPage.Navigation.PushModalAsync(new SelecionarTipoUsuarioPage()); break; case Model.Tipo.Empresa: App.EmpresaDados = await EmpresaDao.BuscarPeloCodigo(App.UsuarioLogadoAuth.User.LocalId); Application.Current.MainPage = new MenuEmpresaPage(); break; case Model.Tipo.Estudante: App.EstudanteDados = await EstudanteDao.BuscarPeloCodigo(App.UsuarioLogadoAuth.User.LocalId); Application.Current.MainPage = new MenuEstudantePage(); break; } } else { await Application.Current.MainPage.DisplayAlert("Erro", "Dados inválidos", "Ok"); } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Erro", ex.Message, "Ok"); } finally { IsBusy = false; } }
/// <summary> /// Verifica se existe algum usuario logado atraves do Properties e ja realiza a Autenticação /// e inicia o todos os serviços do Firebase /// </summary> private async void ExisteUsuarioLogado() { bool flag = false; try { string[] credencial = Util.Properties.GetLogin(); if (credencial != null) { if (await UsuarioDao.EntrarComEmailESenha(credencial[0], credencial[1])) { flag = true; } } else { Util.Properties.RemoveLogin(); } } catch (Exception e) { await Current.MainPage.DisplayAlert("Erro", e.Message, "Ok"); } finally { if (flag) { switch (UsuarioLogado.Tipo) { case Tipo.NaoDefinido: _ = Current.MainPage.Navigation.PushModalAsync(new SelecionarTipoUsuarioPage()); break; case Tipo.Empresa: EmpresaDados = await EmpresaDao.BuscarPeloCodigo(UsuarioLogadoAuth.User.LocalId); Current.MainPage = new MenuEmpresaPage(); break; case Tipo.Estudante: EstudanteDados = await EstudanteDao.BuscarPeloCodigo(UsuarioLogadoAuth.User.LocalId); Current.MainPage = new MenuEstudantePage(); break; } } else { MainPage = new NavigationPage(new IntroducaoPage()); } } }
private async void GetUserType() { switch (App.UsuarioLogado.Tipo) { case Tipo.NaoDefinido: _ = App.Current.MainPage.Navigation.PushModalAsync(new SelecionarTipoUsuarioPage()); break; case Tipo.Empresa: App.EmpresaDados = await EmpresaDao.BuscarPeloCodigo(App.UsuarioLogadoAuth.User.LocalId); App.Current.MainPage = new MenuEmpresaPage(); break; case Tipo.Estudante: App.EstudanteDados = await EstudanteDao.BuscarPeloCodigo(App.UsuarioLogadoAuth.User.LocalId); App.Current.MainPage = new MenuEstudantePage(); break; } }