async void OptionClick(Object o) { if (o is Answer) { if (((Answer)o).text.Equals(Question.CorrectAnswer)) { Score++; } } if (Score >= 3) { bool isLoggedIn = App.Current.Properties.ContainsKey("IsLoggedIn") ? Convert.ToBoolean(App.Current.Properties["IsLoggedIn"]) : false; Page p; if (!isLoggedIn) { p = new LogIn(); LogInViewModel log = (LogInViewModel)p.BindingContext; log.NextPage = new AddQuestion(); } else { p = new AddQuestion(); AddQuestionViewModel add = (AddQuestionViewModel)p.BindingContext; TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion amricanQuestion = await proxy.GetRandomQuestion(); add.NextPage = new Game(amricanQuestion, 0); } if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } else { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion amricanQuestion = await proxy.GetRandomQuestion(); Page p = new Game(amricanQuestion, Score); if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } }
async void Log() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); User u = await proxy.LoginAsync(Email, Password); if (u != null) { App a = (App)App.Current; a.CurrentUser = u; try { await SecureStorage.SetAsync("email", Email); await SecureStorage.SetAsync("password", Password); } catch { } Application.Current.Properties["IsLoggedIn"] = Boolean.TrueString; Page p = null; if (NextPage != null) { if (NextPage is AddQuestion) { AddQuestionViewModel add = (AddQuestionViewModel)NextPage.BindingContext; AmericanQuestion amricanQuestion = await proxy.GetRandomQuestion(); add.NextPage = new Game(amricanQuestion, 0); p = NextPage; } } else { p = new HomeWhenLogged(); } if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } else { Label = "Email or password is incorrect. Please try again"; } }
void AddQ() { Counter--; if (Counter <= 0) { Able = false; } Page p = new AddQuestion(); AddQuestionViewModel a = (AddQuestionViewModel)p.BindingContext; a.NextPage = new Questions(); if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } }