コード例 #1
0
ファイル: UserViewModel.cs プロジェクト: craigomatic/Gi7
        public UserViewModel(GithubService githubService, INavigationService navigationService, string user)
        {
            Username = user;
            EventsRequest = new ListForUser(Username);
            ShowAppBar = false;

            ShareCommand = new RelayCommand(() =>
            {
                new ShareLinkTask()
                {
                    LinkUri = new Uri(User.HtmlUrl),
                    Title = User.Name + " is on Github.",
                    Message = "I found his profile on Github, you might want to see it.",
                }.Show();
            }, () => User != null);
            FollowCommand = new RelayCommand(() =>
            {
                githubService.Load(new Follow(Username, Follow.Type.FOLLOW), r =>
                {
                    IsFollowing = true;
                });
            }, () => IsFollowing.HasValue && !IsFollowing.Value);
            UnFollowCommand = new RelayCommand(() =>
            {
                githubService.Load(new Follow(Username, Follow.Type.UNFOLLOW), r =>
                {
                    IsFollowing = false;
                });
            }, () => IsFollowing.HasValue && IsFollowing.Value);
            RepoSelectedCommand = new RelayCommand<Repository>(r =>
            {
                if (r != null)
                    navigationService.NavigateTo(String.Format(ViewModelLocator.RepositoryUrl, r.Owner.Login, r.Name));
            });
            UserSelectedCommand = new RelayCommand<User>(u =>
            {
                if (user != null)
                    navigationService.NavigateTo(string.Format(ViewModelLocator.UserUrl, u.Login));
            });
            PivotChangedCommand = new RelayCommand<SelectionChangedEventArgs>(args =>
            {
                var header = ((PivotItem)args.AddedItems[0]).Header as String;
                ShowAppBar = false;
                switch (header)
                {
                    case "Feed":
                        if (EventsRequest == null)
                            EventsRequest = new ListForUser(Username);
                        break;
                    case "Repos":
                        if (Repos == null)
                        {
                            Repos = githubService.Load(new ListWatched(Username));
                            Repos.CollectionChanged += (sender, e) =>
                            {
                                RaisePropertyChanged("WatchedRepos");
                                RaisePropertyChanged("OwnedRepos");
                            };
                        }
                        break;
                    case "Follower":
                        if (FollowersRequest == null)
                            FollowersRequest = new ListFollowers(Username);
                        break;
                    case "Following":
                        if (FollowingsRequest == null)
                            FollowingsRequest = new ListFollowings(Username);
                        break;
                    case "Profile":
                    case "Details":
                        if (User == null)
                        {
                            User = githubService.Load(new UserRequest.Get(Username), u => User = u);
                            if (githubService.IsAuthenticated)
                            {
                                IsFollowing = githubService.Load(new Follow(Username), r =>
                                {
                                    IsFollowing = r;
                                });
                            }
                        }
                        ShowAppBar = true;
                        break;
                }
            });
        }
コード例 #2
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (ListUsers.Count > 0)
            {
                bool usersChanged     = false;
                bool friendsChanged   = false;
                bool followersChanged = false;

                foreach (GridViewRow row in gvUsers.Rows)
                {
                    Control ctrl = row.FindControl("cbxDelete");
                    if (ctrl != null)
                    {
                        CheckBox cbx = (CheckBox)ctrl;
                        if (cbx.Checked)
                        {
                            Control lblctrl = row.FindControl("lblUserId");
                            if (lblctrl != null)
                            {
                                Label lbl  = (Label)lblctrl;
                                var   user = ListUsers.Where(k => k.UserId == lbl.Text).FirstOrDefault();
                                if (user != null)
                                {
                                    var uremove = ListFriends.Where(x => x.UserId == user.UserId).FirstOrDefault();
                                    if (uremove != null)
                                    {
                                        ListFriends.Remove(uremove);
                                        friendsChanged = true;
                                    }
                                    var furemove = ListFollowers.Where(x => x.UserId == user.UserId).FirstOrDefault();
                                    if (furemove != null)
                                    {
                                        ListFollowers.Remove(furemove);
                                        followersChanged = true;
                                    }
                                    ListUsers.Remove(user);
                                    usersChanged = true;
                                }
                            }
                        }
                    }
                }
                if (friendsChanged)
                {
                    Serializer.WriteFollowersXML(ListFriends.ToList(), Constants.FriendsFollowers.Friends.ToString());
                }
                if (followersChanged)
                {
                    Serializer.WriteFollowersXML(ListFollowers.ToList(), Constants.FriendsFollowers.Followers.ToString());
                }
                if (usersChanged)
                {
                    if (friendsChanged)
                    {
                        Serializer.WriteFollowersXML(ListUsers.ToList(), Constants.FriendsFollowers.Analyze.ToString());
                    }
                    if (friendsChanged)
                    {
                        Serializer.WriteFollowersXML(ListUsers.ToList(), Constants.FriendsFollowers.Unfollow.ToString());
                    }
                    if (followersChanged)
                    {
                        Serializer.WriteFollowersXML(ListUsers.ToList(), Constants.FriendsFollowers.NotFollowing.ToString());
                    }
                    Serializer.WriteFollowersXML(ListUsers.ToList(), Constants.FriendsFollowers.Users.ToString());
                }
                BindData();
            }
        }