Ejemplo n.º 1
0
        public async Task <IActionResult> GetVideoCommentsCombined(int videoPostId, string videoId, byte isGoogleDriveVideo)
        {
            if (videoPostId <= 0 || string.IsNullOrWhiteSpace(videoId))
            {
                return(NotFound());
            }

            var videoComments = _vcRepository
                                .FindBy(nv => nv.VideoPostId == videoPostId, vcr => vcr.VideoCommentReplies);
            var videoCommentVM = Mapper.Map <IEnumerable <VideoComment>, IEnumerable <VideoCommentVM> >(videoComments);

            if (isGoogleDriveVideo == 1)
            {
                videoCommentVM = videoCommentVM.OrderByDescending(x => x.DateCreated);
                return(new OkObjectResult(videoCommentVM));
            }

            var youTubeComments = await _youTube.GetYouTubeCommentsByVideoId(videoId);

            // Add youtube comments on top of comments from database
            if (youTubeComments != null && youTubeComments.Comments.Count > 0)
            {
                foreach (var yc in youTubeComments.Comments)
                {
                    videoCommentVM = videoCommentVM.Append(new VideoCommentVM
                    {
                        AuthorDisplayName     = yc.AuthorDisplayName,
                        Comment               = yc.TextDisplay,
                        DateCreated           = yc.UpdatedAt.DateTime,
                        Likes                 = Convert.ToInt32(yc.Likes),
                        IsYouTubeComment      = true,
                        TotalReplyCount       = yc.TotalReplyCount,
                        YouTubeCommentReplies = MappReplies(yc.Replies)
                                                //ParentId = yc.ParentId
                    });
                }
            }

            videoCommentVM = videoCommentVM.OrderByDescending(x => x.DateCreated);

            return(new OkObjectResult(videoCommentVM));
        }