public async Task OnGetAsync() { var curUserId = CurUserId; UserFriends = await UserService.GetUserFriends(curUserId).ToListAsync().ConfigureAwait(false); //不是我 且不在好友表中 var otherTeachers = await UserClient.GetUsersByRoleNameAsync(new UserGrpcService.RoleNameReq { RoleName = ConstStrings.Role_Teacher, Skip = 0, Take = 1000 }); OtherTeachers = otherTeachers.Users.Where(e => !UserFriends.Any(ee => ee == e.Id) && e.Id != CurUserId); }
public void AddToFriends(User subscriber) { if (Id == subscriber.Id) { throw new Exception("You can not add to friend yourself"); } if (!Subscribers.Any(sub => sub.Subscriber.Id == subscriber.Id)) { throw new Exception("This user is not your subscriber"); } if (UserFriends.Any(friend => friend.Friend.Id == subscriber.Id)) { throw new Exception("This user already your friend"); } UserFriends.Add(new UserFriend(Id, subscriber.Id)); RemoveFromSubscribers(subscriber.Id); }