//好友在不在分组中,在,返回该好友,不在,添加新的好友,返回该好友 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); }
//检查指定名字的分组是否在分组列表中,如果在分组List中,返回该分组,如果不在,添加一个分组并返回该分组 public static FriendGroup InGroupListAdd(ref ObservableCollection <FriendGroup> grouplist, String name) { foreach (var group in grouplist) { if (group.Name == name) { return(group); } } FriendGroup friendGroup = new FriendGroup() { Name = name }; grouplist.Add(friendGroup); return(friendGroup); }
//从整个好友列表中删除对应的对象 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); } }