//删除好友 public void DeleteFriend(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("删除该好友?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (MessageBoxResult.OK == result) { //进行删除好友的操作 //将删除好友的信息发送给服务端,由服务端同时删除用户和好友的好友表中的对应ID JObject obj = new JObject(); obj["Id"] = this.Id; String str = obj.ToString(); MClient mClient = MClient.CreateInstance(); mClient.SendDeleteFriend(str); //同时客户端本地将该好友从队列中删除 SqliteConnect.DeleteFriendById(this.Id); //然后从好友队列中删除 Application.Current.Dispatcher.Invoke( new Action(() => { FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance(); FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, this.Id); }) ); } }
//好友在不在分组中,在,返回该好友,不在,添加新的好友,返回该好友 public static FriendEntity InGroupAdd(ref FriendGroup friendGroup, String name) { foreach (var entity in friendGroup.Friends) { if (entity.Name == name) { return(entity); } } FriendEntity friendentity = new FriendEntity(); friendGroup.FriendGroupAdd(ref friendentity); return(friendentity); }
public static FriendEntity InRequestAdd(ref ObservableCollection <FriendEntity> friendRequestGroup, String name) { foreach (var entity in friendRequestGroup) { if (entity.Name == name) { return(entity); } } FriendEntity friendentity = new FriendEntity(); friendRequestGroup.Add(friendentity); return(friendentity); }
//从整个好友列表中删除对应的对象 public static void InGroupListDelete(ObservableCollection <FriendGroup> friendGroups, String id) { FriendGroup friendGroup = null; FriendEntity friendEntity = null; foreach (var group in friendGroups) { foreach (var entity in group.Friends) { if (entity.Id == id) { friendGroup = group; friendEntity = entity; break; } } } //删除对应的对象 friendGroup.Friends.Remove(friendEntity); if (friendGroup.Friends.Count == 0) { friendGroups.Remove(friendGroup); } }
//分组对象添加函数 public void FriendGroupAdd(ref FriendEntity friendEntities) { Friends.Add(friendEntities); }