public List <FriendDTO> GetAllPossibleFriends(FriendsDialogFilter filter) { var allUsers = _context.Users.Include(u => u.FirstFriends).ToList(); var user = allUsers.FirstOrDefault(u => u.Id == filter.UserId); var friendsIds = user.FirstFriends.Select(f => f.SecondFriendId).ToList(); var allPossibleFriends = allUsers.Where(u => u.Id != filter.UserId) .Select(u => FriendCoreConverter.ToDTO(u, friendsIds.Contains(u.Id))).ToList(); return(allPossibleFriends); }
public (int, List <FriendDTO>) GetFriends(FriendsPageFilter filter) { //TODO OPTIMIZE QUERY PLEASEEEEE //TODO correct filter and check if data is correct var query = _context.Friendships.Where(f => f.FirstFriendId == filter.UserId).Include(f => f.SecondFriend) .ThenInclude(fr => fr.Library) .OrderBy(f => f.SecondFriend.Name); int totalNumber = query.Count(); var friends = query.Skip(filter.PageIndex * filter.PageSize).Take(filter.PageSize).Select(f => FriendCoreConverter.ToDTO(f.SecondFriend, true)).ToList(); return(totalNumber, friends); }