//属于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("网络错误"); } }