//Contructor public LoginViewModel() { error = ""; username = ""; password = ""; proxy = TriviaWebAPIProxy.CreateProxy(); }
public async void SignUP() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(NickName)) { ErrorMessage = "Please enter email, password and nickname"; } else { User u = new User { Email = Email, Password = Password, NickName = NickName, Questions = new List <AmericanQuestion>() }; bool registered = await proxy.RegisterUser(u); if (registered) { LoginPage p = new LoginPage(); if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } else { ErrorMessage = "Something went wrong"; } } }
async void SignUp() { User u = new User { Email = Email, Password = Password, NickName = NickName, }; TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); bool b = await proxy.RegisterUser(u); if (b) { Label = "successfully registered! please wait 5 seconds"; //wait 10 seconds - to learn how await Task.Delay(10000); User us = await proxy.LoginAsync(Email, Password); App.Current.Properties["UserDetail"] = JsonSerializer.Serialize(u); Page p = new HomeWhenLogged(); if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } else { Label = "The email or nickname is already exsits. Please try another one"; } }
private async void Button_Clicked(object sender, EventArgs e) { //Example of how to use the proxy! TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion q = await proxy.GetRandomQuestion(); //tq.Wait(); //AmericanQuestion q = tq.Result; User user = new User { Email = "*****@*****.**", NickName = "testNickName", Password = "******" }; bool tu = await proxy.RegisterUser(user); if (tu) { AmericanQuestion nq = new AmericanQuestion { QText = "Who is the founder of Testla?", CorrectAnswer = "Elon Musk", OtherAnswers = new string[] { "Steve Jobs", "Bill Gates", "George Constanza" }, CreatorNickName = "testNickName" }; bool nqt = await proxy.PostNewQuestion(nq); if (nqt) { bool dt = await proxy.DeleteQuestion(nq); } } }
private async void Register() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); User user = new User() { Email = Email, NickName = Nickname, Password = Password }; Task <bool> registerTask = Task.Run(() => proxy.RegisterUser(user)); await registerTask; if (registerTask.Result) { ((App)App.Current).User = user; if (!popOrPush) { PushModal?.Invoke(new QuestioningPage()); } else { Pop?.Invoke(); } } else { Error = "Email or NickName Exists"; } }
public async void AddQuestion() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); App app = (App)App.Current; User u = app.CurrentUser; AmericanQuestion q = new AmericanQuestion { QText = this.questionText, CorrectAnswer = this.correctAnswer, OtherAnswers = new string[] { wrongAnswer1, wrongAnswer2, wrongAnswer3 }, CreatorNickName = u.NickName }; bool succeeded = await proxy.PostNewQuestion(q); if (!succeeded) { Message = "Question was not added"; } else { Message = "Question was added successfully!"; //await App.Current.MainPage.Navigation.PopAsync(); } }
async void AddQ() { string[] arr = new string[3]; arr[0] = Option1; arr[1] = Option2; arr[2] = Option3; //User u = JsonSerializer.Deserialize<User>(content, serializerOptions); //User u = (User)App.Current.Properties["User"]; App app = (App)App.Current; User u = app.CurrentUser; AmericanQuestion a = new AmericanQuestion { CorrectAnswer = this.CorrectAnswer, QText = this.Question, OtherAnswers = arr, CreatorNickName = u.NickName, }; TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); bool b = await proxy.PostNewQuestion(a); u.Questions.Add(a); if (b) { //AmericanQuestion q = await proxy.GetRandomQuestion(); //string[] options = new string[4]; //Random r = new Random(); //int num = r.Next(0, 4); //options[num] = q.CorrectAnswer; //for (int i = 0, optionNum = 0; i < options.Length; i++) //{ // if (options[i] == null) // { // options[i] = q.OtherAnswers[optionNum]; // optionNum++; // } //} AmericanQuestion question = await proxy.GetRandomQuestion(); Page p = new Game(question, 0); //GameViewModel game = (GameViewModel)p.BindingContext; //game.Options = options; //game.Question = a; //game.QuestionText = a.QText; //game.Score = 0; if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } } else { Label = "Something went wrong! Please try again"; } }
async void PlayGame() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion amricanQuestion = await proxy.GetRandomQuestion(); Page p = new Game(amricanQuestion, 0); if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } }
//public Command CommandNameAnswer { get; set; } //public Command CommandNameNextQuestion { get; set; } public GameVM() { Answers = new Answer[4]; CounterText = "You Answered 0 corrects answers in a row"; HasAnswered = false; //CommandNameAnswer = new Command<int>(AnswerClicked); //CommandNameNextQuestion = new Command(GetNextQuestion); //CommandNameNextQuestion.ChangeCanExecute(); proxy = TriviaWebAPIProxy.CreateProxy(); Counter = 0; SetUpQuestion(); }
async void PlayGame() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion amricanQuestion = await proxy.GetRandomQuestion(); Page p = new Game(amricanQuestion, 0); GameViewModel game = (GameViewModel)p.BindingContext; game.Score = 0; if (NavigateToPageEvent != null) { NavigateToPageEvent(p); } }
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 RemoveQuestion(AmericanQuestion a) { if (QuestionList.Contains(a)) { try { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); await proxy.DeleteQuestion(a); QuestionList.Remove(a); } catch (Exception e) { } } Counter++; Able = true; }
private async void Login() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); Task <User> loginTask = proxy.LoginAsync(Email, Password); await loginTask; if (loginTask.Result != null) { ((App)App.Current).User = loginTask.Result; PushModal?.Invoke(new QuestioningPage()); } else { Error = "Email or NickName Does Not Match"; } }
public async void LoginAsync() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); User u = await proxy.LoginAsync(Email, Password); if (u == null) { Message = "Email or password incorrect"; } else { App app = (App)App.Current; app.CurrentUser = u; await app.MainPage.Navigation.PopModalAsync(); } }
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"; } }
public async void RegisterAsync() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); User uu = new User { NickName = this.nickname, Email = this.email, Password = this.password, }; bool u = await proxy.RegisterUser(uu); if (!u) { Message = "Registration isn't completed successfully"; } else { App app = (App)App.Current; app.CurrentUser = uu; await app.MainPage.Navigation.PopModalAsync(); } }
public async void Login() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password)) { ErrorMessage = "please fill in both fields"; } else { User user = await proxy.LoginAsync(Email, Password); if (user == null) { ErrorMessage = "wrong email or password"; } else { ((App)Application.Current).currentUser = user; NavigateToPageEvent(new GamePage()); } } }
private async void NewQuestion() { TriviaWebAPIProxy proxy = TriviaWebAPIProxy.CreateProxy(); AmericanQuestion question = await proxy.GetRandomQuestion(); }