//属于AddFriendCommand private void AddFriend(object obj) { string targetName = (obj as ClientUser).UserName; //首先判断是否已经是好友 var currentUserFriends = dataService.GetAllFriends(); var searchedUser = from u in currentUserFriends where u.UserName == targetName select u; if (searchedUser.Count() != 0) { MessageBox.Show("你与此用户已是好友"); return; } Message msg = new Message(MessageType.FRIENDREQUEST, dataService.UserName, targetName , string.Empty); ResponseType response = dataService.SendAddFriendMessage(msg); if (response == ResponseType.OK) { ClientUser newFriend = obj as ClientUser; Utilities.Messenger.Default.Send(new Messages.NewFriendMessage(newFriend)); MessageBox.Show("添加好友成功"); } else if (response == ResponseType.INVALID) { MessageBox.Show("添加好友失败"); } else { MessageBox.Show("网络错误"); } }
//构造函数 public MainViewModel(ClientDataService service, Action closeWindow) { this._closeWindow = closeWindow; dataService = service; Chats = dataService.GetAllChats(); Friends = dataService.GetAllFriends(); dataService.NewChatCreated += OnNewChatCreated; currentUserName = dataService.UserName; ChatMainVisibility = Visibility.Visible; FriendListVisibility = Visibility.Hidden; ChatListVisibility = Visibility.Visible; FriendMainVisibility = Visibility.Hidden; LoadCommands(); }
//构造函数 public MainViewModel(ClientDataService service, Action closeWindow) { this._closeWindow = closeWindow; dataService = service; Chats = dataService.GetAllChats(); Friends = dataService.GetAllFriends(); dataService.NewChatCreated += OnNewChatCreated; currentUserName = dataService.UserName; ChatMainVisibility = Visibility.Visible; FriendListVisibility = Visibility.Hidden; ChatListVisibility = Visibility.Visible; FriendMainVisibility = Visibility.Hidden; LoadCommands(); }