Beispiel #1
0
 private IEnumerable <UserDto> MapLikesToDto(LikesCollection likes, IEnumerable <ApplicationUser> users)
 {
     return(likes
            .Select(like => users.FirstOrDefault(x => x.Id == like.UserId))
            .Select(user => _mapper.Map <UserDto>(user))
            .Where(user => user != null)
            .ToList());
 }
        private IEnumerable <LikeDto> MapLikesToDto(LikesCollection likes, IEnumerable <ApplicationUser> users)
        {
            return(likes
                   .Select(like => new { User = users.FirstOrDefault(user => user.Id == like.UserId), Like = like })
                   .Select(likeWithUserData =>
            {
                if (likeWithUserData.User == null)
                {
                    return null;
                }

                return new LikeDto
                {
                    UserId = likeWithUserData.User.Id,
                    FullName = likeWithUserData.User.FullName,
                    PictureId = likeWithUserData.User.PictureId,
                    Type = likeWithUserData.Like.Type
                };
            })
                   .Where(like => like != null)
                   .ToList());
        }