Esempio n. 1
0
        public static async Task <ObservableCollection <QuestionDAO> > LoadListQuestion()
        {
            ObservableCollection <QuestionDAO> myList = new ObservableCollection <Models.QuestionDAO>();

            try
            {
                var List = await App.MobileService.InvokeApiAsync("Question", HttpMethod.Get, null);

                if (List != null)
                {
                    myList.Clear();
                    foreach (var item in List)
                    {
                        myList.Add(new Models.QuestionDAO(item));
                    }
                    return(myList);
                    // NextQuestion();
                }
                myList.Clear();
                return(myList);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("! ! ! Loading Question in Service ! ! ! " + ex.Message);
                return(ConnectServiceHelper.LoadListQuestion().Result);
            }
        }
Esempio n. 2
0
        public async static Task <ObservableCollection <QuestionDAO> > GetListQuestionChallenge(string listIdQuestion)
        {
            ObservableCollection <QuestionDAO> myList = new ObservableCollection <Models.QuestionDAO>();

            try
            {
                Dictionary <string, string> myInfo = new Dictionary <string, string>();
                myInfo.Add("listIdQuestion", listIdQuestion);
                var List = await App.MobileService.InvokeApiAsync("Question", HttpMethod.Get, myInfo);

                if (List != null)
                {
                    myList.Clear();
                    foreach (var item in List)
                    {
                        myList.Add(new Models.QuestionDAO(item));
                    }
                    return(myList);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("! ! ! Loading Question in Service ! ! ! " + ex.Message);
                return(ConnectServiceHelper.GetListQuestionChallenge(listIdQuestion).Result);
            }
        }
Esempio n. 3
0
        public async static Task <ObservableCollection <QuestionDAO> > LoadQuestionByGenre(string genre)
        {
            ObservableCollection <QuestionDAO> ListQuestion = new ObservableCollection <QuestionDAO>();

            try
            {
                Dictionary <string, string> myDic = new Dictionary <string, string>();
                myDic.Add("genre", genre);

                var myQues = await App.MobileService.InvokeApiAsync("Question", HttpMethod.Get, myDic);

                if (myQues != null)
                {
                    if (ListQuestion.Count != 0)
                    {
                        ListQuestion.Clear();
                    }
                    ListQuestion.Clear();
                    foreach (var item in myQues)
                    {
                        ListQuestion.Add(new Models.QuestionDAO(item));
                    }
                    return(ListQuestion);
                }
                ListQuestion.Clear();
                return(ListQuestion);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("! ! ! Loading Question in Service ! ! ! " + ex.Message);
                return(ConnectServiceHelper.LoadQuestionByGenre(genre).Result);
            }
        }
        private async void LoadGame()
        {
            switch (Global.TypeGenre)
            {
            case "default":
                Global.ListQuestion = await ConnectServiceHelper.LoadListQuestion();

                if (Global.ListQuestion != null)
                {
                    NextQuestion();
                }
                break;

            case "challenge":
                Global.ListQuestion = await ConnectServiceHelper.GetListQuestionChallenge(Global.CurrentChallenge.ListIdQuestion);

                if (Global.ListQuestion != null)
                {
                    NextQuestion();
                }
                break;

            default:
                Global.ListQuestion = await ConnectServiceHelper.LoadQuestionByGenre(Global.TypeGenre);

                if (Global.ListQuestion != null)
                {
                    NextQuestion();
                }
                break;
            }
        }
        private async void Btn_Prev_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CurrentPage--;
                if (CurrentPage < 0)
                {
                    Btn_Prev.IsEnabled = false;
                    CurrentPage        = 0;
                    return;
                }
                else
                {
                    image.Visibility = System.Windows.Visibility.Visible;
                    SB_Rotation.Begin();
                    Btn_Next.IsEnabled = true;
                    var list = await ConnectServiceHelper.LoadPlayer(CurrentPage);

                    if (list != null)
                    {
                        ListPlayer = list;
                        ListBox_Player.DataContext = ListPlayer;
                    }
                    else
                    {
                        Btn_Prev.IsEnabled = false;
                        image.Visibility   = System.Windows.Visibility.Collapsed;
                        SB_Rotation.Stop();
                    }
                }
            }
            catch { }
        }
Esempio n. 6
0
        private async void ChallengePlayer()
        {
            Dictionary <string, string> mySend = new Dictionary <string, string>();

            mySend.Add("idFaceSend", Global.CurrentUser.IdFacebook);
            mySend.Add("nameSend", Global.CurrentUser.Name);
            mySend.Add("linkFaceSend", Global.CurrentUser.LinkFacebook);
            mySend.Add("idFaceReceive", Global.IdFaceChallenger);
            mySend.Add("score", Global.GameScore.ToString());
            mySend.Add("time", Global.GameTime.ToString());
            string listQuestion = string.Empty;

            for (int i = 0; i < Global.ListQuestion.Count; i++)
            {
                listQuestion += Global.ListQuestion[i].IdQuestion + ",";
            }
            mySend.Add("listIdQuestion", listQuestion);
            if (await ConnectServiceHelper.ChallengePlayer(mySend))
            {
                MessageBox.Show("Challenge Success!\r\nWait Result form Player who you challenge!", "Challenge Information", MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show("Challenge Fail!\r\nHave some error! Do it again, sorry!", "Challenge Information", MessageBoxButton.OK);
            }
        }
Esempio n. 7
0
        private async void LoadTopPlayer()
        {
            ListUser = await ConnectServiceHelper.LoadTopScore();

            if (ListUser != null)
            {
                ListBox_Score.DataContext = ListUser;
            }
        }
Esempio n. 8
0
        private async void LoadListChallenge()
        {
            try
            {
                image.Visibility = System.Windows.Visibility.Visible;
                SB_Rotation.Begin();

                List_Challenge = await ConnectServiceHelper.GetChallenges(Global.AccessToken);

                ListChallenge.DataContext = List_Challenge;
            }
            catch { }
        }
Esempio n. 9
0
 void CreateNewUser()
 {
     if (Btn_LogInFacebook.CurrentUser != null)
     {
         Global.CurrentUser              = new UserMusicDAO();
         Global.CurrentUser.Name         = Btn_LogInFacebook.CurrentUser.Name;
         Global.CurrentUser.IdFacebook   = Btn_LogInFacebook.CurrentUser.Id;
         Global.CurrentUser.LinkFacebook = Btn_LogInFacebook.CurrentUser.Link;
         Global.CurrentUser.UserImage    = Btn_LogInFacebook.CurrentUser.ProfilePictureUrl.OriginalString;
         Global.AccessToken              = Btn_LogInFacebook.CurrentSession.AccessToken;
         ConnectServiceHelper.CreateUser(Btn_LogInFacebook.CurrentUser.Id, Btn_LogInFacebook.CurrentUser.Link, Btn_LogInFacebook.CurrentUser.Name, Global.AccessToken);
         LoadListChallenge();
     }
 }
Esempio n. 10
0
 private void UpdateResult()
 {
     ConnectServiceHelper.UpdateScore(Global.GameScore, Global.GameTime, Global.CurrentUser.IdFacebook);
     ConnectServiceHelper.UpdateScore(Global.CurrentChallenge.Score, Global.CurrentChallenge.Time, Global.CurrentChallenge.IdFaceSend);
     if (Text_Winner.Text == "! You Win !")
     {
         ConnectServiceHelper.UpdateWinLose(true, Global.CurrentUser.IdFacebook);
         ConnectServiceHelper.UpdateWinLose(false, Global.CurrentChallenge.IdFaceSend);
     }
     else if (Text_Winner.Text == "! You Lose !")
     {
         ConnectServiceHelper.UpdateWinLose(false, Global.CurrentUser.IdFacebook);
         ConnectServiceHelper.UpdateWinLose(true, Global.CurrentChallenge.IdFaceSend);
     }
     ConnectServiceHelper.DeleteChallenge(Global.CurrentChallenge.IdChallenge);
 }