Exemplo n.º 1
0
        async void retrievePoll()
        {
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollQuestion());

            while (httpTask == null)
            {
                httpTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollQuestion());
            }

            if (httpTask != null)
            {
                if (httpTask != "There is no poll for now.")
                {
                    List <Poll> pollList = JsonConvert.DeserializeObject <List <Poll> >(httpTask.ToString());

                    //If poll is available, get the poll details, else display the error message
                    if (pollList != null)
                    {
                        if (pollList.Count > 0)
                        {
                            //Get poll details
                            poll = pollList[0];
                            Console.WriteLine("Poll question is: " + poll.pollQuestion);
                            string pollID       = poll.pollID;
                            string pollQuestion = poll.pollQuestion;

                            //Get poll options
                            string httpOptionTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollOptions(pollID));

                            while (httpOptionTask == null)
                            {
                                httpOptionTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollOptions(pollID));
                            }

                            if (httpOptionTask != null)
                            {
                                List <pollOption> pollOptionList = JsonConvert.DeserializeObject <List <pollOption> >(httpOptionTask.ToString());
                                poll.pollOptions = pollOptionList;
                                List <string> pollOptionStrings = new List <string>();
                                foreach (pollOption option in poll.pollOptions)
                                {
                                    pollOptionStrings.Add(option.optionTitle);
                                }
                                if (pollOptionList != null)
                                {
                                    if (pollOptionList.Count > 0)
                                    {
                                        //Display poll details and options
                                        isPollPresent = true;
                                        Console.WriteLine("YES TESTING IF ISPRESENT " + isPollPresent);
                                        pollQuestionLbl.Text         = pollQuestion;
                                        pollOptionPicker.ItemsSource = pollOptionStrings;
                                        pollQuestionLbl.IsVisible    = true;
                                        optionFrame.IsVisible        = true;
                                        //submitButton.IsVisible = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            errorMsg.IsVisible = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Poll Task is null ");
                        errorMsg.IsVisible = true;
                    }
                }
                else
                {
                    errorMsg.IsVisible = true;
                }
            }
            //await Task.Run(() => checkAdminLoginStatus());
            checkAdminLoginStatus();
            //activityIndicator.IsVisible = false;
            //activityIndicator.IsRunning = false;
        }