コード例 #1
0
        public async Task ExecuteLoadQuestionDetailCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                var question = await ParseAccess.GetQuestion(questionId);

                var state     = "Closed";
                var stateFlag = question.Get <int>("stateFlag");

                if (stateFlag == (int)RequestState.Active)
                {
                    state = "Active";
                }
                else if (stateFlag == (int)RequestState.InProgress)
                {
                    state = "In Progress";
                }

                var topicObjects = question.Get <IList <ParseObject> >("topics");
                var topics       = new List <string>();
                foreach (var topic in topicObjects)
                {
                    topics.Add(topic.Get <string>("topicText"));
                }

                var ownerObject = question.Get <ParseObject>("createdBy");

                var owner = new User
                {
                    ObjectId  = ownerObject.ObjectId,
                    FirstName = ownerObject.Get <string>("firstName"),
                    LastName  = ownerObject.Get <string>("lastName"),
                    Username  = ownerObject.Get <string>("username")
                };
                Question = new Question()
                {
                    Title     = question.Get <string>("title"),
                    Body      = question.Get <string>("body"),
                    ObjectId  = question.ObjectId,
                    Topics    = topics,
                    CreatedAt = question.CreatedAt.Value + RestService.TimeDiff,
                    Owner     = owner,
                    State     = state
                };

                Answers.Clear();
                var answers = await ParseAccess.LoadAnswers(question);

                foreach (var answer in answers)
                {
                    ParseUser userObject = answer.Get <ParseUser>("createdBy");
                    var       user       = new User
                    {
                        ObjectId  = userObject.ObjectId,
                        FirstName = userObject.Get <string>("firstName"),
                        LastName  = userObject.Get <string>("lastName"),
                        Username  = userObject.Get <string>("username")
                    };

                    DateTime now = RestService.GetServerTime();
                    var      a   = new Answer
                    {
                        Body      = answer.Get <string>("body"),
                        CreatedBy = user,
                        TimeAgo   = HelperFunctions.TimeAgo(answer.UpdatedAt.Value, now)
                    };
                    Answers.Add(a);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }