Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }