Exemplo n.º 1
0
        public async Task ExecuteLoadUsersCommandAsync(string filter)
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");
            try
            {
                IsBusy = true;
                Users.Clear();


                followedUsers.Clear();

                try
                {
                    followedUsers.AddRange((await ParseAccess.GetUser(ParseAccess.CurrentUser().ObjectId)).Get <IList <string> >("followedUsers"));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                IEnumerable <Parse.ParseObject> users;
                if (filter == "Followed Users")
                {
                    users = await ParseAccess.LoadFollowedUsers(followedUsers);
                }
                else
                {
                    users = await ParseAccess.LoadUsers();
                }

                foreach (var user in users)
                {
                    var isFollowed = false;

                    var topicObjects = user.Get <IList <ParseObject> >("followedTopics");
                    var topics       = new List <string>();
                    foreach (var topic in topicObjects)
                    {
                        topics.Add(topic.Get <string>("topicText"));
                    }
                    if (followedUsers.Contains(user.ObjectId))
                    {
                        isFollowed = true;
                    }
                    var u = new User
                    {
                        Username       = user.Get <string>("username"),
                        FirstName      = user.Get <string>("firstName"),
                        LastName       = user.Get <string>("lastName"),
                        ObjectId       = user.ObjectId,
                        IsFollowed     = isFollowed,
                        FollowedTopics = topics
                    };
                    Users.Add(u);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }