Esempio n. 1
0
        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);
                }
            }
        }
        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";
            }
        }